001: package com.knowgate.ldap;
002:
003: /*
004: Copyright (C) 2004 Know Gate S.L. All rights reserved.
005: C/Oņa, 107 1š2 28050 Madrid (Spain)
006:
007: Redistribution and use in source and binary forms, with or without
008: modification, are permitted provided that the following conditions
009: are met:
010:
011: 1. Redistributions of source code must retain the above copyright
012: notice, this list of conditions and the following disclaimer.
013:
014: 2. The end-user documentation included with the redistribution,
015: if any, must include the following acknowledgment:
016: "This product includes software parts from hipergate
017: (http://www.hipergate.org/)."
018: Alternately, this acknowledgment may appear in the software itself,
019: if and wherever such third-party acknowledgments normally appear.
020:
021: 3. The name hipergate must not be used to endorse or promote products
022: derived from this software without prior written permission.
023: Products derived from this software may not be called hipergate,
024: nor may hipergate appear in their name, without prior written
025: permission.
026:
027: This library is distributed in the hope that it will be useful,
028: but WITHOUT ANY WARRANTY; without even the implied warranty of
029: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
030:
031: You should have received a copy of hipergate License with this code;
032: if not, visit http://www.hipergate.org or mail to info@hipergate.org
033: */
034:
035: import java.util.Properties;
036: import java.sql.Connection;
037: import java.sql.SQLException;
038:
039: /**
040: * LDAP Abstract Base Class
041: * @author Sergio Montoro Ten
042: * @version 1.0
043: */
044:
045: public abstract class LDAPModel {
046:
047: /**
048: * <p>Connect to LDAP Service</p>
049: * At this point, there is no authentication, and any operations are conducted as an anonymous client.
050: * @param sConnStr ldap://<i>host</i>:port/<i>distinguished_name</i><br><b>Example</b> "ldap://fobos.kg.int:389/dc=hipergate,dc=org"
051: * @throws LDAPException
052: */
053:
054: public abstract void connect(String sConnStr) throws LDAPException;
055:
056: /**
057: * <P>Connect to LDAP Server using a Properties object</P>
058: * @param oProps Properties for connecting to LDAP server.<BR>
059: * For example :<BR>
060: * ldapconnect=ldap://fobos.kg.int:389/dc=hipergate,dc=org<BR>
061: * ldapuser=cn=Manager,dc=hipergate,dc=org<BR>
062: * ldappassword=manager<BR>
063: * @throws LDAPException
064: */
065:
066: public abstract void connectAndBind(Properties oProps)
067: throws LDAPException;
068:
069: /**
070: * <p>Synchronously authenticates to the LDAP server using LDAP_V3.</p>
071: * 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.
072: * @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.
073: * @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.
074: * @throws LDAPException
075: * @throws IllegalStateException If not conencted to LDAP
076: */
077:
078: public abstract void bind(String sUser, String sPass)
079: throws LDAPException;
080:
081: /**
082: * <p>Synchronously disconnects from the LDAP server</p>
083: * The disconnect method abandons any outstanding requests, issues an unbind request to the server, and then closes the socket.
084: * @throws LDAPException
085: */
086:
087: public abstract void disconnect() throws LDAPException;
088:
089: /**
090: * <p>Check whether or not an LDAP entry exists</p>
091: * The directory is searched from the connection string key.<br>
092: * For example if ldapconnect connection property is ldap://192.168.1.1:389/dc=hipergate,dc=org
093: * then only entries under "dc=hipergate,dc=org" will be searched
094: * @param sSearchString LDAP search string, for example "cn=user@mail.com,dc=publicContacts,dc=my_workarea,dc=my_domain"
095: * @throws LDAPException
096: */
097:
098: public abstract boolean exists(String sSearchString)
099: throws LDAPException;
100:
101: /**
102: * Drop an entire LDAP directory
103: * @throws LDAPException
104: * @throws IllegalStateException If not connected to LDAP
105: */
106:
107: public abstract void dropAll() throws LDAPException;
108:
109: /**
110: * <p>Add an address from v_ldap_contacts view to an LDAP directory</p>
111: * Addresses may be either public or private depending on the value of field
112: * v_ldap_contacts.bo_private. If bo_private is zero then the address is public,
113: * if bo_private is not zero then the address is private.<br>
114: * Private addresses are only visible to the user that created them.<br>
115: * 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>
116: * 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
117: * @param oJdbc JDBC Connection
118: * @param sAddrId GUID of address to be added
119: * @throws com.knowgate.ldap.LDAPException If address already exists at directory
120: * @throws SQLException If sAddrId is not found at v_ldap_contacts SQL view
121: * @throws IllegalStateException If not connected to LDAP
122: */
123:
124: public abstract void addAddress(Connection oJdbc, String sAddrId)
125: throws LDAPException, SQLException;
126:
127: /**
128: * <p>Add or replace an Address</p>
129: * This method is the same as addAddress() except that it does not raise an
130: * LDAPException if address already exists; in that case address is just replaced.
131: * @param oJdbc JDBC Connection
132: * @param sAddrId GUID of address to be added or replaced
133: * @throws LDAPException
134: * @throws SQLException
135: */
136:
137: public abstract void addOrReplaceAddress(Connection oJdbc,
138: String sAddrId) throws LDAPException, SQLException;
139:
140: /**
141: * Delete an address from LDAP directory
142: * @param oJdbc JDBC Connection
143: * @param sAddrId GUID of address to be deleted
144: * @throws LDAPException
145: * @throws SQLException If sAddrId is not found at v_ldap_contacts SQL view
146: * @throws IllegalStateException If not connected to LDAP
147: */
148:
149: public abstract void deleteAddress(Connection oJdbc, String sAddrId)
150: throws LDAPException, SQLException;
151:
152: /**
153: * <p>Add a User from v_ldap_users view to an LDAP directory</p>
154: * 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
155: * @param oJdbc JDBC Connection
156: * @param sUserId GUID of user to be added
157: * @throws LDAPException
158: * @throws SQLException If sUserId is not found at v_ldap_users SQL view
159: * @throws IllegalStateException If not connected to LDAP
160: */
161:
162: /**
163: * <p>Add a User from v_ldap_users view to an LDAP directory</p>
164: * 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
165: * @param oJdbc JDBC Connection
166: * @param sUserId GUID of user to be added
167: * @throws LDAPException
168: * @throws SQLException If sUserId is not found at v_ldap_users SQL view
169: * @throws IllegalStateException If not connected to LDAP
170: */
171:
172: public abstract void addUser(Connection oJdbc, String sUserId)
173: throws LDAPException, SQLException;
174:
175: /**
176: * Add or replace a User from v_ldap_users SQL view to the LDAP directory
177: * @param oJdbc JDBC database connection
178: * @param sUserId GUID of user to be added or replaced
179: * @throws com.knowgate.ldap.LDAPException
180: * @throws java.sql.SQLException
181: */
182:
183: public abstract void addOrReplaceUser(Connection oJdbc,
184: String sUserId) throws LDAPException, SQLException;
185:
186: /**
187: * Delete a User from LDAP directory
188: * @param oJdbc JDBC Connection
189: * @param sUserId GUID of user to be added
190: * @throws LDAPException
191: * @throws SQLException If sUserId is not found at v_ldap_users SQL view
192: */
193:
194: public abstract void deleteUser(Connection oJdbc, String sUserId)
195: throws LDAPException, SQLException;
196:
197: /**
198: * <P>Load all users and contact address from a Domain into an LDAP directory</P>
199: * @param oJdbc JDBC Connection
200: * @param iDomainId Numeric Identifier for Domain
201: * @throws LDAPException
202: * @throws SQLException
203: */
204:
205: public abstract void loadDomain(Connection oJdbc, int iDomainId)
206: throws LDAPException, SQLException;
207:
208: /**
209: * <P>Load all users and contact address from a WorkArea into an LDAP directory</P>
210: * @param oJdbc JDBC Connection
211: * @param sDomainNm Name for Domain containing the WorkArea
212: * @param sWorkAreaNm WorkArea Name
213: * @throws LDAPException
214: * @throws SQLException
215: */
216:
217: public abstract void loadWorkArea(Connection oJdbc,
218: String sDomainNm, String sWorkAreaNm) throws LDAPException,
219: SQLException;
220:
221: /**
222: * <p>Delete a WorkArea from the LDAP directory</p>
223: * All entries under dc=<i>sDomainNm</i>,dc=hipergate,dc=org that match dc=<i>sWorkAreaNm</i> are deleted
224: * @param sDomainNm Domain Name
225: * @param sWorkAreaNm WorkArea Name
226: * @throws LDAPException
227: * @throws IllegalStateException If not connected to LDAP
228: */
229:
230: public abstract void deleteWorkArea(String sDomainNm,
231: String sWorkAreaNm) throws LDAPException,
232: IllegalStateException;
233:
234: // ---------------------------------------------------------------------------
235:
236: public static final int PWD_CLEAR_TEXT = 0;
237: public static final int PWD_DTIP_RC4 = 1;
238:
239: public static final short USER_NOT_FOUND = -1;
240: public static final short INVALID_PASSWORD = -2;
241: public static final short ACCOUNT_DEACTIVATED = -3;
242: public static final short SESSION_EXPIRED = -4;
243: public static final short DOMAIN_NOT_FOUND = -5;
244: public static final short WORKAREA_NOT_FOUND = -6;
245: public static final short WORKAREA_NOT_SET = -7;
246: public static final short ACCOUNT_CANCELLED = -8;
247: public static final short PASSWORD_EXPIRED = -9;
248: public static final short INTERNAL_ERROR = -255;
249: }
|