KickJava   Java API By Example, From Geeks To Geeks.

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


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  * --------------------------------------------------------------------------
22  * $Id: LdapRealmForm.java,v 1.7 2005/04/21 08:59:54 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.security;
27
28 import java.util.List JavaDoc;
29
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31
32 import org.apache.struts.action.ActionMessage;
33 import org.apache.struts.action.ActionErrors;
34 import org.apache.struts.action.ActionMapping;
35 import org.objectweb.jonas.webapp.jonasadmin.Jlists;
36
37 /**
38  * @author Michel-Ange ANTON
39  */

40 public class LdapRealmForm extends FactoryRealmForm {
41
42 // --------------------------------------------------------- Constants
43

44 // --------------------------------------------------------- Properties variables
45

46     private String JavaDoc authenticationMode = null;
47     private String JavaDoc baseDn = null;
48     private String JavaDoc initialContextFactory = null;
49     private String JavaDoc language = null;
50     private String JavaDoc providerUrl = null;
51     private String JavaDoc referral = null;
52     private String JavaDoc roleDn = null;
53     private String JavaDoc roleNameAttribute = null;
54     private String JavaDoc roleSearchFilter = null;
55     private String JavaDoc securityAuthentication = null;
56     private String JavaDoc securityCredentials = null;
57     private String JavaDoc securityPrincipal = null;
58     private String JavaDoc securityProtocol = null;
59     private String JavaDoc stateFactories = null;
60     private String JavaDoc userDn = null;
61     private String JavaDoc userPasswordAttribute = null;
62     private String JavaDoc userRolesAttribute = null;
63     private String JavaDoc userSearchFilter = null;
64     private String JavaDoc algorithm = null;
65
66     private List JavaDoc securityAuthenticationLdapValues = Jlists.getSecurityAuthenticationLdapValues();
67     private List JavaDoc authenticationModeLdapValues = Jlists.getAuthenticationModeLdapValues();
68     private List JavaDoc securityAlgorithms = Jlists.getSecurityAlgorithms();
69
70 // --------------------------------------------------------- Public Methods
71

72     /**
73      * Reset all properties to their default values.
74      *
75      * @param mapping The mapping used to select this instance
76      * @param request The servlet request we are processing
77      */

78
79     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
80         super.reset(mapping, request);
81
82         authenticationMode = "bind";
83         baseDn = null;
84         initialContextFactory = "com.sun.jndi.ldap.LdapCtxFactory";
85         language = null;
86         providerUrl = "ldap://localhost:389";
87         referral = null;
88         roleDn = null;
89         roleNameAttribute = "cn";
90         roleSearchFilter = "uniqueMember={0}";
91         securityAuthentication = "simple";
92         securityCredentials = null;
93         securityPrincipal = null;
94         securityProtocol = null;
95         stateFactories = null;
96         userDn = null;
97         userPasswordAttribute = "userPassword";
98         userRolesAttribute = "memberOf";
99         userSearchFilter = "uid={0}";
100     }
101
102     /**
103      * Validate the properties that have been set from this HTTP request,
104      * and return an <code>ActionErrors</code> object that encapsulates any
105      * validation errors that have been found. If no errors are found, return
106      * <code>null</code> or an <code>ActionErrors</code> object with no
107      * recorded error messages.
108      *
109      * @param mapping The mapping used to select this instance
110      * @param request The servlet request we are processing
111      * @return List of errors
112      */

113     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
114         ActionErrors oErrors = new ActionErrors();
115         if ((getName() == null) || (getName().length() == 0)) {
116             oErrors.add("name", new ActionMessage("error.security.factory.ldap.realm.name.required"));
117         }
118         if ((baseDn == null) || (baseDn.length() == 0)) {
119             oErrors.add("baseDn"
120                 , new ActionMessage("error.security.factory.ldap.realm.baseDn.required"));
121         }
122         if ((initialContextFactory == null) || (initialContextFactory.length() == 0)) {
123             oErrors.add("initialContextFactory"
124                 , new ActionMessage("error.security.factory.ldap.realm.initialContextFactory.required"));
125             initialContextFactory = "com.sun.jndi.ldap.LdapCtxFactory";
126         }
127         if ((providerUrl == null) || (providerUrl.length() == 0)) {
128             oErrors.add("providerUrl"
129                 , new ActionMessage("error.security.factory.ldap.realm.providerUrl.required"));
130             providerUrl = "ldap://localhost:389";
131         }
132         if ((roleNameAttribute == null) || (roleNameAttribute.length() == 0)) {
133             oErrors.add("roleNameAttribute"
134                 , new ActionMessage("error.security.factory.ldap.realm.roleNameAttribute.required"));
135             roleNameAttribute = "cn";
136         }
137         if ((roleSearchFilter == null) || (roleSearchFilter.length() == 0)) {
138             oErrors.add("roleSearchFilter"
139                 , new ActionMessage("error.security.factory.ldap.realm.roleSearchFilter.required"));
140             roleSearchFilter = "uniqueMember={0}";
141         }
142         if ((userPasswordAttribute == null) || (userPasswordAttribute.length() == 0)) {
143             oErrors.add("userPasswordAttribute"
144                 , new ActionMessage("error.security.factory.ldap.realm.userPasswordAttribute.required"));
145             userPasswordAttribute = "userPassword";
146         }
147         if ((userRolesAttribute == null) || (userRolesAttribute.length() == 0)) {
148             oErrors.add("userRolesAttribute"
149                 , new ActionMessage("error.security.factory.ldap.realm.userRolesAttribute.required"));
150             userRolesAttribute = "memberOf";
151         }
152         if ((userSearchFilter == null) || (userSearchFilter.length() == 0)) {
153             oErrors.add("userSearchFilter"
154                 , new ActionMessage("error.security.factory.ldap.realm.userSearchFilter.required"));
155             userSearchFilter = "uid={0}";
156         }
157         return oErrors;
158     }
159
160 // --------------------------------------------------------- Properties Methods
161

162     public String JavaDoc getAuthenticationMode() {
163         return authenticationMode;
164     }
165
166     public void setAuthenticationMode(String JavaDoc authenticationMode) {
167         this.authenticationMode = authenticationMode;
168     }
169
170     public String JavaDoc getBaseDn() {
171         return baseDn;
172     }
173
174     public void setBaseDn(String JavaDoc baseDn) {
175         this.baseDn = baseDn;
176     }
177
178     public String JavaDoc getInitialContextFactory() {
179         return initialContextFactory;
180     }
181
182     public void setInitialContextFactory(String JavaDoc initialContextFactory) {
183         this.initialContextFactory = initialContextFactory;
184     }
185
186     public String JavaDoc getLanguage() {
187         return language;
188     }
189
190     public void setLanguage(String JavaDoc language) {
191         this.language = language;
192     }
193
194     public String JavaDoc getProviderUrl() {
195         return providerUrl;
196     }
197
198     public void setProviderUrl(String JavaDoc providerUrl) {
199         this.providerUrl = providerUrl;
200     }
201
202     public String JavaDoc getReferral() {
203         return referral;
204     }
205
206     public void setReferral(String JavaDoc referral) {
207         this.referral = referral;
208     }
209
210     public String JavaDoc getRoleDn() {
211         return roleDn;
212     }
213
214     public void setRoleDn(String JavaDoc roleDn) {
215         this.roleDn = roleDn;
216     }
217
218     public String JavaDoc getRoleNameAttribute() {
219         return roleNameAttribute;
220     }
221
222     public void setRoleNameAttribute(String JavaDoc roleNameAttribute) {
223         this.roleNameAttribute = roleNameAttribute;
224     }
225
226     public String JavaDoc getRoleSearchFilter() {
227         return roleSearchFilter;
228     }
229
230     public void setRoleSearchFilter(String JavaDoc roleSearchFilter) {
231         this.roleSearchFilter = roleSearchFilter;
232     }
233
234     public String JavaDoc getSecurityAuthentication() {
235         return securityAuthentication;
236     }
237
238     public void setSecurityAuthentication(String JavaDoc securityAuthentication) {
239         this.securityAuthentication = securityAuthentication;
240     }
241
242     public String JavaDoc getSecurityCredentials() {
243         return securityCredentials;
244     }
245
246     public void setSecurityCredentials(String JavaDoc securityCredentials) {
247         this.securityCredentials = securityCredentials;
248     }
249
250     public String JavaDoc getSecurityPrincipal() {
251         return securityPrincipal;
252     }
253
254     public void setSecurityPrincipal(String JavaDoc securityPrincipal) {
255         this.securityPrincipal = securityPrincipal;
256     }
257
258     public String JavaDoc getSecurityProtocol() {
259         return securityProtocol;
260     }
261
262     public void setSecurityProtocol(String JavaDoc securityProtocol) {
263         this.securityProtocol = securityProtocol;
264     }
265
266     public String JavaDoc getStateFactories() {
267         return stateFactories;
268     }
269
270     public void setStateFactories(String JavaDoc stateFactories) {
271         this.stateFactories = stateFactories;
272     }
273
274     public String JavaDoc getUserDn() {
275         return userDn;
276     }
277
278     public void setUserDn(String JavaDoc userDn) {
279         this.userDn = userDn;
280     }
281
282     public String JavaDoc getUserPasswordAttribute() {
283         return userPasswordAttribute;
284     }
285
286     public void setUserPasswordAttribute(String JavaDoc userPasswordAttribute) {
287         this.userPasswordAttribute = userPasswordAttribute;
288     }
289
290     public String JavaDoc getUserRolesAttribute() {
291         return userRolesAttribute;
292     }
293
294     public void setUserRolesAttribute(String JavaDoc userRolesAttribute) {
295         this.userRolesAttribute = userRolesAttribute;
296     }
297
298     public String JavaDoc getUserSearchFilter() {
299         return userSearchFilter;
300     }
301
302     public void setUserSearchFilter(String JavaDoc userSearchFilter) {
303         this.userSearchFilter = userSearchFilter;
304     }
305
306     public List JavaDoc getSecurityAuthenticationLdapValues() {
307         return securityAuthenticationLdapValues;
308     }
309
310     public List JavaDoc getAuthenticationModeLdapValues() {
311         return authenticationModeLdapValues;
312     }
313
314     public String JavaDoc getAlgorithm() {
315         return algorithm;
316     }
317
318     public void setAlgorithm(String JavaDoc algorithm) {
319         this.algorithm = algorithm;
320     }
321
322     public List JavaDoc getSecurityAlgorithms() {
323         return securityAlgorithms;
324     }
325
326 }
Popular Tags