BEA Systems, Inc.

com.beasys.commerce.bridge.ldap
Class LdapHelper

java.lang.Object
  |
  +--com.beasys.commerce.bridge.ldap.LdapHelper

public class LdapHelper
extends java.lang.Object
implements LDAPBridgeConstants

Helper class for accessing LDAP data. This class is responsible for making calls to an LDAP directory server for user/group information, authentication, and profile data. It is used by the LDAPEntityPropertyManager, LDAPConfiguration, and RealmConfiguration beans.


Field Summary
protected static java.lang.String CONTEXT_FACTORY
           
protected static int GROUP
           
protected static int USER
           
 
Fields inherited from interface com.beasys.commerce.bridge.ldap.LDAPBridgeConstants
LDAP_CONFIG, LDAP_ENABLED_ATTRIBUTE, LDAP_GROUP_ATTRIBUTE, LDAP_USER_ATTRIBUTE
 
Constructor Summary
LdapHelper()
           
 
Method Summary
 boolean authenticate(java.lang.String username, java.lang.String password)
          Authenticates a username and password against an LDAP directory.
protected  void configureForSSL(java.util.Map env)
          Sets up the JNDI environment variables necessary for SSL communication to an LDAP server.
 java.util.Iterator findUsernamesThatStartWith(java.lang.String start)
          Returns an iterator containing the names of all the users that start with a certain set of characters.
 java.lang.String formatDN(java.lang.String dnInfo)
          Given whatever is in the WebLogic LDAP Realm's properties file, formats a value correctly for use as a DN by reversing the order.
 java.util.Iterator getAllGroupNames()
          Returns all of the groups that this configuration is set up to use.
 java.util.ArrayList getAllGroupNamesAsArrayList()
          Returns all of the groups that this configuration is set up to use.
protected  LDAPConfiguration getConfiguration()
          Convenience method for retrieving the LDAPConfiguration.
protected  javax.naming.directory.DirContext getDirContext()
          Uses environment values from LDAPConfiguration to create a JNDI directory context that points to an LDAP server.
 java.lang.String getGroupDN(java.lang.String groupName)
          Given a unique group name returns the group's DN (distinguished name).
 java.util.Iterator getGroupNamesForUser(java.lang.String username)
          Returns the names of the groups of which a user is a member.
 java.util.Map getGroupProperties(java.lang.String groupName)
          Returns properties for a group from LDAP.
protected  java.lang.String getObjectDN(java.lang.String name, int type)
          Forms a DN for a user or a group.
protected  java.util.Map getObjectProperties(java.lang.String name, int type)
          Returns the properties for either a user or a group.
 java.lang.Object getService(java.lang.String aLookupName)
           
 java.lang.String getUserDN(java.lang.String username)
          Given a unique username returns the user's DN (distinguished name).
 java.util.Iterator getUsernames(java.lang.String searchExpression, int limit)
          Returns the usernames in LDAP that match the search expression.
 java.util.Iterator getUsernamesForGroup(java.lang.String groupName)
          Returns the usernames for the users in a group.
 java.util.Iterator getUsernamesForGroup(java.lang.String groupName, java.lang.String searchExpression, int limit)
          Returns a group's list of members in the form of users' names
 java.util.Map getUserProperties(java.lang.String username)
          Returns properties for a user from LDAP.
 boolean groupExists(java.lang.String groupName)
          Returns true if a group by this name exists.
protected  boolean isSSL()
          Checks the LDAP realm configuration to see if we should be communicating over SSL to the LDAP server.
 java.util.Iterator realGetUsernamesForGroup(java.lang.String groupName, java.lang.String searchExpression, int limit)
           
 boolean userExists(java.lang.String username)
          Determines if a user exists in an LDAP directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GROUP

protected static final int GROUP

USER

protected static final int USER

CONTEXT_FACTORY

protected static final java.lang.String CONTEXT_FACTORY
Constructor Detail

LdapHelper

public LdapHelper()
Method Detail

userExists

public boolean userExists(java.lang.String username)
                   throws java.lang.Exception
Determines if a user exists in an LDAP directory.
Parameters:
username - the unique username of a person in the directory
Returns:
true if the user exists in the LDAP directory
Throws:
java.lang.Exception - if a system error occurs

authenticate

public boolean authenticate(java.lang.String username,
                            java.lang.String password)
                     throws java.lang.Exception
Authenticates a username and password against an LDAP directory.
Parameters:
username - the username of the user
password - the user's password
Returns:
true if the authentication was successful, otherwise false
Throws:
java.lang.Exception - if a system error occurs

getUserProperties

public java.util.Map getUserProperties(java.lang.String username)
                                throws java.lang.Exception
Returns properties for a user from LDAP.
Parameters:
username - the user's username
Returns:
properties for a user from LDAP
Throws:
java.lang.Exception - if a system error occurs

getGroupProperties

public java.util.Map getGroupProperties(java.lang.String groupName)
                                 throws java.lang.Exception
Returns properties for a group from LDAP.
Parameters:
groupName - the group's unique display name
Returns:
properties for a group from LDAP
Throws:
java.lang.Exception - if a system error occurs

getObjectProperties

protected java.util.Map getObjectProperties(java.lang.String name,
                                            int type)
                                     throws java.lang.Exception
Returns the properties for either a user or a group.
Parameters:
name - the unique name of the object (user or group)
type - the type of object (user or group)
Returns:
the properties for either a user or a group
Throws:
java.lang.Exception - if a system error occurs

getDirContext

protected javax.naming.directory.DirContext getDirContext()
                                                   throws java.lang.Exception
Uses environment values from LDAPConfiguration to create a JNDI directory context that points to an LDAP server.
Returns:
the directory context
Throws:
java.lang.Exception - if a system error occurs

getAllGroupNames

public java.util.Iterator getAllGroupNames()
                                    throws java.lang.Exception
Returns all of the groups that this configuration is set up to use.
Returns:
all of the groups that this configuration is set up to use
Throws:
java.lang.Exception - if a system error occurs

getAllGroupNamesAsArrayList

public java.util.ArrayList getAllGroupNamesAsArrayList()
                                                throws java.lang.Exception
Returns all of the groups that this configuration is set up to use.
Returns:
all of the groups that this configuration is set up to use
Throws:
java.lang.Exception - if a system error occurs

groupExists

public boolean groupExists(java.lang.String groupName)
                    throws java.lang.Exception
Returns true if a group by this name exists.
Parameters:
groupName - the name of the group
Returns:
true if a group by this name exists
Throws:
java.lang.Exception - if a system error occurs

getUserDN

public java.lang.String getUserDN(java.lang.String username)
                           throws java.lang.Exception
Given a unique username returns the user's DN (distinguished name). Does not validate that the user exists.
Parameters:
username - the user's unique username
Returns:
the user's DN
Throws:
java.lang.Exception - if a system error occurs

getGroupDN

public java.lang.String getGroupDN(java.lang.String groupName)
                            throws java.lang.Exception
Given a unique group name returns the group's DN (distinguished name). Does not validate that the group exists.
Parameters:
groupName - the group's unique group name
Returns:
the group's DN
Throws:
java.lang.Exception - if a system error occurs

getObjectDN

protected java.lang.String getObjectDN(java.lang.String name,
                                       int type)
                                throws java.lang.Exception
Forms a DN for a user or a group.
Parameters:
name - the name of the user or group
type - the type of the object - user or group
Throws:
java.lang.Exception - if a system error occurs

getUsernamesForGroup

public java.util.Iterator getUsernamesForGroup(java.lang.String groupName)
                                        throws java.lang.Exception
Returns the usernames for the users in a group.
Parameters:
groupName - the name of the group
Returns:
the usernames for the users in a group
Throws:
java.lang.Exception - if a system error occurs

getUsernames

public java.util.Iterator getUsernames(java.lang.String searchExpression,
                                       int limit)
                                throws java.lang.Exception
Returns the usernames in LDAP that match the search expression. The only special character supported is the wildcard character ("*").
Parameters:
searchExpression - a search expression such as "J* Smith" where wildcards ("*") are the only supported special character
limit - a limit of results to return (0 returns the maximum)
Returns:
the usernames for the users in a group
Throws:
java.lang.Exception - if a system error occurs

getUsernamesForGroup

public java.util.Iterator getUsernamesForGroup(java.lang.String groupName,
                                               java.lang.String searchExpression,
                                               int limit)
                                        throws java.lang.Exception
Returns a group's list of members in the form of users' names
Parameters:
groupName - the name of the group
searchExpression - a search expression such as "J* Smith" where wildcards ("*") are the only supported special character
limit - a limit of results to return (0 returns the maximum)
Throws:
java.lang.Exception - if a system error occurs

realGetUsernamesForGroup

public java.util.Iterator realGetUsernamesForGroup(java.lang.String groupName,
                                                   java.lang.String searchExpression,
                                                   int limit)
                                            throws java.lang.Exception

getGroupNamesForUser

public java.util.Iterator getGroupNamesForUser(java.lang.String username)
                                        throws java.lang.Exception
Returns the names of the groups of which a user is a member.
Parameters:
username - the name of the user
Returns:
the names of the groups of which a user is a member
Throws:
java.lang.Exception - if a system error occurs

findUsernamesThatStartWith

public java.util.Iterator findUsernamesThatStartWith(java.lang.String start)
                                              throws java.lang.Exception
Returns an iterator containing the names of all the users that start with a certain set of characters.

getConfiguration

protected LDAPConfiguration getConfiguration()
                                      throws java.lang.Exception
Convenience method for retrieving the LDAPConfiguration.
Returns:
the LDAPConfiguration
Throws:
java.lang.Exception - if a system error occurs

configureForSSL

protected void configureForSSL(java.util.Map env)
                        throws java.lang.Exception
Sets up the JNDI environment variables necessary for SSL communication to an LDAP server.
Parameters:
env - the map of environment variables needed for creating a JNDI context.

isSSL

protected boolean isSSL()
                 throws java.lang.Exception
Checks the LDAP realm configuration to see if we should be communicating over SSL to the LDAP server.
Returns:
true if we should be communicating over SSL to the LDAP server

formatDN

public java.lang.String formatDN(java.lang.String dnInfo)
                          throws java.lang.Exception
Given whatever is in the WebLogic LDAP Realm's properties file, formats a value correctly for use as a DN by reversing the order. For example, if a DN in the WebLogic ldaprealm.properties is

o=Acme,ou=North America,ou=People

Then this method would format the DN to be

ou=People,ou=North America,o=Acme

This formatted DN is in the order in which LDAP servers want to see it. Note: you do not need to format a DN that is already in the correct order, if you do it's order will be reversed and it will no longer work.

Parameters:
dnInfo - an LDAP DN in reverse order (as it would be in ldaprealm.properties)
Returns:
the DN in reverse order - correct for LDAP queries

getService

public java.lang.Object getService(java.lang.String aLookupName)

BEA Systems, Inc.

Copyright © 2000 BEA Systems, Inc. All Rights Reserved