KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > security > UserMemoryRealmForm


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Michel-Ange ANTON
22  * --------------------------------------------------------------------------
23  * $Id: UserMemoryRealmForm.java,v 1.5 2005/04/21 08:59:54 kemlerp Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.webapp.jonasadmin.security;
28
29 import java.util.ArrayList JavaDoc;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32
33 import org.apache.struts.action.ActionMessage;
34 import org.apache.struts.action.ActionErrors;
35 import org.apache.struts.action.ActionForm;
36 import org.apache.struts.action.ActionMapping;
37 import org.objectweb.jonas.webapp.jonasadmin.Jlists;
38
39 public class UserMemoryRealmForm extends ActionForm {
40
41 // --------------------------------------------------------- Constants
42

43 // --------------------------------------------------------- Properties variables
44

45     private String JavaDoc action = null;
46     private String JavaDoc user = null;
47     private String JavaDoc password = null;
48     private String JavaDoc confirmPassword = null;
49     private java.util.ArrayList JavaDoc listGroupsUser = new ArrayList JavaDoc();
50     private java.util.ArrayList JavaDoc listGroupsRealm = new ArrayList JavaDoc();
51     private java.util.ArrayList JavaDoc listGroupsUsed = new ArrayList JavaDoc();
52     private java.util.ArrayList JavaDoc listGroupsNotused = new ArrayList JavaDoc();
53     private java.util.ArrayList JavaDoc listRolesUser = new ArrayList JavaDoc();
54     private java.util.ArrayList JavaDoc listRolesRealm = new ArrayList JavaDoc();
55     private java.util.ArrayList JavaDoc listRolesUsed = new ArrayList JavaDoc();
56     private java.util.ArrayList JavaDoc listRolesNotused = new ArrayList JavaDoc();
57     private String JavaDoc groupsUsed = null;
58     private String JavaDoc groupsNotused = null;
59     private String JavaDoc rolesUsed = null;
60     private String JavaDoc rolesNotused = null;
61     private String JavaDoc[] groupsNotusedSelected = new String JavaDoc[0];
62     private String JavaDoc[] groupsUsedSelected = new String JavaDoc[0];
63     private String JavaDoc[] rolesNotusedSelected = new String JavaDoc[0];
64     private String JavaDoc[] rolesUsedSelected = new String JavaDoc[0];
65
66 // --------------------------------------------------------- Public Methods
67

68     /**
69      * Reset all properties to their default values.
70      *
71      * @param mapping The mapping used to select this instance
72      * @param request The servlet request we are processing
73      */

74     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
75         password = null;
76         confirmPassword = null;
77         groupsUsed = null;
78         groupsNotused = null;
79         rolesUsed = null;
80         rolesNotused = null;
81         // Mandatory !
82
groupsNotusedSelected = new String JavaDoc[0];
83         groupsUsedSelected = new String JavaDoc[0];
84         rolesNotusedSelected = new String JavaDoc[0];
85         rolesUsedSelected = new String JavaDoc[0];
86     }
87
88     /**
89      * Validate the properties that have been set from this HTTP request,
90      * and return an <code>ActionErrors</code> object that encapsulates any
91      * validation errors that have been found. If no errors are found, return
92      * <code>null</code> or an <code>ActionErrors</code> object with no
93      * recorded error messages.
94      *
95      * @param mapping The mapping used to select this instance
96      * @param request The servlet request we are processing
97      */

98     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
99         ActionErrors oErrors = new ActionErrors();
100         // Create errors
101
if (action.equals("create") == true) {
102             user = user.trim();
103             if (user.length() == 0) {
104                 oErrors.add("user"
105                     , new ActionMessage("error.security.factory.memory.realm.user.name.required"));
106             }
107             if (password.length() == 0) {
108                 oErrors.add("password"
109                     , new ActionMessage("error.security.factory.memory.realm.user.password.required"));
110             }
111             if (confirmPassword.length() == 0) {
112                 oErrors.add("password"
113                     , new ActionMessage("error.security.factory.memory.realm.user.confirmPassword.required"));
114             }
115         }
116         // Create and apply errors (but this test exists only to not overload the errors)
117
if (oErrors.size() == 0) {
118             if (password.length() > 0) {
119                 if (!password.equals(confirmPassword)) {
120                     oErrors.add("password"
121                         , new ActionMessage("error.security.factory.memory.realm.user.password.change.different"));
122                 }
123             }
124             if ((confirmPassword.length() > 0) && (password.length() == 0)) {
125                 oErrors.add("password"
126                     , new ActionMessage("error.security.factory.memory.realm.user.password.change.required"));
127             }
128         }
129         // Replace the elements in their good place
130
if (oErrors.size() > 0) {
131             listRolesUsed = Jlists.getArrayList(rolesUsed, Jlists.SEPARATOR);
132             listRolesNotused = Jlists.getArrayList(rolesNotused, Jlists.SEPARATOR);
133             listGroupsUsed = Jlists.getArrayList(groupsUsed, Jlists.SEPARATOR);
134             listGroupsNotused = Jlists.getArrayList(groupsNotused, Jlists.SEPARATOR);
135         }
136         return oErrors;
137     }
138
139 // --------------------------------------------------------- Properties Methods
140

141     public String JavaDoc getUser() {
142         return user;
143     }
144
145     public void setUser(String JavaDoc user) {
146         this.user = user;
147     }
148
149     public String JavaDoc getPassword() {
150         return password;
151     }
152
153     public void setPassword(String JavaDoc password) {
154         this.password = password;
155     }
156
157     public String JavaDoc getConfirmPassword() {
158         return confirmPassword;
159     }
160
161     public void setConfirmPassword(String JavaDoc confirmPassword) {
162         this.confirmPassword = confirmPassword;
163     }
164
165     public java.util.ArrayList JavaDoc getListGroupsUser() {
166         return listGroupsUser;
167     }
168
169     public void setListGroupsUser(java.util.ArrayList JavaDoc listGroupsUser) {
170         this.listGroupsUser = listGroupsUser;
171     }
172
173     public java.util.ArrayList JavaDoc getListGroupsRealm() {
174         return listGroupsRealm;
175     }
176
177     public void setListGroupsRealm(java.util.ArrayList JavaDoc listGroupsRealm) {
178         this.listGroupsRealm = listGroupsRealm;
179     }
180
181     public java.util.ArrayList JavaDoc getListGroupsUsed() {
182         return listGroupsUsed;
183     }
184
185     public void setListGroupsUsed(java.util.ArrayList JavaDoc listGroupsUsed) {
186         this.listGroupsUsed = listGroupsUsed;
187     }
188
189     public java.util.ArrayList JavaDoc getListGroupsNotused() {
190         return listGroupsNotused;
191     }
192
193     public void setListGroupsNotused(java.util.ArrayList JavaDoc listGroupsNotused) {
194         this.listGroupsNotused = listGroupsNotused;
195     }
196
197     public java.util.ArrayList JavaDoc getListRolesUser() {
198         return listRolesUser;
199     }
200
201     public void setListRolesUser(java.util.ArrayList JavaDoc listRolesUser) {
202         this.listRolesUser = listRolesUser;
203     }
204
205     public java.util.ArrayList JavaDoc getListRolesRealm() {
206         return listRolesRealm;
207     }
208
209     public void setListRolesRealm(java.util.ArrayList JavaDoc listRolesRealm) {
210         this.listRolesRealm = listRolesRealm;
211     }
212
213     public java.util.ArrayList JavaDoc getListRolesUsed() {
214         return listRolesUsed;
215     }
216
217     public void setListRolesUsed(java.util.ArrayList JavaDoc listRolesUsed) {
218         this.listRolesUsed = listRolesUsed;
219     }
220
221     public java.util.ArrayList JavaDoc getListRolesNotused() {
222         return listRolesNotused;
223     }
224
225     public void setListRolesNotused(java.util.ArrayList JavaDoc listRolesNotused) {
226         this.listRolesNotused = listRolesNotused;
227     }
228
229     public String JavaDoc getGroupsUsed() {
230         return groupsUsed;
231     }
232
233     public void setGroupsUsed(String JavaDoc groupsUsed) {
234         this.groupsUsed = groupsUsed;
235     }
236
237     public String JavaDoc getGroupsNotused() {
238         return groupsNotused;
239     }
240
241     public void setGroupsNotused(String JavaDoc groupsNotused) {
242         this.groupsNotused = groupsNotused;
243     }
244
245     public String JavaDoc getRolesUsed() {
246         return rolesUsed;
247     }
248
249     public void setRolesUsed(String JavaDoc rolesUsed) {
250         this.rolesUsed = rolesUsed;
251     }
252
253     public String JavaDoc getRolesNotused() {
254         return rolesNotused;
255     }
256
257     public void setRolesNotused(String JavaDoc rolesNotused) {
258         this.rolesNotused = rolesNotused;
259     }
260
261     public String JavaDoc[] getGroupsNotusedSelected() {
262         return groupsNotusedSelected;
263     }
264
265     public void setGroupsNotusedSelected(String JavaDoc[] groupsNotusedSelected) {
266         this.groupsNotusedSelected = groupsNotusedSelected;
267     }
268
269     public String JavaDoc[] getGroupsUsedSelected() {
270         return groupsUsedSelected;
271     }
272
273     public void setGroupsUsedSelected(String JavaDoc[] groupsUsedSelected) {
274         this.groupsUsedSelected = groupsUsedSelected;
275     }
276
277     public String JavaDoc[] getRolesNotusedSelected() {
278         return rolesNotusedSelected;
279     }
280
281     public void setRolesNotusedSelected(String JavaDoc[] rolesNotusedSelected) {
282         this.rolesNotusedSelected = rolesNotusedSelected;
283     }
284
285     public String JavaDoc[] getRolesUsedSelected() {
286         return rolesUsedSelected;
287     }
288
289     public void setRolesUsedSelected(String JavaDoc[] rolesUsedSelected) {
290         this.rolesUsedSelected = rolesUsedSelected;
291     }
292
293     public String JavaDoc getAction() {
294         return action;
295     }
296
297     public void setAction(String JavaDoc action) {
298         this.action = action;
299     }
300
301 }
Popular Tags