KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark.authentication;
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 userUniqueAttributeName;
22    private String JavaDoc groupUniqueAttributeName;
23    private String JavaDoc userPasswordAttributeName;
24    private String JavaDoc ldapUser;
25    private String JavaDoc ldapPassword;
26    private String JavaDoc groupUsersName;
27
28    private CallbackUtilities cus;
29    
30    /**
31     * Public constructor (CallbackUtilities).
32     */

33    public LDAPOptions (CallbackUtilities cus) {
34       this.cus=cus;
35       java.util.Properties JavaDoc properties=cus.getProperties();
36       try {
37          ldapPort=Integer.valueOf(properties.getProperty("LDAPPort")).intValue();
38       } catch (Exception JavaDoc ex) {
39 cus.error("LDAPOptions -> Port invalid, using default port 389");
40          ldapPort=389 ;
41       }
42
43       try {
44          structureType=Integer.valueOf(properties.getProperty("LDAPStructureType")).intValue();
45       } catch (Exception JavaDoc ex) {
46 cus.error("LDAPOptions -> Structure type invalid, using default - complex");
47          structureType=1;
48       }
49       if (structureType<0 || structureType>1) {
50 cus.error("LDAPOptions -> Structure type invalid, using default - complex");
51          structureType=1;
52       }
53
54       //boolean attributeOnly = true; // returns attributes
55

56       try {
57          ldapHost=properties.getProperty("LDAPHost");
58       } catch (Exception JavaDoc ex) {
59 cus.error("LDAPOptions -> Host invalid, using default localhost");
60          ldapHost="localhost";
61       }
62       if (ldapHost==null) {
63 cus.error("LDAPOptions -> Host invalid, using default localhost");
64          ldapHost="localhost";
65       }
66
67       try {
68          searchBase=properties.getProperty("LDAPSearchBase");
69       } catch (Exception JavaDoc ex) {
70 cus.error("LDAPOptions -> Search base invalid, not using search base");
71          searchBase="";
72       }
73       if (searchBase==null) {
74 cus.error("LDAPOptions -> Search base invalid, not using search base");
75          searchBase="";
76       }
77       
78       try {
79          groupObjectClasses=properties.getProperty("LDAPGroupObjectClasses");
80       } catch (Exception JavaDoc ex) {
81 cus.error("LDAPOptions -> Group object classes filter invalid, using organizationalUnit");
82          groupObjectClasses="organizationalUnit";
83       }
84       if (groupObjectClasses==null) {
85 cus.error("LDAPOptions -> Group object classes filter invalid, using organizationalUnit");
86          groupObjectClasses="organizationalUnit";
87       }
88
89       try {
90          userObjectClasses=properties.getProperty("LDAPUserObjectClasses");
91       } catch (Exception JavaDoc ex) {
92 cus.error("LDAPOptions -> User object classes filter invalid, using inetOrgPerson");
93          userObjectClasses="inetOrgPerson";
94       }
95       if (userObjectClasses==null) {
96 cus.error("LDAPOptions -> User object classes filter invalid, using inetOrgPerson");
97          userObjectClasses="inetOrgPerson";
98       }
99       
100       try {
101          groupUniqueAttributeName=properties.getProperty("LDAPGroupUniqueAttributeName");
102       } catch (Exception JavaDoc ex) {
103 cus.error("LDAPOptions -> Group unique attribute name invalid, using ou");
104          groupUniqueAttributeName="ou";
105       }
106       if (groupUniqueAttributeName==null) {
107 cus.error("LDAPOptions -> Group unique attribute name invalid, using ou");
108          groupUniqueAttributeName="ou";
109       }
110
111       try {
112          userUniqueAttributeName=properties.getProperty("LDAPUserUniqueAttributeName");
113       } catch (Exception JavaDoc ex) {
114 cus.error("LDAPOptions -> User unique attribute name invalid, using uid");
115          userUniqueAttributeName="uid";
116       }
117       if (userUniqueAttributeName==null) {
118 cus.error("LDAPOptions -> User unique attribute name invalid, using uid");
119          userUniqueAttributeName="uid";
120       }
121
122       try {
123          userPasswordAttributeName=properties.getProperty("LDAPUserPasswordAttributeName");
124       } catch (Exception JavaDoc ex) {
125 cus.error("LDAPOptions -> User password attribute name invalid, using password");
126          userPasswordAttributeName="password";
127       }
128       if (userPasswordAttributeName==null) {
129 cus.error("LDAPOptions -> User password attribute name invalid, using password");
130          userPasswordAttributeName="password";
131       }
132
133       try {
134          ldapUser=properties.getProperty("LDAPUser");
135       } catch (Exception JavaDoc ex) {
136 cus.error("LDAPOptions -> User invalid, leaving empty");
137          ldapUser="";
138       }
139       if (ldapUser==null) {
140 cus.error("LDAPOptions -> User invalid, leaving empty");
141          ldapUser="";
142       }
143
144       try {
145          ldapPassword=properties.getProperty("LDAPPassword");
146       } catch (Exception JavaDoc ex) {
147 cus.error("LDAPOptions -> Password invalid, leaving empty");
148             ldapPassword="";
149       }
150       if (ldapPassword==null) {
151 cus.error("LDAPOptions -> Password invalid, leaving empty");
152          ldapPassword="";
153       }
154       
155        try {
156          groupUsersName=properties.getProperty("LDAPGroupUsersName");
157       } catch (Exception JavaDoc ex) {
158 cus.error("LDAPOptions -> Name of group users invalid, using Users");
159          groupUsersName="Users";
160       }
161       if (groupUsersName==null) {
162 cus.error("LDAPOptions -> Name of group users invalid, using Users");
163          groupUsersName="Users";
164       }
165    }
166
167    /**
168     * Returns LDAP port.
169     *
170     * return LDAP port.
171     */

172    public int getPort () {
173       return ldapPort;
174    }
175
176    /**
177     * Sets LDAP port.
178     *
179     * param port LDAP port.
180     */

181    public void setPort (int port) {
182       this.ldapPort=port;
183    }
184    
185    public int getStructureType () {
186       return structureType;
187    }
188
189    public void setStructureType (int structureType) {
190       this.structureType=structureType;
191    }
192
193    /**
194     * Returns search scope.
195     *
196     * return search scope.
197     */

198    public int getSearchScope () {
199       return searchScope;
200    }
201
202    /**
203     * Returns attributeOnly.
204     *
205     * return attributeOnly.
206     */

207    public boolean getAttributeOnly () {
208       return attributeOnly;
209    }
210
211    /**
212     * Sets attributeOnly.
213     *
214     * param attributeOnly attributeOnly.
215     */

216    public void setAttributeOnly (boolean attrOnly) {
217       this.attributeOnly=attrOnly;
218    }
219
220    /**
221     * Returns LDAP host.
222     *
223     * return LDAP host.
224     */

225    public String JavaDoc getHost () {
226       return ldapHost;
227    }
228
229    /**
230     * Sets LDAP host.
231     *
232     * param host LDAP host.
233     */

234    public void setHost (String JavaDoc host) {
235       this.ldapHost=host;
236    }
237
238    /**
239     * Returns search base.
240     *
241     * return search base.
242     */

243    public String JavaDoc getSearchBase () {
244       return searchBase;
245    }
246
247    /**
248     * Sets search base.
249     *
250     * param searchBase search base.
251     */

252    public void setSearchBase (String JavaDoc searchBase) {
253       this.searchBase=searchBase;
254    }
255    
256    public String JavaDoc getGroupObjectClasses () {
257       return groupObjectClasses;
258    }
259
260    public void setGroupObjectClasses (String JavaDoc groupObjectClasses) {
261       this.groupObjectClasses=groupObjectClasses;
262    }
263    
264    /**
265     * Returns userObjectClasses.
266     *
267     * return userObjectClasses.
268     */

269    public String JavaDoc getUserObjectClasses () {
270       return userObjectClasses;
271    }
272
273    /**
274     * Sets userObjectClasses.
275     *
276     * param userObjectClasses userObjectClasses.
277     */

278    public void setUserObjectClasses (String JavaDoc userObjectClasses) {
279       this.userObjectClasses=userObjectClasses;
280    }
281    
282    public String JavaDoc getGroupUniqueAttributeName () {
283       return groupUniqueAttributeName;
284    }
285
286    public void setGroupUniqueAttributeName (String JavaDoc groupUniqueAttributeName) {
287       this.groupUniqueAttributeName=groupUniqueAttributeName;
288    }
289
290    /**
291     * Returns userUniqueAttributeName.
292     *
293     * return userUniqueAttributeName.
294     */

295    public String JavaDoc getUserUniqueAttributeName () {
296       return userUniqueAttributeName;
297    }
298
299    /**
300     * Sets userUniqueAttributeName.
301     *
302     * param userUniqueAttributeName userUniqueAttributeName.
303     */

304    public void setUserUniqueAttributeName (String JavaDoc userUniqueAttributeName) {
305       this.userUniqueAttributeName=userUniqueAttributeName;
306    }
307
308    /**
309     * Returns userPasswordAttributeName.
310     *
311     * return userPasswordAttributeName.
312     */

313    public String JavaDoc getUserPasswordAttributeName () {
314       return userPasswordAttributeName;
315    }
316
317    /**
318     * Sets userPasswordAttributeName.
319     *
320     * param userPasswordAttributeName userPasswordAttributeName.
321     */

322    public void setUserPasswordAttributeName (String JavaDoc userPasswordAttributeName) {
323       this.userPasswordAttributeName=userPasswordAttributeName;
324    }
325
326    /**
327     * Returns LDAP user.
328     *
329     * return LDAP user.
330     */

331    public String JavaDoc getUser () {
332       return ldapUser;
333    }
334
335    /**
336     * Sets LDAP user.
337     *
338     * param user LDAP user.
339     */

340    public void setUser (String JavaDoc user) {
341       this.ldapUser=user;
342    }
343
344    /**
345     * Returns LDAP password.
346     *
347     * return LDAP password.
348     */

349    public String JavaDoc getPassword () {
350       return ldapPassword;
351    }
352
353    /**
354     * Sets LDAP password.
355     *
356     * param password LDAP password.
357     */

358    public void setPassword (String JavaDoc password) {
359       this.ldapPassword=password;
360    }
361    
362    public String JavaDoc getGroupUsersName () {
363       return groupUsersName;
364    }
365
366    public void setGroupUsersName (String JavaDoc groupUsersName) {
367       this.groupUsersName=groupUsersName;
368    }
369
370 }
371
372
Popular Tags