edu.columbia.coms6901.pingtel.pingim
Class LDAPHandler

java.lang.Object
  |
  +--edu.columbia.coms6901.pingtel.pingim.HelperClass
        |
        +--edu.columbia.coms6901.pingtel.pingim.LDAPHandler

public class LDAPHandler
extends HelperClass

Handles LDAP connections, disconnections, searching, adding, deleting, and all that fun LDAP stuff.

Version:
1.0
Author:
Micah Sherr

Field Summary
private static java.lang.String bindDN
          distinguished name used to bind to LDAP server
private static java.lang.String bindPWD
          the distinguished name's password (used for binding)
private static boolean connected
          connection status.
private static javax.naming.directory.DirContext ldapContext
          the directory context
private static java.lang.String LDAPServer
          IP or hostname of LDAP server
private static int port
          port of LDAP server to bind to
private static java.lang.String searchBase
          the search base for the LDAP directory
private static java.lang.String sSearchPhrase
          the search string used to find buddies in LDAP
 
Fields inherited from class edu.columbia.coms6901.pingtel.pingim.HelperClass
application
 
Constructor Summary
(package private) LDAPHandler(PingIM app)
          Initializes class
 
Method Summary
 boolean addBuddy(Buddy buddy)
          Adds a buddy to the LDAP directory
static void connect()
          Connects to LDAP directory
 void deleteBuddy(Buddy buddy)
          Removes a buddy from the LDAP directory
static void disconnect()
          Disconnects from LDAP server, if connected.
 BuddyList findBuddies()
          Reads LDAP directory and looks for buddies.
static java.util.Date getBuddyExpirationTime(Buddy buddy)
          Gets a buddy's expiration time
protected static java.lang.String getSearchBase()
          Returns the search base (DN) of the current connection to the LDAP Directory
static boolean setBuddyExpirationTime(Buddy buddy, java.util.Date dtExpires)
          Sets a buddy's expiration time
static void setHostname(java.lang.String sHostName)
          Sets hostname of LDAP server
static void setLDAPRoot(java.lang.String sRoot)
          Sets searchroot or base for LDAP directory
static void setLDAPUser(java.lang.String sDN)
          Sets DN to bind to LDAP server
static void setLDAPUserPassword(java.lang.String sPassword)
          Sets password to be used to bind to LDAP server
static void setPort(int iPort)
          Sets port for LDAP server
 
Methods inherited from class edu.columbia.coms6901.pingtel.pingim.HelperClass
setApplication
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

LDAPServer

private static java.lang.String LDAPServer
IP or hostname of LDAP server

port

private static int port
port of LDAP server to bind to

bindDN

private static java.lang.String bindDN
distinguished name used to bind to LDAP server

bindPWD

private static java.lang.String bindPWD
the distinguished name's password (used for binding)

searchBase

private static java.lang.String searchBase
the search base for the LDAP directory

connected

private static boolean connected
connection status. true == connected

ldapContext

private static javax.naming.directory.DirContext ldapContext
the directory context

sSearchPhrase

private static java.lang.String sSearchPhrase
the search string used to find buddies in LDAP
Constructor Detail

LDAPHandler

LDAPHandler(PingIM app)
Initializes class
Parameters:
app - the current PingIM application
Method Detail

setHostname

public static void setHostname(java.lang.String sHostName)
Sets hostname of LDAP server
Parameters:
sHostName - Hostname of LDAP server

setPort

public static void setPort(int iPort)
Sets port for LDAP server
Parameters:
iPort - Port of LDAP server (normally 389)

setLDAPUser

public static void setLDAPUser(java.lang.String sDN)
Sets DN to bind to LDAP server
Parameters:
sDN - DN to bind to LDAP server

setLDAPUserPassword

public static void setLDAPUserPassword(java.lang.String sPassword)
Sets password to be used to bind to LDAP server
Parameters:
sPassword - Password of user specified in setLDAPUser

setLDAPRoot

public static void setLDAPRoot(java.lang.String sRoot)
Sets searchroot or base for LDAP directory
Parameters:
sRoot - Root of LDAP directory

connect

public static void connect()
                    throws javax.naming.NamingException
Connects to LDAP directory
Throws:
javax.naming.NamingException - thrown when connection fails

disconnect

public static void disconnect()
                       throws javax.naming.NamingException
Disconnects from LDAP server, if connected.
Throws:
javax.naming.NamingException - thrown when disconnection fails

findBuddies

public BuddyList findBuddies()
Reads LDAP directory and looks for buddies.
Returns:
list of buddies as a BuddyList

addBuddy

public boolean addBuddy(Buddy buddy)
Adds a buddy to the LDAP directory
Parameters:
buddy - Buddy object that will be added to LDAP directory
Returns:
true on success, false on error

deleteBuddy

public void deleteBuddy(Buddy buddy)
                 throws IMException,
                        javax.naming.NamingException
Removes a buddy from the LDAP directory
Parameters:
buddy - Buddy that will be removed from the LDAP directory
Throws:
IMException - thrown if removal fails or for invalid buddy
javax.naming.NamingException - thrown if an LDAP failure occurs

getSearchBase

protected static java.lang.String getSearchBase()
Returns the search base (DN) of the current connection to the LDAP Directory
Returns:
the current searchbase of the LDAP directory

getBuddyExpirationTime

public static java.util.Date getBuddyExpirationTime(Buddy buddy)
Gets a buddy's expiration time
Parameters:
buddy - Buddy whose expiration time we are retrieving
Returns:
Expiration date

setBuddyExpirationTime

public static boolean setBuddyExpirationTime(Buddy buddy,
                                             java.util.Date dtExpires)
Sets a buddy's expiration time
Parameters:
buddy - Buddy whose expiration time we are about to change
dtExpires - The new expiration time
Returns:
true on success, false on error