KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > realm > AddRealmAction


1 /*
2  * Copyright 2001-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.webapp.admin.realm;
18
19 import java.io.IOException JavaDoc;
20 import java.net.URLEncoder JavaDoc;
21 import java.util.Locale JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import javax.servlet.ServletException JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26 import javax.servlet.http.HttpSession JavaDoc;
27 import org.apache.struts.action.Action;
28 import org.apache.struts.action.ActionErrors;
29 import org.apache.struts.action.ActionForm;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32 import org.apache.struts.util.MessageResources;
33 import org.apache.webapp.admin.TomcatTreeBuilder;
34 import org.apache.webapp.admin.LabelValueBean;
35 import org.apache.webapp.admin.Lists;
36
37 /**
38  * The <code>Action</code> that sets up <em>Add Realm</em> transactions.
39  *
40  * @author Manveen Kaur
41  * @version $Revision: 1.11 $ $Date: 2004/10/18 06:37:54 $
42  */

43
44 public class AddRealmAction extends Action {
45
46     // the list for types of realms
47
private ArrayList JavaDoc types = null;
48
49     // --------------------------------------------------------- Public Methods
50

51     /**
52      * Process the specified HTTP request, and create the corresponding HTTP
53      * response (or forward to another web component that will create it).
54      * Return an <code>ActionForward</code> instance describing where and how
55      * control should be forwarded, or <code>null</code> if the response has
56      * already been completed.
57      *
58      * @param mapping The ActionMapping used to select this instance
59      * @param actionForm The optional ActionForm bean for this request (if any)
60      * @param request The HTTP request we are processing
61      * @param response The HTTP response we are creating
62      *
63      * @exception IOException if an input/output error occurs
64      * @exception ServletException if a servlet exception occurs
65      */

66     public ActionForward execute(ActionMapping mapping,
67                                  ActionForm form,
68                                  HttpServletRequest JavaDoc request,
69                                  HttpServletResponse JavaDoc response)
70         throws IOException JavaDoc, ServletException JavaDoc {
71
72         // Acquire the resources that we need
73
HttpSession JavaDoc session = request.getSession();
74         Locale JavaDoc locale = getLocale(request);
75         MessageResources resources = getResources(request);
76         // Fill in the form values for display and editing
77

78         String JavaDoc realmTypes[] = new String JavaDoc[5];
79         realmTypes[0] = "UserDatabaseRealm";
80         realmTypes[1] = "JNDIRealm";
81         realmTypes[2] = "MemoryRealm";
82         realmTypes[3] = "JDBCRealm";
83         realmTypes[4] = "DataSourceRealm";
84
85         String JavaDoc parent = request.getParameter("parent");
86         String JavaDoc type = request.getParameter("type");
87         if (type == null)
88             type = "UserDatabaseRealm"; // default type is UserDatabaseRealm
89

90         types = new ArrayList JavaDoc();
91         // the first element in the select list should be the type selected
92
types.add(new LabelValueBean(type,
93                 "AddRealm.do?parent=" +
94                 URLEncoder.encode(parent,TomcatTreeBuilder.URL_ENCODING)
95                 + "&type=" + type));
96         for (int i=0; i< realmTypes.length; i++) {
97             if (!type.equalsIgnoreCase(realmTypes[i])) {
98                 types.add(new LabelValueBean(realmTypes[i],
99                 "AddRealm.do?parent=" +
100                 URLEncoder.encode(parent,TomcatTreeBuilder.URL_ENCODING)
101                 + "&type=" + realmTypes[i]));
102             }
103         }
104
105         if ("UserDatabaseRealm".equalsIgnoreCase(type)) {
106             createUserDatabaseRealm(session, parent);
107         } else if ("JNDIRealm".equalsIgnoreCase(type)) {
108             createJNDIRealm(session, parent);
109         } else if ("MemoryRealm".equalsIgnoreCase(type)) {
110             createMemoryRealm(session, parent);
111         } else if ("JDBCRealm".equalsIgnoreCase(type)){
112             createJDBCRealm(session, parent);
113         } else if ("DataSourceRealm".equalsIgnoreCase(type)) {
114             createDataSourceRealm(session, parent);
115         }
116         // Forward to the realm display page
117
return (mapping.findForward(type));
118
119     }
120
121     private void createUserDatabaseRealm(HttpSession JavaDoc session, String JavaDoc parent) {
122
123         UserDatabaseRealmForm realmFm = new UserDatabaseRealmForm();
124         session.setAttribute("userDatabaseRealmForm", realmFm);
125         realmFm.setAdminAction("Create");
126         realmFm.setObjectName("");
127         realmFm.setParentObjectName(parent);
128         String JavaDoc realmType = "UserDatabaseRealm";
129         realmFm.setNodeLabel("Realm (" + realmType + ")");
130         realmFm.setRealmType(realmType);
131         realmFm.setResource("");
132         realmFm.setRealmTypeVals(types);
133     }
134
135     private void createJNDIRealm(HttpSession JavaDoc session, String JavaDoc parent) {
136
137         JNDIRealmForm realmFm = new JNDIRealmForm();
138         session.setAttribute("jndiRealmForm", realmFm);
139         realmFm.setAdminAction("Create");
140         realmFm.setObjectName("");
141         realmFm.setParentObjectName(parent);
142         String JavaDoc realmType = "JNDIRealm";
143         realmFm.setNodeLabel("Realm (" + realmType + ")");
144         realmFm.setRealmType(realmType);
145         realmFm.setDigest("");
146         realmFm.setRoleBase("");
147         realmFm.setUserSubtree("false");
148         realmFm.setRoleSubtree("false");
149         realmFm.setRolePattern("");
150         realmFm.setUserRoleName("");
151         realmFm.setRoleName("");
152         realmFm.setRoleBase("");
153         realmFm.setContextFactory("");
154         realmFm.setUserPattern("");
155         realmFm.setUserSearch("");
156         realmFm.setUserPassword("");
157         realmFm.setConnectionName("");
158         realmFm.setConnectionPassword("");
159         realmFm.setConnectionURL("");
160         realmFm.setSearchVals(Lists.getBooleanValues());
161         realmFm.setRealmTypeVals(types);
162     }
163
164     private void createMemoryRealm(HttpSession JavaDoc session, String JavaDoc parent) {
165
166         MemoryRealmForm realmFm = new MemoryRealmForm();
167         session.setAttribute("memoryRealmForm", realmFm);
168         realmFm.setAdminAction("Create");
169         realmFm.setObjectName("");
170         realmFm.setParentObjectName(parent);
171         String JavaDoc realmType = "MemoryRealm";
172         realmFm.setNodeLabel("Realm (" + realmType + ")");
173         realmFm.setRealmType(realmType);
174         realmFm.setPathName("");
175         realmFm.setRealmTypeVals(types);
176     }
177
178     private void createJDBCRealm(HttpSession JavaDoc session, String JavaDoc parent) {
179
180         JDBCRealmForm realmFm = new JDBCRealmForm();
181         session.setAttribute("jdbcRealmForm", realmFm);
182         realmFm.setAdminAction("Create");
183         realmFm.setObjectName("");
184         realmFm.setParentObjectName(parent);
185         String JavaDoc realmType = "JDBCRealm";
186         realmFm.setNodeLabel("Realm (" + realmType + ")");
187         realmFm.setRealmType(realmType);
188         realmFm.setDigest("");
189         realmFm.setDriver("");
190         realmFm.setRoleNameCol("");
191         realmFm.setPasswordCol("");
192         realmFm.setUserTable("");
193         realmFm.setRoleTable("");
194         realmFm.setConnectionName("");
195         realmFm.setConnectionPassword("");
196         realmFm.setConnectionURL("");
197         realmFm.setRealmTypeVals(types);
198     }
199     
200     private void createDataSourceRealm(HttpSession JavaDoc session, String JavaDoc parent) {
201
202         DataSourceRealmForm realmFm = new DataSourceRealmForm();
203         session.setAttribute("dataSourceRealmForm", realmFm);
204         realmFm.setAdminAction("Create");
205         realmFm.setObjectName("");
206         realmFm.setParentObjectName(parent);
207         String JavaDoc realmType = "DataSourceRealm";
208         realmFm.setNodeLabel("Realm (" + realmType + ")");
209         realmFm.setRealmType(realmType);
210         realmFm.setDataSourceName("");
211         realmFm.setDigest("");
212         realmFm.setLocalDataSource("false");
213         realmFm.setRoleNameCol("");
214         realmFm.setUserCredCol("");
215         realmFm.setUserNameCol("");
216         realmFm.setUserRoleTable("");
217         realmFm.setUserTable("");
218         realmFm.setRealmTypeVals(types);
219         realmFm.setBooleanVals(Lists.getBooleanValues());
220     }
221
222
223 }
224
Popular Tags