com.wewebu.ow.server.util.ldap
Class OwLdapConnector

java.lang.Object
  extended by com.wewebu.ow.server.util.ldap.OwLdapConnector

public class OwLdapConnector
extends Object

Utility class for connecting to an LDAP Server.

Alfresco Workdesk
Copyright (c) Alfresco Software, Inc.
All rights reserved.

For licensing information read the license.txt file or
go to: http://wiki.alfresco.com


Field Summary
static String ELEMENT_SCHEMA_INTERPRETER
          name of the configuration element changing the LDAP attribute storing the schema interpreter class name.
static String USER_DN_PROPERTY
          Distinguished name property name
static String USERS_DIRECTORY_PROPERTY
           
 
Constructor Summary
OwLdapConnector(Node configNode_p)
          Construct LDAP connector from the XML config node of bootstrap.xml
OwLdapConnector(Properties props_p, int recursionLevel_p)
          Construct the LDAP Connector with given properties
 
Method Summary
 void authenticate(String userName_p, String password_p)
          Authenticates a user using LDAP.
The user name and password are stored for further operations.
 OwLdapConnection createConnection(boolean adminConnection_p)
          Create a Connection with properties depending on the given parameter.
 String findDistinguishedNameAnonymously(String user_p)
          Returns the full distinguished name for the login user to use for authentication later.
 OwObjectCollection findGroupsMatching(String namePattern)
          Find groups that match a given pattern.
 OwUserInfo findUserByDNAnonymously(String strID_p)
          Finds a user by its Distinguished Name.
 OwUserInfo findUserByIdAnonymously(String strID_p)
          Finds a user by its id.
 OwUserInfo findUserByLoginAnonymously(String strID_p)
           
 OwObjectCollection findUserDNsMatching(String pattern)
           
 Collection getAllShortGroupNames()
          Reads all groups from the LDAP (e.g.
 Collection getAllShortGroupNames(boolean useAdminAccount_p)
          Reads all groups from the LDAP (e.g.
 Properties getProperties()
          Returns the properties used to build up the LDAP context of the logged in user
protected  Properties getProperties(boolean admin_p)
          Get specific properties configuration of user or admin.
 String getRecordId(String dname)
          Retrieves the value of the attribute that should be used as OWD ID.
 int getRecursionLevel()
          Get the defined level of recursion.
 Collection getShortGroupNames()
          Returns the group names of the user.
 Collection getShortGroupNames(boolean useAdminAccount_p)
          Returns the group names of the user.
 String getUserDisplayName()
          Get the user display name, or a null value.
 String getUserDisplayName(String dname)
          Get the display name for the user with the given DN.
 String getUserId()
          Returns a unique ID of the user
 String getUserLongName()
          Gets the user's long name
 String getUserShortName()
          Get the user short name, or a null value.
protected  void prepareForAuthentication(String userName_p, String password_p)
          Called before authentication method to prepare configuration for
 String toString()
          toString method: creates a String representation of the object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

USERS_DIRECTORY_PROPERTY

public static final String USERS_DIRECTORY_PROPERTY
See Also:
Constant Field Values

ELEMENT_SCHEMA_INTERPRETER

public static final String ELEMENT_SCHEMA_INTERPRETER
name of the configuration element changing the LDAP attribute storing the schema interpreter class name.

Since:
3.1.0.0
See Also:
Constant Field Values

USER_DN_PROPERTY

public static final String USER_DN_PROPERTY
Distinguished name property name

Since:
3.1.0.0
See Also:
Constant Field Values
Constructor Detail

OwLdapConnector

public OwLdapConnector(Properties props_p,
                       int recursionLevel_p)
Construct the LDAP Connector with given properties

Parameters:
props_p - properties used to build up the LDAP context
recursionLevel_p - Recursion level for getting the groups of a given user

OwLdapConnector

public OwLdapConnector(Node configNode_p)
Construct LDAP connector from the XML config node of bootstrap.xml

Parameters:
configNode_p - XML node of bootstrap.xml
Method Detail

createConnection

public OwLdapConnection createConnection(boolean adminConnection_p)
Create a Connection with properties depending on the given parameter.

Parameters:
adminConnection_p - boolean flag to initialize with specific properties
Returns:
a new OwLdapConnection based on the administrator properties if adminConnection_p is true or the users properties if adminConnection_p is false
Since:
3.1.0.0

getProperties

public Properties getProperties()
Returns the properties used to build up the LDAP context of the logged in user

Returns:
Properties

getProperties

protected Properties getProperties(boolean admin_p)
Get specific properties configuration of user or admin.

Parameters:
admin_p - boolean
Returns:
Properties
Since:
3.2.0.2

authenticate

public void authenticate(String userName_p,
                         String password_p)
                  throws OwAuthenticationException,
                         OwConfigurationException
Authenticates a user using LDAP.
The user name and password are stored for further operations.

Parameters:
userName_p - (the samAccount)
password_p -
Throws:
OwAuthenticationException - LDAP authorization Exception
OwConfigurationException - possible cause: the LDAP connector is not set up correctly in the bootstrap.xml (Authentication node)

prepareForAuthentication

protected void prepareForAuthentication(String userName_p,
                                        String password_p)
                                 throws OwAuthenticationException,
                                        OwConfigurationException
Called before authentication method to prepare configuration for

Parameters:
userName_p -
password_p -
Throws:
OwAuthenticationException
OwConfigurationException
Since:
3.2.0.2

getShortGroupNames

public Collection getShortGroupNames()
                              throws OwAuthenticationException,
                                     OwInvalidOperationException
Returns the group names of the user.

Returns:
List of the group names
Throws:
OwAuthenticationException - LDAP authorization Exception
OwInvalidOperationException - invalid LDAP operation

getShortGroupNames

public Collection getShortGroupNames(boolean useAdminAccount_p)
                              throws OwAuthenticationException,
                                     OwInvalidOperationException
Returns the group names of the user.

Parameters:
useAdminAccount_p - if true the LDAP Connector uses the administrator account set in the bootstrap.xml to retrieve the user group names of the logged in user, if false use the user logged in user account to retrieve this informations.
Returns:
List of the group names
Throws:
OwAuthenticationException - LDAP authorization Exception
OwInvalidOperationException - invalid LDAP operation

getAllShortGroupNames

public Collection getAllShortGroupNames()
                                 throws OwAuthenticationException,
                                        OwInvalidOperationException
Reads all groups from the LDAP (e.g. CN=Builtin)

Returns:
Collection
Throws:
OwAuthenticationException - LDAP authorization Exception
OwInvalidOperationException - invalid LDAP operation

getAllShortGroupNames

public Collection getAllShortGroupNames(boolean useAdminAccount_p)
                                 throws OwAuthenticationException,
                                        OwInvalidOperationException
Reads all groups from the LDAP (e.g. CN=Builtin)

Parameters:
useAdminAccount_p - if true the LDAP Connector uses the administrator account set in the bootstrap.xml to retrieve the user group names of the logged in user, if false use the user logged in user account to retrieve this informations.
Returns:
List of the group names
Throws:
OwAuthenticationException - LDAP authorization Exception
OwInvalidOperationException - invalid LDAP operation

getUserLongName

public String getUserLongName()
                       throws OwAuthenticationException,
                              OwInvalidOperationException
Gets the user's long name

Returns:
a String
Throws:
OwAuthenticationException - LDAP authorization Exception
OwInvalidOperationException - invalid LDAP operation

getUserId

public String getUserId()
                 throws OwAuthenticationException,
                        OwInvalidOperationException
Returns a unique ID of the user

Returns:
a String
Throws:
OwAuthenticationException - LDAP authorization Exception
OwInvalidOperationException - invalid LDAP operation

findDistinguishedNameAnonymously

public String findDistinguishedNameAnonymously(String user_p)
                                        throws OwAuthenticationException,
                                               OwConfigurationException
Returns the full distinguished name for the login user to use for authentication later. The distinguished name is nice since it contains organizational unit and container information. This method searches anonymously if allowed otherwise takes the principle given by the properties, to perform an anonymous search, the Active Directory Server admin must set up the Active Directory Server to allow anonymous searches.

Parameters:
user_p - representing the login name for the user being searched
Returns:
String representing the full distinguished name for the login passed to the method
Throws:
OwAuthenticationException - the user that wants to login is not available in the LDAP
OwConfigurationException - possible cause: the LDAP connector is not set up correctly in the bootstrap.xml (Authentication node)

findUserDNsMatching

public OwObjectCollection findUserDNsMatching(String pattern)
                                       throws OwException
Throws:
OwException

getUserShortName

public String getUserShortName()
                        throws OwAuthenticationException,
                               OwInvalidOperationException
Get the user short name, or a null value.

Returns:
the user short name, or a null value.
Throws:
OwAuthenticationException - thrown when the user is not authenticated.
OwInvalidOperationException - thrown when the "name" attribute cannot be resolved.
Since:
2.5.3.0

getUserDisplayName

public String getUserDisplayName()
                          throws OwAuthenticationException,
                                 OwInvalidOperationException
Get the user display name, or a null value.

Returns:
the user short name, or a null value.
Throws:
OwAuthenticationException - thrown when the user is not authenticated.
OwInvalidOperationException - thrown when the "displayName" attribute cannot be resolved.
Since:
2.5.3.0

toString

public String toString()
toString method: creates a String representation of the object

Overrides:
toString in class Object
Returns:
a String - the String representation

findUserByDNAnonymously

public OwUserInfo findUserByDNAnonymously(String strID_p)
                                   throws OwException
Finds a user by its Distinguished Name.

Parameters:
strID_p -
Returns:
user with the given DN.
Throws:
OwException - Throws OwObjectNotFoundException if no user was found.

findUserByIdAnonymously

public OwUserInfo findUserByIdAnonymously(String strID_p)
                                   throws OwException
Finds a user by its id.

Parameters:
strID_p -
Returns:
user with the given DN.
Throws:
OwException - Throws OwObjectNotFoundException if no user was found.

getUserDisplayName

public String getUserDisplayName(String dname)
                          throws OwException
Get the display name for the user with the given DN. The Display Name will be used in OWD.

Parameters:
dname - The DN of the user.
Returns:
The display name.
Throws:
OwException

getRecordId

public String getRecordId(String dname)
                   throws OwException
Retrieves the value of the attribute that should be used as OWD ID.

Parameters:
dname - The LDAP DN of the record (group, user)
Returns:
The ID to be used inside OWD for this record.
Throws:
OwException

getRecursionLevel

public int getRecursionLevel()
Get the defined level of recursion.

Returns:
int
Since:
3.2.0.2

findUserByLoginAnonymously

public OwUserInfo findUserByLoginAnonymously(String strID_p)
                                      throws OwException
Parameters:
strID_p -
Returns:
user with the given login name or null
Throws:
OwException

findGroupsMatching

public OwObjectCollection findGroupsMatching(String namePattern)
                                      throws OwException
Find groups that match a given pattern.

Parameters:
namePattern - pattern for the group name to search by.
Returns:
a collection of OwUserInfo representing groups that match the pattern.
Throws:
OwException
Since:
4.1.1.0


Copyright © 2013 Alfresco Business Solutions. All Rights Reserved.