KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > ldap > LDAPModel


1 package com.knowgate.ldap;
2
3 /*
4   Copyright (C) 2004 Know Gate S.L. All rights reserved.
5                       C/Oņa, 107 1š2 28050 Madrid (Spain)
6
7   Redistribution and use in source and binary forms, with or without
8   modification, are permitted provided that the following conditions
9   are met:
10
11   1. Redistributions of source code must retain the above copyright
12      notice, this list of conditions and the following disclaimer.
13
14   2. The end-user documentation included with the redistribution,
15      if any, must include the following acknowledgment:
16      "This product includes software parts from hipergate
17      (http://www.hipergate.org/)."
18      Alternately, this acknowledgment may appear in the software itself,
19      if and wherever such third-party acknowledgments normally appear.
20
21   3. The name hipergate must not be used to endorse or promote products
22      derived from this software without prior written permission.
23      Products derived from this software may not be called hipergate,
24      nor may hipergate appear in their name, without prior written
25      permission.
26
27   This library is distributed in the hope that it will be useful,
28   but WITHOUT ANY WARRANTY; without even the implied warranty of
29   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
30
31   You should have received a copy of hipergate License with this code;
32   if not, visit http://www.hipergate.org or mail to info@hipergate.org
33 */

34
35 import java.util.Properties JavaDoc;
36 import java.sql.Connection JavaDoc;
37 import java.sql.SQLException JavaDoc;
38
39 /**
40  * LDAP Abstract Base Class
41  * @author Sergio Montoro Ten
42  * @version 1.0
43  */

44
45 public abstract class LDAPModel {
46
47   /**
48    * <p>Connect to LDAP Service</p>
49    * At this point, there is no authentication, and any operations are conducted as an anonymous client.
50    * @param sConnStr ldap://<i>host</i>:port/<i>distinguished_name</i><br><b>Example</b> "ldap://fobos.kg.int:389/dc=hipergate,dc=org"
51    * @throws LDAPException
52    */

53
54   public abstract void connect (String JavaDoc sConnStr) throws LDAPException;
55
56   /**
57    * <P>Connect to LDAP Server using a Properties object</P>
58    * @param oProps Properties for connecting to LDAP server.<BR>
59    * For example :<BR>
60    * ldapconnect=ldap://fobos.kg.int:389/dc=hipergate,dc=org<BR>
61    * ldapuser=cn=Manager,dc=hipergate,dc=org<BR>
62    * ldappassword=manager<BR>
63    * @throws LDAPException
64    */

65
66   public abstract void connectAndBind (Properties JavaDoc oProps) throws LDAPException;
67
68   /**
69    * <p>Synchronously authenticates to the LDAP server using LDAP_V3.</p>
70    * If the object has been disconnected from an LDAP server, this method attempts to reconnect to the server. If the object has already authenticated, the old authentication is discarded.
71    * @param sUser If non-null and non-empty, specifies that the connection and all operations through it should be authenticated with dn as the distinguished name.
72    * @param sPass If non-null and non-empty, specifies that the connection and all operations through it should be authenticated with dn as the distinguished name and passwd as password.
73    * @throws LDAPException
74    * @throws IllegalStateException If not conencted to LDAP
75    */

76
77   public abstract void bind (String JavaDoc sUser, String JavaDoc sPass) throws LDAPException;
78
79   /**
80    * <p>Synchronously disconnects from the LDAP server</p>
81    * The disconnect method abandons any outstanding requests, issues an unbind request to the server, and then closes the socket.
82    * @throws LDAPException
83    */

84
85   public abstract void disconnect() throws LDAPException;
86
87   /**
88    * <p>Check whether or not an LDAP entry exists</p>
89    * The directory is searched from the connection string key.<br>
90    * For example if ldapconnect connection property is ldap://192.168.1.1:389/dc=hipergate,dc=org
91    * then only entries under "dc=hipergate,dc=org" will be searched
92    * @param sSearchString LDAP search string, for example "cn=user@mail.com,dc=publicContacts,dc=my_workarea,dc=my_domain"
93    * @throws LDAPException
94    */

95
96   public abstract boolean exists (String JavaDoc sSearchString) throws LDAPException;
97
98   /**
99    * Drop an entire LDAP directory
100    * @throws LDAPException
101    * @throws IllegalStateException If not connected to LDAP
102    */

103
104   public abstract void dropAll () throws LDAPException;
105
106   /**
107    * <p>Add an address from v_ldap_contacts view to an LDAP directory</p>
108    * Addresses may be either public or private depending on the value of field
109    * v_ldap_contacts.bo_private. If bo_private is zero then the address is public,
110    * if bo_private is not zero then the address is private.<br>
111    * Private addresses are only visible to the user that created them.<br>
112    * Public addresses are stored at cn=<i>user@mail.com</i>,dc=publicContacts,dc=<i>workarea_name</i>,dc=<i>domain_name</i>,dc=hipergate,dc=org<br>
113    * Private addresses are stored at cn=<i>user@mail.com</i>,dc=privateContacts,cn=<i>owner_guid</i>,dc=users,dc=<i>domain_name</i>,dc=hipergate,dc=org
114    * @param oJdbc JDBC Connection
115    * @param sAddrId GUID of address to be added
116    * @throws com.knowgate.ldap.LDAPException If address already exists at directory
117    * @throws SQLException If sAddrId is not found at v_ldap_contacts SQL view
118    * @throws IllegalStateException If not connected to LDAP
119    */

120
121   public abstract void addAddress (Connection JavaDoc oJdbc, String JavaDoc sAddrId) throws LDAPException, SQLException JavaDoc;
122
123   /**
124    * <p>Add or replace an Address</p>
125    * This method is the same as addAddress() except that it does not raise an
126    * LDAPException if address already exists; in that case address is just replaced.
127    * @param oJdbc JDBC Connection
128    * @param sAddrId GUID of address to be added or replaced
129    * @throws LDAPException
130    * @throws SQLException
131    */

132
133   public abstract void addOrReplaceAddress (Connection JavaDoc oJdbc, String JavaDoc sAddrId) throws LDAPException, SQLException JavaDoc;
134
135   /**
136    * Delete an address from LDAP directory
137    * @param oJdbc JDBC Connection
138    * @param sAddrId GUID of address to be deleted
139    * @throws LDAPException
140    * @throws SQLException If sAddrId is not found at v_ldap_contacts SQL view
141    * @throws IllegalStateException If not connected to LDAP
142    */

143
144   public abstract void deleteAddress (Connection JavaDoc oJdbc, String JavaDoc sAddrId) throws LDAPException, SQLException JavaDoc;
145
146   /**
147    * <p>Add a User from v_ldap_users view to an LDAP directory</p>
148    * Users are added under cn=<i>user@mail.com</i>,dc=users,dc=<i>workarea_name</i>,dc=<i>domain_name</i>,dc=hipergate,dc=org
149    * @param oJdbc JDBC Connection
150    * @param sUserId GUID of user to be added
151    * @throws LDAPException
152    * @throws SQLException If sUserId is not found at v_ldap_users SQL view
153    * @throws IllegalStateException If not connected to LDAP
154    */

155
156   /**
157    * <p>Add a User from v_ldap_users view to an LDAP directory</p>
158    * Users are added under cn=<i>user@mail.com</i>,dc=users,dc=<i>workarea_name</i>,dc=<i>domain_name</i>,dc=hipergate,dc=org
159    * @param oJdbc JDBC Connection
160    * @param sUserId GUID of user to be added
161    * @throws LDAPException
162    * @throws SQLException If sUserId is not found at v_ldap_users SQL view
163    * @throws IllegalStateException If not connected to LDAP
164    */

165
166   public abstract void addUser (Connection JavaDoc oJdbc, String JavaDoc sUserId) throws LDAPException, SQLException JavaDoc;
167
168
169   /**
170    * Add or replace a User from v_ldap_users SQL view to the LDAP directory
171    * @param oJdbc JDBC database connection
172    * @param sUserId GUID of user to be added or replaced
173    * @throws com.knowgate.ldap.LDAPException
174    * @throws java.sql.SQLException
175    */

176
177   public abstract void addOrReplaceUser (Connection JavaDoc oJdbc, String JavaDoc sUserId) throws LDAPException, SQLException JavaDoc;
178
179   /**
180     * Delete a User from LDAP directory
181     * @param oJdbc JDBC Connection
182     * @param sUserId GUID of user to be added
183     * @throws LDAPException
184     * @throws SQLException If sUserId is not found at v_ldap_users SQL view
185     */

186
187   public abstract void deleteUser (Connection JavaDoc oJdbc, String JavaDoc sUserId) throws LDAPException, SQLException JavaDoc;
188
189   /**
190    * <P>Load all users and contact address from a Domain into an LDAP directory</P>
191    * @param oJdbc JDBC Connection
192    * @param iDomainId Numeric Identifier for Domain
193    * @throws LDAPException
194    * @throws SQLException
195    */

196
197   public abstract void loadDomain (Connection JavaDoc oJdbc, int iDomainId) throws LDAPException, SQLException JavaDoc;
198
199   /**
200    * <P>Load all users and contact address from a WorkArea into an LDAP directory</P>
201    * @param oJdbc JDBC Connection
202    * @param sDomainNm Name for Domain containing the WorkArea
203    * @param sWorkAreaNm WorkArea Name
204    * @throws LDAPException
205    * @throws SQLException
206    */

207
208   public abstract void loadWorkArea (Connection JavaDoc oJdbc, String JavaDoc sDomainNm, String JavaDoc sWorkAreaNm) throws LDAPException, SQLException JavaDoc;
209
210   /**
211    * <p>Delete a WorkArea from the LDAP directory</p>
212    * All entries under dc=<i>sDomainNm</i>,dc=hipergate,dc=org that match dc=<i>sWorkAreaNm</i> are deleted
213    * @param sDomainNm Domain Name
214    * @param sWorkAreaNm WorkArea Name
215    * @throws LDAPException
216    * @throws IllegalStateException If not connected to LDAP
217    */

218
219   public abstract void deleteWorkArea (String JavaDoc sDomainNm, String JavaDoc sWorkAreaNm) throws LDAPException, IllegalStateException JavaDoc;
220
221   // ---------------------------------------------------------------------------
222

223   public static final int PWD_CLEAR_TEXT = 0;
224   public static final int PWD_DTIP_RC4 = 1;
225
226   public static final short USER_NOT_FOUND = -1;
227   public static final short INVALID_PASSWORD = -2;
228   public static final short ACCOUNT_DEACTIVATED = -3;
229   public static final short SESSION_EXPIRED = -4;
230   public static final short DOMAIN_NOT_FOUND = -5;
231   public static final short WORKAREA_NOT_FOUND = -6;
232   public static final short WORKAREA_NOT_SET = -7;
233   public static final short ACCOUNT_CANCELLED = -8;
234   public static final short PASSWORD_EXPIRED = -9;
235   public static final short INTERNAL_ERROR = -255;
236 }
Popular Tags