KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > usergroup > LDAPOptions


1 package org.enhydra.shark.usergroup;
2
3 import org.enhydra.shark.api.internal.working.CallbackUtilities;
4
5 /**
6  * Options for LDAP client.
7  *
8  * @author Sasa Bojanic
9  * @version 1.0
10  */

11 public class LDAPOptions {
12    private int ldapPort;
13    private int searchScope = 2; // 12.07.2004 tj: the only possible value is 2
14
private boolean attributeOnly = false; // returns attributes and their values
15
private String JavaDoc ldapHost;
16    // possible values: 0 (simple structure)and 1 (complex structure)
17
private int structureType;
18    private String JavaDoc searchBase;
19    private String JavaDoc userObjectClasses;
20    private String JavaDoc groupObjectClasses;
21    private String JavaDoc relationObjectClasses; // needed only for structureType=1
22
private String JavaDoc groupUniqueAttributeName;
23    private String JavaDoc groupDescriptionAttributeName;
24    private String JavaDoc userUniqueAttributeName;
25    private String JavaDoc relationUniqueAttributeName; //needed only for structureType=1
26
private String JavaDoc relationMemberAttributeName; //needed only for structureType=1
27
private String JavaDoc userPasswordAttributeName;
28    private String JavaDoc userRealNameAttributeName;
29    private String JavaDoc userFirstNameAttributeName;
30    private String JavaDoc userLastNameAttributeName;
31    private String JavaDoc userEmailAttributeName;
32    private String JavaDoc ldapUser;
33    private String JavaDoc ldapPassword;
34    private String JavaDoc groupGroupsName;
35    private String JavaDoc groupUsersName;
36    private String JavaDoc groupGroupRelationsName;
37    private String JavaDoc groupUserRelationsName;
38
39    private CallbackUtilities cus;
40    public LDAPOptions (CallbackUtilities cus) {
41       this.cus=cus;
42       java.util.Properties JavaDoc properties=cus.getProperties();
43       try {
44          ldapPort=Integer.valueOf(properties.getProperty("LDAPPort")).intValue();
45       } catch (Exception JavaDoc ex) {
46 cus.error("LDAPOptions -> Port invalid, using default port 389");
47          ldapPort=389 ;
48       }
49
50       try {
51          structureType=Integer.valueOf(properties.getProperty("LDAPStructureType")).intValue();
52       } catch (Exception JavaDoc ex) {
53 cus.error("LDAPOptions -> Structure type invalid, using default - complex");
54          structureType=1;
55       }
56       if (structureType<0 || structureType>1) {
57 cus.error("LDAPOptions -> Structure type invalid, using default - complex");
58          structureType=1;
59       }
60
61       //boolean attributeOnly = true; // returns attributes
62

63       try {
64          ldapHost=properties.getProperty("LDAPHost");
65       } catch (Exception JavaDoc ex) {
66 cus.error("LDAPOptions -> Host invalid, using default localhost");
67          ldapHost="localhost";
68       }
69       if (ldapHost==null) {
70 cus.error("LDAPOptions -> Host invalid, using default localhost");
71          ldapHost="localhost";
72       }
73
74       try {
75          searchBase=properties.getProperty("LDAPSearchBase");
76       } catch (Exception JavaDoc ex) {
77 cus.error("LDAPOptions -> Search base invalid, not using search base");
78          searchBase="";
79       }
80       if (searchBase==null) {
81 cus.error("LDAPOptions -> Search base invalid, not using search base");
82          searchBase="";
83       }
84
85       try {
86          groupObjectClasses=properties.getProperty("LDAPGroupObjectClasses");
87       } catch (Exception JavaDoc ex) {
88 cus.error("LDAPOptions -> Group object classes filter invalid, using organizationalUnit");
89          groupObjectClasses="organizationalUnit";
90       }
91       if (groupObjectClasses==null) {
92 cus.error("LDAPOptions -> Group object classes filter invalid, using organizationalUnit");
93          groupObjectClasses="organizationalUnit";
94       }
95       
96       if (structureType == 1){
97         try {
98            relationObjectClasses=properties.getProperty("LDAPRelationObjectClasses");
99         } catch (Exception JavaDoc ex) {
100 cus.error("LDAPOptions -> Relation object classes filter invalid, using groupOfNames");
101            relationObjectClasses="groupOfNames";
102         }
103         if (relationObjectClasses==null) {
104 cus.error("LDAPOptions -> Relation object classes filter invalid, using groupOfNames");
105            relationObjectClasses="groupOfNames";
106         }
107       }
108       
109       try {
110          userObjectClasses=properties.getProperty("LDAPUserObjectClasses");
111       } catch (Exception JavaDoc ex) {
112 cus.error("LDAPOptions -> User object classes filter invalid, using inetOrgPerson");
113          userObjectClasses="inetOrgPerson";
114       }
115       if (userObjectClasses==null) {
116 cus.error("LDAPOptions -> User object classes filter invalid, using inetOrgPerson");
117          userObjectClasses="inetOrgPerson";
118       }
119
120       try {
121          groupUniqueAttributeName=properties.getProperty("LDAPGroupUniqueAttributeName");
122       } catch (Exception JavaDoc ex) {
123 cus.error("LDAPOptions -> Group unique attribute name invalid, using ou");
124          groupUniqueAttributeName="ou";
125       }
126       if (groupUniqueAttributeName==null) {
127 cus.error("LDAPOptions -> Group unique attribute name invalid, using ou");
128          groupUniqueAttributeName="ou";
129       }
130
131       try {
132          groupDescriptionAttributeName=properties.getProperty("LDAPGroupDescriptionAttributeName");
133       } catch (Exception JavaDoc ex) {
134 cus.error("LDAPOptions -> Group description attribute name invalid, using description");
135          groupDescriptionAttributeName="description";
136       }
137       if (groupDescriptionAttributeName==null) {
138 cus.error("LDAPOptions -> Group description attribute name invalid, using description");
139          groupDescriptionAttributeName="description";
140       }
141
142       try {
143          userUniqueAttributeName=properties.getProperty("LDAPUserUniqueAttributeName");
144       } catch (Exception JavaDoc ex) {
145 cus.error("LDAPOptions -> User unique attribute name invalid, using uid");
146          userUniqueAttributeName="uid";
147       }
148       if (userUniqueAttributeName==null) {
149 cus.error("LDAPOptions -> User unique attribute name invalid, using uid");
150          userUniqueAttributeName="uid";
151       }
152       
153       if (structureType == 1) {
154         try {
155            relationUniqueAttributeName=properties.getProperty("LDAPRelationUniqueAttributeName");
156         } catch (Exception JavaDoc ex) {
157 cus.error("LDAPOptions -> relation unique attribute name invalid, using cn");
158            relationUniqueAttributeName="cn";
159         }
160         if (relationUniqueAttributeName==null) {
161 cus.error("LDAPOptions -> relation unique attribute name invalid, using cn");
162            relationUniqueAttributeName="cn";
163         }
164       }
165
166       if (structureType == 1) {
167         try {
168            relationMemberAttributeName=properties.getProperty("LDAPRelationMemberAttributeName");
169         } catch (Exception JavaDoc ex) {
170 cus.error("LDAPOptions -> relation member attribute name invalid, using member");
171            relationMemberAttributeName="member";
172         }
173         if (relationMemberAttributeName==null) {
174 cus.error("LDAPOptions -> relation member attribute name invalid, using member");
175            relationMemberAttributeName="member";
176         }
177       }
178
179       try {
180          userPasswordAttributeName=properties.getProperty("LDAPUserPasswordAttributeName");
181       } catch (Exception JavaDoc ex) {
182 cus.error("LDAPOptions -> User password attribute name invalid, using password");
183          userPasswordAttributeName="password";
184       }
185       if (userPasswordAttributeName==null) {
186 cus.error("LDAPOptions -> User password attribute name invalid, using password");
187          userPasswordAttributeName="password";
188       }
189
190       try {
191          userRealNameAttributeName=properties.getProperty("LDAPUserRealNameAttributeName");
192       } catch (Exception JavaDoc ex) {
193 cus.error("LDAPOptions -> User real name attribute name invalid, using cn");
194          userRealNameAttributeName="cn";
195       }
196       if (userRealNameAttributeName==null) {
197 cus.error("LDAPOptions -> User real name attribute name invalid, using cn");
198          userRealNameAttributeName="cn";
199       }
200
201        try {
202          userFirstNameAttributeName=properties.getProperty("LDAPUserFirstNameAttributeName");
203       } catch (Exception JavaDoc ex) {
204 cus.error("LDAPOptions -> User first name attribute name invalid, using givenName");
205          userFirstNameAttributeName="givenName";
206       }
207       if (userFirstNameAttributeName==null) {
208 cus.error("LDAPOptions -> User first name attribute name invalid, using givenName");
209          userFirstNameAttributeName="givenName";
210       }
211
212        try {
213          userLastNameAttributeName=properties.getProperty("LDAPUserLastNameAttributeName");
214       } catch (Exception JavaDoc ex) {
215 cus.error("LDAPOptions -> User last name attribute name invalid, using sn");
216          userLastNameAttributeName="sn";
217       }
218       if (userLastNameAttributeName==null) {
219 cus.error("LDAPOptions -> User last name attribute name invalid, using sn");
220          userLastNameAttributeName="sn";
221       }
222
223       try {
224          userEmailAttributeName=properties.getProperty("LDAPUserEmailAttributeName");
225       } catch (Exception JavaDoc ex) {
226 cus.error("LDAPOptions -> User email attribute name invalid, using mail");
227          userEmailAttributeName="mail";
228       }
229       if (userEmailAttributeName==null) {
230 cus.error("LDAPOptions -> User email attribute name invalid, using mail");
231          userEmailAttributeName="mail";
232       }
233
234       try {
235          ldapUser=properties.getProperty("LDAPUser");
236       } catch (Exception JavaDoc ex) {
237 cus.error("LDAPOptions -> User invalid, leaving empty");
238          ldapUser="";
239       }
240       if (ldapUser==null) {
241 cus.error("LDAPOptions -> User invalid, leaving empty");
242          ldapUser="";
243       }
244
245       try {
246          ldapPassword=properties.getProperty("LDAPPassword");
247       } catch (Exception JavaDoc ex) {
248 cus.error("LDAPOptions -> Password invalid, leaving empty");
249             ldapPassword="";
250       }
251       if (ldapPassword==null) {
252 cus.error("LDAPOptions -> Password invalid, leaving empty");
253          ldapPassword="";
254       }
255
256    if (structureType == 1){
257       try {
258          groupGroupsName=properties.getProperty("LDAPGroupGroupsName");
259       } catch (Exception JavaDoc ex) {
260 cus.error("LDAPOptions -> Name of group groups invalid, using Groups");
261          groupGroupsName="Groups";
262       }
263       if (groupGroupsName==null) {
264 cus.error("LDAPOptions -> Name of group groups invalid, using Groups");
265          groupGroupsName="Groups";
266       }
267       
268       try {
269          groupUsersName=properties.getProperty("LDAPGroupUsersName");
270       } catch (Exception JavaDoc ex) {
271 cus.error("LDAPOptions -> Name of group users invalid, using Users");
272          groupUsersName="Users";
273       }
274       if (groupUsersName==null) {
275 cus.error("LDAPOptions -> Name of group users invalid, using Users");
276          groupUsersName="Users";
277       }
278
279       try {
280            groupGroupRelationsName=properties.getProperty("LDAPGroupGroupRelationsName");
281       } catch (Exception JavaDoc ex) {
282 cus.error("LDAPOptions -> Name of group group relations invalid, using GroupRelations");
283          groupGroupRelationsName="GroupRelations";
284       }
285       if (groupGroupRelationsName==null) {
286 cus.error("LDAPOptions -> Name of group group relations invalid, using GroupRelations");
287          groupGroupRelationsName="GroupRelations";
288       }
289     
290       try {
291            groupUserRelationsName=properties.getProperty("LDAPGroupUserRelationsName");
292       } catch (Exception JavaDoc ex) {
293 cus.error("LDAPOptions -> Name of group user relations invalid, using UserRelations");
294          groupUserRelationsName="UserRelations";
295       }
296       if (groupUserRelationsName==null) {
297 cus.error("LDAPOptions -> Name of group user relations invalid, using UserRelations");
298          groupUserRelationsName="UserRelations";
299       }
300    
301     } // if structureType == 1
302

303    }
304
305    public int getPort () {
306       return ldapPort;
307    }
308
309    public void setPort (int port) {
310       this.ldapPort=port;
311    }
312
313    public int getStructureType () {
314       return structureType;
315    }
316
317    public void setStructureType (int structureType) {
318       this.structureType=structureType;
319    }
320
321    public int getSearchScope () {
322       return searchScope;
323    }
324
325    public boolean getAttributeOnly () {
326       return attributeOnly;
327    }
328
329    public void setAttributeOnly (boolean attrOnly) {
330       this.attributeOnly=attrOnly;
331    }
332
333    public String JavaDoc getHost () {
334       return ldapHost;
335    }
336
337    public void setHost (String JavaDoc host) {
338       this.ldapHost=host;
339    }
340
341    public String JavaDoc getSearchBase () {
342       return searchBase;
343    }
344
345    public void setSearchBase (String JavaDoc searchBase) {
346       this.searchBase=searchBase;
347    }
348
349    public String JavaDoc getGroupObjectClasses () {
350       return groupObjectClasses;
351    }
352
353    public void setGroupObjectClasses (String JavaDoc groupObjectClasses) {
354       this.groupObjectClasses=groupObjectClasses;
355    }
356    
357    public String JavaDoc getRelationObjectClasses () {
358       return relationObjectClasses;
359    }
360
361    public void setRelationObjectClasses (String JavaDoc relationObjectClasses) {
362       this.relationObjectClasses=relationObjectClasses;
363    }
364
365    public String JavaDoc getUserObjectClasses () {
366       return userObjectClasses;
367    }
368
369    public void setUserObjectClasses (String JavaDoc userObjectClasses) {
370       this.userObjectClasses=userObjectClasses;
371    }
372
373    public String JavaDoc getGroupUniqueAttributeName () {
374       return groupUniqueAttributeName;
375    }
376
377    public void setGroupUniqueAttributeName (String JavaDoc groupUniqueAttributeName) {
378       this.groupUniqueAttributeName=groupUniqueAttributeName;
379    }
380
381    public String JavaDoc getGroupDescriptionAttributeName () {
382       return groupDescriptionAttributeName;
383    }
384
385    public void setGroupDescriptionAttributeName (String JavaDoc groupDescriptionAttributeName) {
386       this.groupDescriptionAttributeName=groupDescriptionAttributeName;
387    }
388
389    public String JavaDoc getUserUniqueAttributeName () {
390       return userUniqueAttributeName;
391    }
392
393    public void setUserUniqueAttributeName (String JavaDoc userUniqueAttributeName) {
394       this.userUniqueAttributeName=userUniqueAttributeName;
395    }
396    
397    public String JavaDoc getRelationUniqueAttributeName () {
398       return relationUniqueAttributeName;
399    }
400
401    public void setRelationUniqueAttributeName (String JavaDoc relationUniqueAttributeName) {
402       this.relationUniqueAttributeName=relationUniqueAttributeName;
403    }
404    
405    public String JavaDoc getRelationMemberAttributeName () {
406       return relationMemberAttributeName;
407    }
408
409    public void setRelationMemberAttributeName (String JavaDoc relationMemberAttributeName) {
410       this.relationMemberAttributeName=relationMemberAttributeName;
411    }
412
413    public String JavaDoc getUserPasswordAttributeName () {
414       return userPasswordAttributeName;
415    }
416
417    public void setUserPasswordAttributeName (String JavaDoc userPasswordAttributeName) {
418       this.userPasswordAttributeName=userPasswordAttributeName;
419    }
420
421    public String JavaDoc getUserRealNameAttributeName () {
422       return userRealNameAttributeName;
423    }
424
425    public void setUserRealNameAttributeName(String JavaDoc userRealNameAttributeName) {
426       this.userRealNameAttributeName=userRealNameAttributeName;
427    }
428
429    public String JavaDoc getUserFirstNameAttributeName () {
430       return userFirstNameAttributeName;
431    }
432
433    public void setUserFirstNameAttributeName(String JavaDoc userFirstNameAttributeName) {
434       this.userFirstNameAttributeName=userFirstNameAttributeName;
435    }
436
437    public String JavaDoc getUserLastNameAttributeName () {
438       return userLastNameAttributeName;
439    }
440
441    public void setUserLastNameAttributeName(String JavaDoc userLastNameAttributeName) {
442       this.userLastNameAttributeName=userLastNameAttributeName;
443    }
444
445    public String JavaDoc getUserEmailAttributeName () {
446       return userEmailAttributeName;
447    }
448
449    public void setUserEmailAttributeName(String JavaDoc userEmailAttributeName) {
450       this.userEmailAttributeName=userEmailAttributeName;
451    }
452
453    public String JavaDoc getUser () {
454       return ldapUser;
455    }
456
457    public void setUser (String JavaDoc user) {
458       this.ldapUser=user;
459    }
460
461    public String JavaDoc getPassword () {
462       return ldapPassword;
463    }
464
465    public void setPassword (String JavaDoc password) {
466       this.ldapPassword=password;
467    }
468    
469    public String JavaDoc getGroupGroupsName () {
470       return groupGroupsName;
471    }
472
473    public void setGroupGroupsName (String JavaDoc groupGroupsName) {
474       this.groupGroupsName=groupGroupsName;
475    }
476    
477    public String JavaDoc getGroupUsersName () {
478       return groupUsersName;
479    }
480
481    public void setGroupUsersName (String JavaDoc groupUsersName) {
482       this.groupUsersName=groupUsersName;
483    }
484    
485    public String JavaDoc getGroupGroupRelationsName () {
486       return groupGroupRelationsName;
487    }
488
489    public void setGroupGroupRelationsName (String JavaDoc groupGroupRelationsName) {
490       this.groupGroupRelationsName=groupGroupRelationsName;
491    }
492    
493    public String JavaDoc getGroupUserRelationsName () {
494       return groupUserRelationsName;
495    }
496
497    public void setGroupUserRelationsName (String JavaDoc groupUserRelationsName) {
498       this.groupUserRelationsName=groupUserRelationsName;
499    }
500
501 }
502
503
Popular Tags