KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2001,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 javax.servlet.http.HttpServletRequest JavaDoc;
20 import org.apache.struts.action.ActionError;
21 import org.apache.struts.action.ActionErrors;
22 import org.apache.struts.action.ActionForm;
23 import org.apache.struts.action.ActionMapping;
24 import java.net.InetAddress JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.apache.webapp.admin.ApplicationServlet;
28 import org.apache.webapp.admin.LabelValueBean;
29
30 /**
31  * Form bean for the JNDI realm page.
32  *
33  * @author Manveen Kaur
34  * @version $Revision: 1.6 $ $Date: 2004/06/28 02:14:51 $
35  */

36
37 public final class JNDIRealmForm extends RealmForm {
38
39     // ----------------------------------------------------- Instance Variables
40

41     /**
42      * The text for the connection user name.
43      */

44     private String JavaDoc connectionName = null;
45
46     /**
47      * The text for the connection Password.
48      */

49     private String JavaDoc connectionPassword = null;
50
51     /**
52      * The text for the connection URL.
53      */

54     private String JavaDoc connectionURL = null;
55
56     /**
57      * The text for the context Factory.
58      */

59     private String JavaDoc contextFactory = null;
60
61     /**
62      * The text for the digest algorithm.
63      */

64     private String JavaDoc digest = null;
65
66     /**
67      * The text for the role Base.
68      */

69     private String JavaDoc roleBase = null;
70
71     /**
72      * The text for the role name.
73      */

74     private String JavaDoc roleName = null;
75
76     /**
77      * The text for the role Pattern.
78      */

79     private String JavaDoc rolePattern = null;
80
81     /**
82      * Should we search the entire subtree for matching roles?
83      */

84     private String JavaDoc roleSubtree = "false";
85
86     /**
87      * The text for the user Base.
88      */

89     private String JavaDoc userBase = null;
90
91     /**
92      * The text for the user Password.
93      */

94     private String JavaDoc userPassword = null;
95
96     /**
97      * The text for the user Pattern.
98      */

99     private String JavaDoc userPattern = null;
100
101     /**
102      * The text for the user role name.
103      */

104     private String JavaDoc userRoleName = null;
105
106     /**
107      * The text for the user Search.
108      */

109     private String JavaDoc userSearch = null;
110
111     /**
112      * Should we search the entire subtree for matching users?
113      */

114     private String JavaDoc userSubtree = "false";
115
116     /**
117      * Set of valid values for search subtrees(true/false).
118      */

119     private List JavaDoc searchVals = null;
120
121
122     // ------------------------------------------------------------- Properties
123

124     /**
125      * Return the search Vals.
126      */

127     public List JavaDoc getSearchVals() {
128
129         return this.searchVals;
130
131     }
132
133     /**
134      * Set the search Vals.
135      */

136     public void setSearchVals(List JavaDoc searchVals) {
137
138         this.searchVals = searchVals;
139
140     }
141
142     /**
143      * Return the roleSubtree boolean Text.
144      */

145     public String JavaDoc getRoleSubtree() {
146
147         return this.roleSubtree;
148
149     }
150
151     /**
152      * Set the roleSubtree Text.
153      */

154     public void setRoleSubtree(String JavaDoc roleSubtree) {
155
156         this.roleSubtree = roleSubtree;
157
158     }
159
160     /**
161      * Return the userSubtree boolean Text.
162      */

163     public String JavaDoc getUserSubtree() {
164
165         return this.userSubtree;
166
167     }
168
169     /**
170      * Set the userSubtree Text.
171      */

172     public void setUserSubtree(String JavaDoc userSubtree) {
173
174         this.userSubtree = userSubtree;
175
176     }
177
178     /**
179      * Return the digest.
180      */

181     public String JavaDoc getDigest() {
182
183         return this.digest;
184
185     }
186
187     /**
188      * Set the digest.
189      */

190     public void setDigest(String JavaDoc digest) {
191
192         this.digest = digest;
193
194     }
195
196     /**
197      * Return the roleBase .
198      */

199     public String JavaDoc getRoleBase() {
200
201         return this.roleBase ;
202
203     }
204
205     /**
206      * Set the roleBase .
207      */

208     public void setRoleBase(String JavaDoc roleBase ) {
209
210         this.roleBase = roleBase ;
211
212     }
213
214     /**
215      * Return the role name.
216      */

217     public String JavaDoc getRoleName() {
218
219         return this.roleName ;
220
221     }
222
223     /**
224      * Set the role name Attribute .
225      */

226     public void setRoleName(String JavaDoc roleName) {
227
228         this.roleName = roleName ;
229
230     }
231
232     /**
233      * Return the userBase.
234      */

235     public String JavaDoc getUserBase() {
236
237         return this.userBase ;
238
239     }
240
241     /**
242      * Set the userBase.
243      */

244     public void setUserBase(String JavaDoc userBase ) {
245
246         this.userBase = userBase ;
247
248     }
249
250     /**
251      * Return the user role name.
252      */

253     public String JavaDoc getUserRoleName() {
254
255         return this.userRoleName ;
256
257     }
258
259     /**
260      * Set the user role name Attribute .
261      */

262     public void setUserRoleName(String JavaDoc userRoleName) {
263
264         this.userRoleName = userRoleName ;
265
266     }
267
268     /**
269      * Return the role Pattern
270      */

271     public String JavaDoc getRolePattern() {
272
273         return this.rolePattern ;
274
275     }
276
277     /**
278      * Set the role Pattern.
279      */

280     public void setRolePattern(String JavaDoc rolePattern ) {
281
282         this.rolePattern = rolePattern ;
283
284     }
285
286     /**
287      * Return the user Password .
288      */

289     public String JavaDoc getUserPassword() {
290
291         return this.userPassword ;
292
293     }
294
295     /**
296      * Set the user Password .
297      */

298     public void setUserPassword(String JavaDoc userPassword ) {
299
300         this.userPassword = userPassword ;
301
302     }
303
304
305     /**
306      * Return the user Pattern .
307      */

308     public String JavaDoc getUserPattern() {
309
310         return this.userPattern ;
311
312     }
313
314     /**
315      * Set the user user Pattern .
316      */

317     public void setUserPattern(String JavaDoc userPattern) {
318
319         this.userPattern = userPattern ;
320
321     }
322
323     /**
324      * Return the user Search.
325      */

326     public String JavaDoc getUserSearch() {
327
328         return this.userSearch;
329
330     }
331
332     /**
333      * Set the user user Search.
334      */

335     public void setUserSearch(String JavaDoc userSearch) {
336
337         this.userSearch = userSearch;
338
339     }
340
341     /**
342      * Return the connection name.
343      */

344     public String JavaDoc getConnectionName() {
345
346         return this.connectionName;
347
348     }
349
350     /**
351      * Set the connectionName.
352      */

353     public void setConnectionName(String JavaDoc connectionName) {
354
355         this.connectionName = connectionName;
356
357     }
358
359
360     /**
361      * Return the connection password.
362      */

363     public String JavaDoc getConnectionPassword() {
364
365         return this.connectionPassword;
366
367     }
368
369     /**
370      * Set the connection password.
371      */

372     public void setConnectionPassword(String JavaDoc connectionPassword) {
373
374         this.connectionPassword = connectionPassword;
375
376     }
377
378
379     /**
380      * Return the connection URL.
381      */

382     public String JavaDoc getConnectionURL() {
383
384         return this.connectionURL;
385
386     }
387
388     /**
389      * Set the connectionURL.
390      */

391     public void setConnectionURL(String JavaDoc connectionURL) {
392
393         this.connectionURL = connectionURL;
394
395     }
396
397     /**
398      * Return the context Factory .
399      */

400     public String JavaDoc getContextFactory() {
401
402         return this.contextFactory ;
403
404     }
405
406     /**
407      * Set the context Factory .
408      */

409     public void setContextFactory(String JavaDoc contextFactory ) {
410
411         this.contextFactory = contextFactory ;
412
413     }
414
415     // --------------------------------------------------------- Public Methods
416

417     /**
418      * Reset all properties to their default values.
419      *
420      * @param mapping The mapping used to select this instance
421      * @param request The servlet request we are processing
422      */

423     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
424
425         super.reset(mapping, request);
426         this.roleSubtree="false";
427         this.userSubtree="false";
428
429         this.digest = null;
430         this.roleName = null;
431         this.userRoleName = null;
432
433         this.connectionName = null;
434         this.connectionPassword = null;
435         this.connectionURL = null;
436
437         this.rolePattern = null;
438         this.roleBase = null;
439         this.userBase = null;
440         this.userPassword = null;
441         this.userPattern = null;
442         this.userSearch = null;
443         this.contextFactory = null;
444     }
445
446     /**
447      * Render this object as a String.
448      */

449     public String JavaDoc toString() {
450
451         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("UserDatabaseRealmForm[adminAction=");
452         sb.append(getAdminAction());
453         sb.append(",userSubtree=");
454         sb.append(userSubtree);
455         sb.append(",roleSubtree=");
456         sb.append(roleSubtree);
457         sb.append(",digest=");
458         sb.append(digest);
459         sb.append("',userRoleName='");
460         sb.append(userRoleName);
461         sb.append("',roleName='");
462         sb.append(roleName);
463         sb.append("',connectionName=");
464         sb.append(connectionName);
465         sb.append(",connectionPassword=");
466         sb.append(connectionPassword);
467         sb.append("',connectionURL='");
468         sb.append(connectionURL);
469         sb.append("',rolePattern=");
470         sb.append(rolePattern);
471         sb.append(",roleBase=");
472         sb.append(roleBase);
473         sb.append("',userPassword='");
474         sb.append(userPassword);
475         sb.append(",userBase=");
476         sb.append(userBase);
477         sb.append("',userPattern=");
478         sb.append(userPattern);
479         sb.append("',userSearch=");
480         sb.append(userSearch);
481         sb.append(",contextFactory=");
482         sb.append(contextFactory);
483         sb.append("',objectName='");
484         sb.append(getObjectName());
485         sb.append("',realmType=");
486         sb.append(getRealmType());
487         sb.append("]");
488         return (sb.toString());
489
490     }
491
492     /**
493      * Validate the properties that have been set from this HTTP request,
494      * and return an <code>ActionErrors</code> object that encapsulates any
495      * validation errors that have been found. If no errors are found, return
496      * <code>null</code> or an <code>ActionErrors</code> object with no
497      * recorded error messages.
498      *
499      * @param mapping The mapping used to select this instance
500      * @param request The servlet request we are processing
501      */

502
503     public ActionErrors validate(ActionMapping mapping,
504     HttpServletRequest JavaDoc request) {
505
506         ActionErrors errors = new ActionErrors();
507
508         String JavaDoc submit = request.getParameter("submit");
509
510         // front end validation when save is clicked.
511
//if (submit != null) {
512
// the following fields are required.
513

514             if ((connectionURL == null) || (connectionURL.length() < 1)) {
515                 errors.add("connectionURL",
516                 new ActionError("error.connURL.required"));
517             }
518
519             // Either userPattern or userSearch should be specified not both
520
boolean isUserPatternSpecified = false;
521             boolean isUserSearchSpecified = false;
522             if ((userPattern != null) && (userPattern.length() > 0)) {
523                 isUserPatternSpecified = true;
524             }
525
526             if ((userSearch != null) && (userSearch.length() > 0)) {
527                 isUserSearchSpecified = true;
528             }
529
530             if (isUserPatternSpecified && isUserSearchSpecified) {
531                 errors.add("userPattern" ,
532                 new ActionError("error.userPattern.userSearch.defined"));
533             }
534
535             /*if ((digest == null) || (digest.length() < 1)) {
536                 errors.add("digest",
537                 new ActionError("error.digest.required"));
538             } */

539
540             /*if ((roleName == null) || (roleName.length() < 1)) {
541                 errors.add("roleName",
542                 new ActionError("error.roleName.required"));
543             }
544
545             if ((userRoleName == null) || (userRoleName.length() < 1)) {
546                 errors.add("userRoleName",
547                 new ActionError("error.userRoleName.required"));
548             }
549
550             if ((rolePattern == null) || (rolePattern.length() < 1)) {
551                 errors.add("rolePattern",
552                 new ActionError("error.rolePattern.required"));
553             }
554
555             if ((roleBase == null) || (roleBase.length() < 1)) {
556                 errors.add("roleBase",
557                 new ActionError("error.roleBase.required"));
558             }
559
560             if ((userBase == null) || (userBase.length() < 1)) {
561                 errors.add("userBase",
562                 new ActionError("error.userBase.required"));
563             }
564
565             if ((userPassword == null) || (userPassword.length() < 1)) {
566                 errors.add("userPassword",
567                 new ActionError("error.userPassword.required"));
568             }
569
570             if ((userPattern == null) || (userPattern.length() < 1)) {
571                 errors.add("userPattern",
572                 new ActionError("error.userPattern.required"));
573             }
574
575             if ((userSearch == null) || (userSearch.length() < 1)) {
576                 errors.add("userSearch",
577                 new ActionError("error.userSearch.required"));
578             }
579
580             if ((connectionName == null) || (connectionName.length() < 1)) {
581                 errors.add("connectionName",
582                 new ActionError("error.connName.required"));
583             }
584
585             if ((connectionPassword == null) || (connectionPassword.length() < 1)) {
586                 errors.add("connectionPassword",
587                 new ActionError("error.connPassword.required"));
588             }
589
590             if ((contextFactory == null) || (contextFactory.length() < 1)) {
591                 errors.add("contextFactory",
592                 new ActionError("error.contextFactory.required"));
593             } */

594         //}
595

596         return errors;
597     }
598 }
599
Popular Tags