001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): Michel-Ange ANTON
022: * --------------------------------------------------------------------------
023: * $Id: UserMemoryRealmForm.java 6599 2005-04-21 08:59:54Z kemlerp $
024: * --------------------------------------------------------------------------
025: */
026:
027: package org.objectweb.jonas.webapp.jonasadmin.security;
028:
029: import java.util.ArrayList;
030:
031: import javax.servlet.http.HttpServletRequest;
032:
033: import org.apache.struts.action.ActionMessage;
034: import org.apache.struts.action.ActionErrors;
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionMapping;
037: import org.objectweb.jonas.webapp.jonasadmin.Jlists;
038:
039: public class UserMemoryRealmForm extends ActionForm {
040:
041: // --------------------------------------------------------- Constants
042:
043: // --------------------------------------------------------- Properties variables
044:
045: private String action = null;
046: private String user = null;
047: private String password = null;
048: private String confirmPassword = null;
049: private java.util.ArrayList listGroupsUser = new ArrayList();
050: private java.util.ArrayList listGroupsRealm = new ArrayList();
051: private java.util.ArrayList listGroupsUsed = new ArrayList();
052: private java.util.ArrayList listGroupsNotused = new ArrayList();
053: private java.util.ArrayList listRolesUser = new ArrayList();
054: private java.util.ArrayList listRolesRealm = new ArrayList();
055: private java.util.ArrayList listRolesUsed = new ArrayList();
056: private java.util.ArrayList listRolesNotused = new ArrayList();
057: private String groupsUsed = null;
058: private String groupsNotused = null;
059: private String rolesUsed = null;
060: private String rolesNotused = null;
061: private String[] groupsNotusedSelected = new String[0];
062: private String[] groupsUsedSelected = new String[0];
063: private String[] rolesNotusedSelected = new String[0];
064: private String[] rolesUsedSelected = new String[0];
065:
066: // --------------------------------------------------------- Public Methods
067:
068: /**
069: * Reset all properties to their default values.
070: *
071: * @param mapping The mapping used to select this instance
072: * @param request The servlet request we are processing
073: */
074: public void reset(ActionMapping mapping, HttpServletRequest request) {
075: password = null;
076: confirmPassword = null;
077: groupsUsed = null;
078: groupsNotused = null;
079: rolesUsed = null;
080: rolesNotused = null;
081: // Mandatory !
082: groupsNotusedSelected = new String[0];
083: groupsUsedSelected = new String[0];
084: rolesNotusedSelected = new String[0];
085: rolesUsedSelected = new String[0];
086: }
087:
088: /**
089: * Validate the properties that have been set from this HTTP request,
090: * and return an <code>ActionErrors</code> object that encapsulates any
091: * validation errors that have been found. If no errors are found, return
092: * <code>null</code> or an <code>ActionErrors</code> object with no
093: * recorded error messages.
094: *
095: * @param mapping The mapping used to select this instance
096: * @param request The servlet request we are processing
097: */
098: public ActionErrors validate(ActionMapping mapping,
099: HttpServletRequest request) {
100: ActionErrors oErrors = new ActionErrors();
101: // Create errors
102: if (action.equals("create") == true) {
103: user = user.trim();
104: if (user.length() == 0) {
105: oErrors
106: .add(
107: "user",
108: new ActionMessage(
109: "error.security.factory.memory.realm.user.name.required"));
110: }
111: if (password.length() == 0) {
112: oErrors
113: .add(
114: "password",
115: new ActionMessage(
116: "error.security.factory.memory.realm.user.password.required"));
117: }
118: if (confirmPassword.length() == 0) {
119: oErrors
120: .add(
121: "password",
122: new ActionMessage(
123: "error.security.factory.memory.realm.user.confirmPassword.required"));
124: }
125: }
126: // Create and apply errors (but this test exists only to not overload the errors)
127: if (oErrors.size() == 0) {
128: if (password.length() > 0) {
129: if (!password.equals(confirmPassword)) {
130: oErrors
131: .add(
132: "password",
133: new ActionMessage(
134: "error.security.factory.memory.realm.user.password.change.different"));
135: }
136: }
137: if ((confirmPassword.length() > 0)
138: && (password.length() == 0)) {
139: oErrors
140: .add(
141: "password",
142: new ActionMessage(
143: "error.security.factory.memory.realm.user.password.change.required"));
144: }
145: }
146: // Replace the elements in their good place
147: if (oErrors.size() > 0) {
148: listRolesUsed = Jlists.getArrayList(rolesUsed,
149: Jlists.SEPARATOR);
150: listRolesNotused = Jlists.getArrayList(rolesNotused,
151: Jlists.SEPARATOR);
152: listGroupsUsed = Jlists.getArrayList(groupsUsed,
153: Jlists.SEPARATOR);
154: listGroupsNotused = Jlists.getArrayList(groupsNotused,
155: Jlists.SEPARATOR);
156: }
157: return oErrors;
158: }
159:
160: // --------------------------------------------------------- Properties Methods
161:
162: public String getUser() {
163: return user;
164: }
165:
166: public void setUser(String user) {
167: this .user = user;
168: }
169:
170: public String getPassword() {
171: return password;
172: }
173:
174: public void setPassword(String password) {
175: this .password = password;
176: }
177:
178: public String getConfirmPassword() {
179: return confirmPassword;
180: }
181:
182: public void setConfirmPassword(String confirmPassword) {
183: this .confirmPassword = confirmPassword;
184: }
185:
186: public java.util.ArrayList getListGroupsUser() {
187: return listGroupsUser;
188: }
189:
190: public void setListGroupsUser(java.util.ArrayList listGroupsUser) {
191: this .listGroupsUser = listGroupsUser;
192: }
193:
194: public java.util.ArrayList getListGroupsRealm() {
195: return listGroupsRealm;
196: }
197:
198: public void setListGroupsRealm(java.util.ArrayList listGroupsRealm) {
199: this .listGroupsRealm = listGroupsRealm;
200: }
201:
202: public java.util.ArrayList getListGroupsUsed() {
203: return listGroupsUsed;
204: }
205:
206: public void setListGroupsUsed(java.util.ArrayList listGroupsUsed) {
207: this .listGroupsUsed = listGroupsUsed;
208: }
209:
210: public java.util.ArrayList getListGroupsNotused() {
211: return listGroupsNotused;
212: }
213:
214: public void setListGroupsNotused(
215: java.util.ArrayList listGroupsNotused) {
216: this .listGroupsNotused = listGroupsNotused;
217: }
218:
219: public java.util.ArrayList getListRolesUser() {
220: return listRolesUser;
221: }
222:
223: public void setListRolesUser(java.util.ArrayList listRolesUser) {
224: this .listRolesUser = listRolesUser;
225: }
226:
227: public java.util.ArrayList getListRolesRealm() {
228: return listRolesRealm;
229: }
230:
231: public void setListRolesRealm(java.util.ArrayList listRolesRealm) {
232: this .listRolesRealm = listRolesRealm;
233: }
234:
235: public java.util.ArrayList getListRolesUsed() {
236: return listRolesUsed;
237: }
238:
239: public void setListRolesUsed(java.util.ArrayList listRolesUsed) {
240: this .listRolesUsed = listRolesUsed;
241: }
242:
243: public java.util.ArrayList getListRolesNotused() {
244: return listRolesNotused;
245: }
246:
247: public void setListRolesNotused(java.util.ArrayList listRolesNotused) {
248: this .listRolesNotused = listRolesNotused;
249: }
250:
251: public String getGroupsUsed() {
252: return groupsUsed;
253: }
254:
255: public void setGroupsUsed(String groupsUsed) {
256: this .groupsUsed = groupsUsed;
257: }
258:
259: public String getGroupsNotused() {
260: return groupsNotused;
261: }
262:
263: public void setGroupsNotused(String groupsNotused) {
264: this .groupsNotused = groupsNotused;
265: }
266:
267: public String getRolesUsed() {
268: return rolesUsed;
269: }
270:
271: public void setRolesUsed(String rolesUsed) {
272: this .rolesUsed = rolesUsed;
273: }
274:
275: public String getRolesNotused() {
276: return rolesNotused;
277: }
278:
279: public void setRolesNotused(String rolesNotused) {
280: this .rolesNotused = rolesNotused;
281: }
282:
283: public String[] getGroupsNotusedSelected() {
284: return groupsNotusedSelected;
285: }
286:
287: public void setGroupsNotusedSelected(String[] groupsNotusedSelected) {
288: this .groupsNotusedSelected = groupsNotusedSelected;
289: }
290:
291: public String[] getGroupsUsedSelected() {
292: return groupsUsedSelected;
293: }
294:
295: public void setGroupsUsedSelected(String[] groupsUsedSelected) {
296: this .groupsUsedSelected = groupsUsedSelected;
297: }
298:
299: public String[] getRolesNotusedSelected() {
300: return rolesNotusedSelected;
301: }
302:
303: public void setRolesNotusedSelected(String[] rolesNotusedSelected) {
304: this .rolesNotusedSelected = rolesNotusedSelected;
305: }
306:
307: public String[] getRolesUsedSelected() {
308: return rolesUsedSelected;
309: }
310:
311: public void setRolesUsedSelected(String[] rolesUsedSelected) {
312: this .rolesUsedSelected = rolesUsedSelected;
313: }
314:
315: public String getAction() {
316: return action;
317: }
318:
319: public void setAction(String action) {
320: this.action = action;
321: }
322:
323: }
|