pt.digitalis.utils.ldap.impl
Class AbstractLDAPUtils

java.lang.Object
  extended by pt.digitalis.utils.ldap.impl.AbstractLDAPUtils
All Implemented Interfaces:
ILDAPUtils
Direct Known Subclasses:
LDAPUtilsActiveDirectoryImpl, LDAPUtilsOpenLDAPImpl

public abstract class AbstractLDAPUtils
extends Object
implements ILDAPUtils

Defines a set operations common to all LDAP implementations.

Author:
Rodrigo Gon�alves rgoncalves@digitalis.pt
, Luis Pinto lpinto@digitalis.pt
, F�bio Souto fsouto@digitalis.pt

Field Summary
protected static String CN_TAG
          The "CN=" constant string.
protected  LDAPConfigurations ldapConfigurations
          The LDAP configurations.
protected static String NON_AVAILABLE
          The 'N/A' constant string.
 
Constructor Summary
AbstractLDAPUtils()
           
 
Method Summary
 void addGroup(LDAPGroup newGroup)
          Adds a new group to the LDAP tree.
 void addGroupAttribute(String commonName, String attributeName, Object value)
          Adds an attribute to a given group.
 void addUser(LDAPUser newUser)
          Adds a new user to the LDAP tree.
 void addUserAttribute(String loginName, String attributeName, Object value)
          Adds an attribute to a given user.
 void addUserToGroup(String groupCN, String userLogin)
          Adds a user from a given group.
protected abstract  String calculateDistinguishedName(String commonName, String mainGroupCommonName)
          Calculates an entity's distinguished name.
abstract  void changePassword(String loginName, String newPassword)
          Changes the password for a given user.
protected  LDAPGroup convertFromAttributesToLDAPGroup(Attributes attributes, String distinguishedName)
          Converts an Attributes object into an LDAPGroup.
protected  LDAPUser convertFromAttributesToLDAPUser(Attributes attributes, String distinguishedName)
          Converts an Attributes object into an LDAPUser.
protected  LDAPUser convertFromAttributesToLDAPUser(Attributes attributes, String distinguishedName, boolean convertAttributes)
          Converts an Attributes object into an LDAPUser.
protected  LDAPGroup convertFromSearchResultToLDAPGroup(SearchResult searchResult)
          Converts a SearchResult object into an LDAPGroup.
protected  LDAPUser convertFromSearchResultToLDAPUser(SearchResult searchResult)
          Converts a SearchResult object into an LDAPUser.
protected  LDAPUser convertFromSearchResultToLDAPUser(SearchResult searchResult, boolean convertAttributes)
          Converts a SearchResult object into an LDAPUser.
protected  Map<String,Object> convertFromSearchResultToMap(SearchResult searchResult)
          Converts a search result into a map.
 int countAllfUsers(String groupId)
          Count allf users.
 int countAllGroups()
          Counts all groups in the LDAP directory
 int countAllGroupsOfUser(String loginName)
          Counts all groups of a user
 int countAllUsers()
          Counts all users in the LDAP directory
 int countUsers(Map<String,String> attributes)
          Count users in the LDAP directory which match the provided attributes
 List<SearchResult> doLDAPCount(LdapContext context, String baseNode, String searchCriteria)
          Performs a lightweight search on LDAP, for counting purposes.
 List<SearchResult> doLDAPSearchMultipleReturns(LdapContext context, String baseNode, String searchCriteria)
          Performs an LDAP tree search that can return multiple values.
 List<SearchResult> doLDAPSearchMultipleReturnsPaging(LdapContext context, String baseNode, String searchCriteria, int rowsPerPage, Integer pageToReturn)
          Performs an LDAP tree search that can return multiple values.
 Set<LDAPGroup> findAllGroups()
          Returns the list of all groups.
 Set<LDAPUser> findAllUsers()
          Returns the list of all users.
 LDAPGroup findGroupByCommonName(String cn)
          Returns the group with a given common name.
 LDAPGroup findGroupByDistinguishedName(String dn)
          Returns the group with a given distinguished name.
 Set<LDAPGroup> findGroups(int rowsPerPage, int pageToReturn)
          Finds a subset of all the groups, according to the parameters
 Set<LDAPGroup> findGroupsOfUser(String loginName)
          Returns the list of a given user's groups.
 Set<LDAPGroup> findGroupsOfUserPagination(String loginName, int rowsPerPage, int pageToReturn)
          Returns the list of a given user's groups, with pagination
 LDAPUser findUserByDistinguishedName(String dn)
          Returns the user with a given distinguished name.
 LDAPUser findUserByLogin(String loginName)
          Returns the user with a given login name.
 LDAPUser findUserByLogin(String loginName, boolean convertAttributes)
          Returns the user with a given login name.
 Set<LDAPUser> findUsers(int rowsPerPage, int pageToReturn)
          Finds a subset of all the users, according to the parameters
 Set<LDAPUser> findUsersByAttribute(String attribute, String value)
          Returns the list of users with a given attribute value.
 Set<LDAPUser> findUsersByAttributes(Map<String,String> attributes)
          Finds a set of LDAP users that match all of the specified criteria
 Set<LDAPUser> findUsersByAttributes(Map<String,String> attributes, int rowsPerPage, int pageToReturn)
          Finds a set of LDAP users that match all of the specified criteria
 Set<LDAPUser> findUsersByEmail(String value)
          Returns the list of users with a given email attribute value.
 Map<String,LDAPUser> findUsersInGroup(String groupCN)
          Checks if a given user belongs to a given group.
protected  Attributes getAttributesForGroupAddition(LDAPGroup newGroup)
          Prepares the LDAP attributes for group addition.
protected  Attributes getAttributesForUserAddition(LDAPUser newUser)
          Prepares the LDAP attributes for user addition.
protected  SearchResult getByDistinguishedName(String distinguishedName)
          Finds an entity by distinguished name.
protected  SearchResult getByLogin(String loginName)
          Finds an user by login name.
 Set<LDAPGroup> getChildGroupsByCN(String commonName)
          Returns the list of groups that belong to a parent group given its common name.
 Set<LDAPGroup> getChildGroupsByDN(String distinguishedName)
          Returns the list of groups that belong to a parent group given its distinguished name.
protected static String getCNFromDN(String distinguishedName)
          Extracts the common name from the distinguished name.
protected  String getCommonName()
          Returns the standard LDAP name for the 'cn' attribute.
 LDAPConfigurations getConfigurations()
          Inspector for the LDAP configurations object.
protected  String getDescriptionAttributeName()
          Returns the standard LDAP name for the 'description' attribute.
protected  String getDisplayNameAttributeName()
          Returns the standard LDAP name for the 'displayName' attribute.
protected  String getGivenNameAttributeName()
          Returns the standard LDAP name for the 'givenName' attribute.
 Object getGroupAttribute(String attributeName, String commonName)
          Returns a given attribute or null of it doesn't exists.
 String getGroupAttributeName()
          Gets the name attribute name
 Map<String,Object> getGroupAttributes(String commonName)
          Returns the attribute map.
protected  SearchResult getGroupByCommonName(String cn)
          Finds an entity by common name.
protected  LDAPGroup getGroupByDistinguishedName(String distinguishedName)
          Finds a group by distinguished name.
protected abstract  String getGroupClassName()
          Returns the standard LDAP name for the 'group' attribute.
protected  String getGroupIdentifierName()
          Returns the group identifier name.
abstract  String getGroupParentGroupAttributeName()
          Returns the implementation dependent name for the LDAP attribute that stores the group's parent group.
protected  LdapContext getLDAPContext()
          Returns the LDAP context to use for search and modification operations.
protected static pt.digitalis.log.ILogWrapper getLogger()
          Inspector for the 'logger' attribute.
 String getMailAttributeName()
          Returns the standard LDAP name for the 'e-mail' attribute.
 String getNameAttributeName()
          Returns the standard LDAP name for the 'name' attribute.
 String getNonAvailableValue()
          Get the Non Available Message.
protected  String getObjectClassName()
          Returns the 'objectClass' attribute name.
protected  String getPasswordAttributeName()
          Returns the standard LDAP name for the 'password' attribute.
protected  LdapContext getSecureLDAPContext()
          Returns the LDAP context to use for search and modification operations with a secure connection.
protected  String getSurnameAttributeName()
          Returns the standard LDAP name for the 'surname' attribute.
 Object getUserAttribute(String attributeName, String loginName)
          Returns a given attribute or null of it doesn't exists.
 Map<String,Object> getUserAttributes(String loginName)
          Returns the attribute map.
protected  LDAPUser getUserByDistinguishedName(String distinguishedName)
          Finds an user by distinguished name.
protected abstract  String getUserClassName()
          Returns the standard LDAP name for the 'user' attribute.
protected  String getUserIdentifierName()
          Returns the user identifier name.
protected  SearchResult getUserInGroup(String userLogin, String groupCN)
          Finds a user with a given login name on a given group.
 String getUserLoginAttributeName()
          Gets the user login attribute name
 String getUserParentGroupAttributeName()
          Returns the parent group attribute name.
 boolean groupContainsAttribute(String attributeName, String commonName)
          Group contains attribute.
 boolean groupExists(String groupCN)
          Checks if a given group exists on the LDAP tree.
 boolean isIdentityValid(String loginName, String suppliedPassword)
          Checks if the supplied password matches the one defined for a user with a given ID.
 boolean isReadOnly()
          Get the ldap readOnly configuration value.
 boolean isUserInGroup(String groupCN, String userLogin)
          Checks if a given user belongs to a given group.
protected  void modifyAttributes(String distinguishedName, ModificationItem[] mods, boolean secure)
          Modifies the passed attributes of an entity with the given DN.
static byte[] parseControls(Control[] controls)
          Parses the controls.
 void removeGroup(String groupCN)
          Removes an existing group from the LDAP tree.
 void removeGroupAttribute(String commonName, String attributeName)
          Removes an attribute from a given group.
 void removeUser(String loginName)
          Removes an existing user from the LDAP tree.
 void removeUserAttribute(String loginName, String attributeName)
          Removes an attribute from a given user.
 void removeUserFromGroup(String groupCN, String userLogin)
          Removes a user from a given group.
 void resetConfigurations()
          Resets the LDAP configurations.
 void setGroupAttribute(String commonName, String attributeName, Object value)
          Sets a given attribute value.
 void setLogger(pt.digitalis.log.ILogWrapper logger)
          Set the API logger
 void setUserAttribute(String loginName, String attributeName, Object value)
          Sets the a given attribute value.
 void updateGroup(LDAPGroup groupToUpdate, String groupCN)
          Updates an existing group on the LDAP tree.
 void updateUser(LDAPUser userToUpdate, String userLogin)
          Updates an existing user on the LDAP tree.
 boolean userContainsAttribute(String id, String loginName)
          Checks if a given attribute belongs to the entity.
 boolean userExists(String loginName)
          Checks if a user exists on the LDAP tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface pt.digitalis.utils.ldap.ILDAPUtils
getUnchangeableLDAPAttributes
 

Field Detail

CN_TAG

protected static final String CN_TAG
The "CN=" constant string.

See Also:
Constant Field Values

NON_AVAILABLE

protected static final String NON_AVAILABLE
The 'N/A' constant string.

See Also:
Constant Field Values

ldapConfigurations

protected LDAPConfigurations ldapConfigurations
The LDAP configurations.

Constructor Detail

AbstractLDAPUtils

public AbstractLDAPUtils()
Method Detail

getCNFromDN

protected static final String getCNFromDN(String distinguishedName)
Extracts the common name from the distinguished name.

Parameters:
distinguishedName - the distinguished name to process
Returns:
the common name extracted from the distinguished name

getLogger

protected static pt.digitalis.log.ILogWrapper getLogger()
Inspector for the 'logger' attribute.

Returns:
the logger value

parseControls

public static byte[] parseControls(Control[] controls)
                            throws NamingException
Parses the controls.

Parameters:
controls - the controls
Returns:
the byte[]
Throws:
NamingException - the naming exception

addGroup

public void addGroup(LDAPGroup newGroup)
              throws LDAPOperationException
Description copied from interface: ILDAPUtils
Adds a new group to the LDAP tree.

Specified by:
addGroup in interface ILDAPUtils
Parameters:
newGroup - the group to add
Throws:
LDAPOperationException - if the group can't be created
See Also:
ILDAPUtils.addGroup(pt.digitalis.utils.ldap.LDAPGroup)

addGroupAttribute

public void addGroupAttribute(String commonName,
                              String attributeName,
                              Object value)
                       throws LDAPOperationException
Description copied from interface: ILDAPUtils
Adds an attribute to a given group.

Specified by:
addGroupAttribute in interface ILDAPUtils
Parameters:
commonName - the group's common name
attributeName - the attribute name
value - the attribute value
Throws:
LDAPOperationException
See Also:
ILDAPUtils.addGroupAttribute(java.lang.String, java.lang.String, java.lang.Object)

addUser

public void addUser(LDAPUser newUser)
             throws LDAPOperationException
Description copied from interface: ILDAPUtils
Adds a new user to the LDAP tree.

Specified by:
addUser in interface ILDAPUtils
Parameters:
newUser - the new user to add to the LDAP server
Throws:
LDAPOperationException - if the user can't be created
See Also:
ILDAPUtils.addUser(pt.digitalis.utils.ldap.LDAPUser)

addUserAttribute

public void addUserAttribute(String loginName,
                             String attributeName,
                             Object value)
                      throws LDAPOperationException
Description copied from interface: ILDAPUtils
Adds an attribute to a given user.

Specified by:
addUserAttribute in interface ILDAPUtils
Parameters:
loginName - the user login name
attributeName - the attribute name
value - the attribute value
Throws:
LDAPOperationException - if the attribute can't be added
See Also:
ILDAPUtils.addUserAttribute(java.lang.String, java.lang.String, java.lang.Object)

addUserToGroup

public void addUserToGroup(String groupCN,
                           String userLogin)
                    throws LDAPOperationException
Description copied from interface: ILDAPUtils
Adds a user from a given group.

Specified by:
addUserToGroup in interface ILDAPUtils
Parameters:
groupCN - the CN of the group
userLogin - the login name of the user to add
Throws:
LDAPOperationException - if the user groups can't be added
See Also:
ILDAPUtils.addUserToGroup(java.lang.String, java.lang.String)

calculateDistinguishedName

protected abstract String calculateDistinguishedName(String commonName,
                                                     String mainGroupCommonName)
                                              throws LDAPOperationException
Calculates an entity's distinguished name.

To be implemented for each LDAP technology.

Parameters:
commonName - the entity's common name
mainGroupCommonName - the entity's main group name
Returns:
the entity's distinguished name
Throws:
LDAPOperationException - if the distinguished name can't be calculated

changePassword

public abstract void changePassword(String loginName,
                                    String newPassword)
                             throws LDAPOperationException
Description copied from interface: ILDAPUtils
Changes the password for a given user.

Specified by:
changePassword in interface ILDAPUtils
Parameters:
loginName - the login name of the user to change the password
newPassword - the new password to set
Throws:
LDAPOperationException - if the operation cannot be executed
See Also:
ILDAPUtils.changePassword(java.lang.String, java.lang.String)

convertFromAttributesToLDAPGroup

protected LDAPGroup convertFromAttributesToLDAPGroup(Attributes attributes,
                                                     String distinguishedName)
Converts an Attributes object into an LDAPGroup.

Parameters:
attributes - the object to convert
distinguishedName - the group DN
Returns:
the converted object

convertFromAttributesToLDAPUser

protected LDAPUser convertFromAttributesToLDAPUser(Attributes attributes,
                                                   String distinguishedName)
Converts an Attributes object into an LDAPUser.

Parameters:
attributes - the object to convert
distinguishedName - the user DN
Returns:
the converted object

convertFromAttributesToLDAPUser

protected LDAPUser convertFromAttributesToLDAPUser(Attributes attributes,
                                                   String distinguishedName,
                                                   boolean convertAttributes)
Converts an Attributes object into an LDAPUser.

Parameters:
attributes - the object to convert
distinguishedName - the user DN
convertAttributes - the convert attributes
Returns:
the converted object

convertFromSearchResultToLDAPGroup

protected LDAPGroup convertFromSearchResultToLDAPGroup(SearchResult searchResult)
Converts a SearchResult object into an LDAPGroup.

Parameters:
searchResult - the object to convert
Returns:
the converted object

convertFromSearchResultToLDAPUser

protected LDAPUser convertFromSearchResultToLDAPUser(SearchResult searchResult)
Converts a SearchResult object into an LDAPUser.

Parameters:
searchResult - the object to convert
Returns:
the converted object

convertFromSearchResultToLDAPUser

protected LDAPUser convertFromSearchResultToLDAPUser(SearchResult searchResult,
                                                     boolean convertAttributes)
Converts a SearchResult object into an LDAPUser.

Parameters:
searchResult - the object to convert
convertAttributes - the convert attributes
Returns:
the converted object

convertFromSearchResultToMap

protected final Map<String,Object> convertFromSearchResultToMap(SearchResult searchResult)
                                                         throws LDAPOperationException
Converts a search result into a map.

Parameters:
searchResult - the search result object
Returns:
the map with the converted values
Throws:
LDAPOperationException - if the conversion can't be performed

countAllfUsers

public int countAllfUsers(String groupId)
                   throws LDAPOperationException
Count allf users.

Specified by:
countAllfUsers in interface ILDAPUtils
Parameters:
groupId - the group id
Returns:
the int
Throws:
LDAPOperationException - the lDAP operation exception
See Also:
ILDAPUtils.countAllfUsers(java.lang.String)

countAllGroups

public int countAllGroups()
                   throws NamingException,
                          LDAPOperationException
Description copied from interface: ILDAPUtils
Counts all groups in the LDAP directory

Specified by:
countAllGroups in interface ILDAPUtils
Returns:
the number of groups in the LDAP directory
Throws:
NamingException
LDAPOperationException
See Also:
ILDAPUtils.countAllGroups()

countAllGroupsOfUser

public int countAllGroupsOfUser(String loginName)
                         throws NamingException,
                                LDAPOperationException
Description copied from interface: ILDAPUtils
Counts all groups of a user

Specified by:
countAllGroupsOfUser in interface ILDAPUtils
Parameters:
loginName - The user login name
Returns:
the number of users in the LDAP directory
Throws:
NamingException
LDAPOperationException
See Also:
ILDAPUtils.countAllGroupsOfUser(java.lang.String)

countAllUsers

public int countAllUsers()
                  throws NamingException,
                         LDAPOperationException
Description copied from interface: ILDAPUtils
Counts all users in the LDAP directory

Specified by:
countAllUsers in interface ILDAPUtils
Returns:
the number of users in the LDAP directory
Throws:
NamingException
LDAPOperationException
See Also:
ILDAPUtils.countAllUsers()

countUsers

public int countUsers(Map<String,String> attributes)
               throws LDAPOperationException
Description copied from interface: ILDAPUtils
Count users in the LDAP directory which match the provided attributes

Specified by:
countUsers in interface ILDAPUtils
Parameters:
attributes - The attributes to be considered in the search
Returns:
The number of users that match the provided attributes
Throws:
LDAPOperationException - if the operation can't be executed
See Also:
ILDAPUtils.countUsers(java.util.Map)

doLDAPCount

public List<SearchResult> doLDAPCount(LdapContext context,
                                      String baseNode,
                                      String searchCriteria)
                               throws NamingException,
                                      LDAPOperationException,
                                      IOException
Performs a lightweight search on LDAP, for counting purposes.

Parameters:
context - a valid Ldap context
baseNode - the base node to start the search
searchCriteria - the criteria to search
Returns:
an enumeration of SearchResults for the objects that satisfy the search criteria.
Throws:
NamingException - if the search cannot be executed
LDAPOperationException - if there is an error creating the LDAP context
IOException - Signals that an I/O exception has occurred.

doLDAPSearchMultipleReturns

public List<SearchResult> doLDAPSearchMultipleReturns(LdapContext context,
                                                      String baseNode,
                                                      String searchCriteria)
                                               throws NamingException,
                                                      LDAPOperationException,
                                                      IOException
Performs an LDAP tree search that can return multiple values.

Parameters:
context - a valid Ldap context
baseNode - the base node to start the search
searchCriteria - the criteria to search
Returns:
an enumeration of SearchResults for the objects that satisfy the search criteria.
Throws:
NamingException - if the search cannot be executed
LDAPOperationException - if there is an error creating the LDAP context
IOException - Signals that an I/O exception has occurred.

doLDAPSearchMultipleReturnsPaging

public List<SearchResult> doLDAPSearchMultipleReturnsPaging(LdapContext context,
                                                            String baseNode,
                                                            String searchCriteria,
                                                            int rowsPerPage,
                                                            Integer pageToReturn)
                                                     throws NamingException,
                                                            LDAPOperationException,
                                                            IOException
Performs an LDAP tree search that can return multiple values.

Parameters:
context - a valid Ldap context
baseNode - the base node to start the search
searchCriteria - the criteria to search
rowsPerPage - the request number of results limit
pageToReturn - the page to return, null if all pages must be returned
Returns:
an enumeration of SearchResults for the objects that satisfy the search criteria.
Throws:
NamingException - if the search cannot be executed
LDAPOperationException - if there is an error creating the LDAP context
IOException - Signals that an I/O exception has occurred.

findAllGroups

public Set<LDAPGroup> findAllGroups()
                             throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the list of all groups.

Specified by:
findAllGroups in interface ILDAPUtils
Returns:
the list of all the groups
Throws:
LDAPOperationException - if the operation can't be executed
See Also:
ILDAPUtils.findAllGroups()

findAllUsers

public Set<LDAPUser> findAllUsers()
                           throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the list of all users.

Specified by:
findAllUsers in interface ILDAPUtils
Returns:
the list of all the users
Throws:
LDAPOperationException - if the operation can't be executed
See Also:
ILDAPUtils.findAllUsers()

findGroupByCommonName

public LDAPGroup findGroupByCommonName(String cn)
                                throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the group with a given common name.

Specified by:
findGroupByCommonName in interface ILDAPUtils
Parameters:
cn - the group's common name
Returns:
the LDAPGroup with the given common name
Throws:
LDAPOperationException - if the operation cannot be executed
See Also:
ILDAPUtils.findGroupByCommonName(java.lang.String)

findGroupByDistinguishedName

public LDAPGroup findGroupByDistinguishedName(String dn)
                                       throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the group with a given distinguished name.

Specified by:
findGroupByDistinguishedName in interface ILDAPUtils
Parameters:
dn - the group's distinguished name
Returns:
the LDAPGroup with the given distinguished name
Throws:
LDAPOperationException - if the operation cannot be executed
See Also:
ILDAPUtils.findGroupByDistinguishedName(java.lang.String)

findGroups

public Set<LDAPGroup> findGroups(int rowsPerPage,
                                 int pageToReturn)
                          throws LDAPOperationException
Description copied from interface: ILDAPUtils
Finds a subset of all the groups, according to the parameters

Specified by:
findGroups in interface ILDAPUtils
Parameters:
rowsPerPage - The number of rows per page
pageToReturn - The page number to return
Returns:
The list containing the specified subset of groups
Throws:
LDAPOperationException - if the operation cannot be executed.
See Also:
ILDAPUtils.findGroups(int, int)

findGroupsOfUser

public Set<LDAPGroup> findGroupsOfUser(String loginName)
                                throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the list of a given user's groups.

Specified by:
findGroupsOfUser in interface ILDAPUtils
Parameters:
loginName - the user's login name
Returns:
the list of all the groups that the user belongs to
Throws:
LDAPOperationException - if the operation can't be executed
See Also:
ILDAPUtils.findGroupsOfUser(java.lang.String)

findGroupsOfUserPagination

public Set<LDAPGroup> findGroupsOfUserPagination(String loginName,
                                                 int rowsPerPage,
                                                 int pageToReturn)
                                          throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the list of a given user's groups, with pagination

Specified by:
findGroupsOfUserPagination in interface ILDAPUtils
Parameters:
loginName - the user's login name
rowsPerPage - The number of results per page
pageToReturn - The page number to return
Returns:
the list of all the groups that the user belongs to
Throws:
LDAPOperationException - if the operation can't be executed
See Also:
ILDAPUtils.findGroupsOfUserPagination(java.lang.String, int, int)

findUserByDistinguishedName

public LDAPUser findUserByDistinguishedName(String dn)
                                     throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the user with a given distinguished name.

Specified by:
findUserByDistinguishedName in interface ILDAPUtils
Parameters:
dn - the user's login name
Returns:
the LDAPUser with the given login name
Throws:
LDAPOperationException - if the operation cannot be executed
See Also:
ILDAPUtils.findUserByDistinguishedName(java.lang.String)

findUserByLogin

public LDAPUser findUserByLogin(String loginName)
                         throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the user with a given login name.

Specified by:
findUserByLogin in interface ILDAPUtils
Parameters:
loginName - the user's login name
Returns:
the LDAPUser with the given login name
Throws:
LDAPOperationException - if the operation cannot be executed
See Also:
ILDAPUtils.findUserByLogin(java.lang.String)

findUserByLogin

public LDAPUser findUserByLogin(String loginName,
                                boolean convertAttributes)
                         throws LDAPOperationException
Returns the user with a given login name.

Parameters:
loginName - the user's login name
convertAttributes - the convert attributes
Returns:
the LDAPUser with the given login name
Throws:
LDAPOperationException - if the operation cannot be executed

findUsers

public Set<LDAPUser> findUsers(int rowsPerPage,
                               int pageToReturn)
                        throws LDAPOperationException
Description copied from interface: ILDAPUtils
Finds a subset of all the users, according to the parameters

Specified by:
findUsers in interface ILDAPUtils
Parameters:
rowsPerPage - The number of rows per page
pageToReturn - The page number to return
Returns:
The list containing the specified subset of groups
Throws:
LDAPOperationException
See Also:
ILDAPUtils.findUsers(int, int)

findUsersByAttribute

public Set<LDAPUser> findUsersByAttribute(String attribute,
                                          String value)
                                   throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the list of users with a given attribute value.

Specified by:
findUsersByAttribute in interface ILDAPUtils
Parameters:
attribute - the attribute to search
value - the value for the attribute
Returns:
the LDAPUser with the given login name
Throws:
LDAPOperationException - if the operation cannot be executed
See Also:
ILDAPUtils.findUsersByAttribute(java.lang.String, java.lang.String)

findUsersByAttributes

public Set<LDAPUser> findUsersByAttributes(Map<String,String> attributes)
                                    throws LDAPOperationException
Description copied from interface: ILDAPUtils
Finds a set of LDAP users that match all of the specified criteria

Specified by:
findUsersByAttributes in interface ILDAPUtils
Parameters:
attributes - A map of (attribute, attribute value) pairs
Returns:
A set of LDAP users that match all of the specified criteria
Throws:
LDAPOperationException - if the operation cannot be executed
See Also:
ILDAPUtils.findUsersByAttributes(java.util.Map)

findUsersByAttributes

public Set<LDAPUser> findUsersByAttributes(Map<String,String> attributes,
                                           int rowsPerPage,
                                           int pageToReturn)
                                    throws LDAPOperationException
Description copied from interface: ILDAPUtils
Finds a set of LDAP users that match all of the specified criteria

Specified by:
findUsersByAttributes in interface ILDAPUtils
Parameters:
attributes - A map of (attribute, attribute value) pairs
rowsPerPage - The number of results per page
pageToReturn - The number of the page to return
Returns:
A set of LDAP users that match all of the specified criteria
Throws:
LDAPOperationException - if the operation cannot be executed
See Also:
ILDAPUtils.findUsersByAttributes(java.util.Map, int, int)

findUsersByEmail

public Set<LDAPUser> findUsersByEmail(String value)
                               throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the list of users with a given email attribute value.

Specified by:
findUsersByEmail in interface ILDAPUtils
Parameters:
value - the value for the attribute email
Returns:
the LDAPUser with the given login name
Throws:
LDAPOperationException - if the operation cannot be executed
See Also:
ILDAPUtils.findUsersByEmail(java.lang.String)

findUsersInGroup

public Map<String,LDAPUser> findUsersInGroup(String groupCN)
                                      throws LDAPOperationException
Description copied from interface: ILDAPUtils
Checks if a given user belongs to a given group.

Specified by:
findUsersInGroup in interface ILDAPUtils
Parameters:
groupCN - the group's CN
Returns:
a map of the group's users ()
Throws:
LDAPOperationException - if the operation can't be executed
See Also:
ILDAPUtils.findUsersInGroup(java.lang.String)

getAttributesForGroupAddition

protected Attributes getAttributesForGroupAddition(LDAPGroup newGroup)
                                            throws LDAPOperationException
Prepares the LDAP attributes for group addition.

Parameters:
newGroup - the group to add
Returns:
the attribute list
Throws:
LDAPOperationException - if the attribute list can't be prepared

getAttributesForUserAddition

protected Attributes getAttributesForUserAddition(LDAPUser newUser)
                                           throws LDAPOperationException
Prepares the LDAP attributes for user addition.

Parameters:
newUser - the user to add
Returns:
the attribute list
Throws:
LDAPOperationException - if the attribute list can't be prepared

getByDistinguishedName

protected SearchResult getByDistinguishedName(String distinguishedName)
                                       throws LDAPOperationException
Finds an entity by distinguished name. To be overridden on the different LDAP implementations.

Parameters:
distinguishedName - the distinguished name
Returns:
the result of the search by distinguished name
Throws:
LDAPOperationException - if operation cannot be performed

getByLogin

protected SearchResult getByLogin(String loginName)
                           throws LDAPOperationException
Finds an user by login name. To be overridden on the different LDAP implementations.

Parameters:
loginName - the login name of the user to find
Returns:
the result of the search by login name
Throws:
LDAPOperationException - if operation cannot be performed

getChildGroupsByCN

public Set<LDAPGroup> getChildGroupsByCN(String commonName)
                                  throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the list of groups that belong to a parent group given its common name.

Specified by:
getChildGroupsByCN in interface ILDAPUtils
Parameters:
commonName - the parent group's common name
Returns:
the list of all the groups that the user belongs to the parent group
Throws:
LDAPOperationException - if the operation can't be executed
See Also:
ILDAPUtils.getChildGroupsByCN(java.lang.String)

getChildGroupsByDN

public Set<LDAPGroup> getChildGroupsByDN(String distinguishedName)
                                  throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the list of groups that belong to a parent group given its distinguished name.

Specified by:
getChildGroupsByDN in interface ILDAPUtils
Parameters:
distinguishedName - the parent group's distinguished name
Returns:
the list of all the groups that the user belongs to the parent group
Throws:
LDAPOperationException - if the operation can't be executed
See Also:
ILDAPUtils.getChildGroupsByDN(java.lang.String)

getCommonName

protected final String getCommonName()
Returns the standard LDAP name for the 'cn' attribute.

Returns:
the standard LDAP name for the 'cn' attribute

getConfigurations

public LDAPConfigurations getConfigurations()
Description copied from interface: ILDAPUtils
Inspector for the LDAP configurations object.

Specified by:
getConfigurations in interface ILDAPUtils
Returns:
the LDAP configurations object
See Also:
ILDAPUtils.getConfigurations()

getDescriptionAttributeName

protected String getDescriptionAttributeName()
Returns the standard LDAP name for the 'description' attribute. To be overridden on the different LDAP implementations. This method must NOT be qualified with 'final' and/or 'static' to preserve polymorphic behavior.

Returns:
the standard LDAP name for the 'description' attribute

getDisplayNameAttributeName

protected String getDisplayNameAttributeName()
Returns the standard LDAP name for the 'displayName' attribute. To be overridden on the different LDAP implementations. This method must NOT be qualified with 'final' and/or 'static' to preserve polymorphic behavior.

Returns:
the standard LDAP name for the 'displayName' attribute

getGivenNameAttributeName

protected String getGivenNameAttributeName()
Returns the standard LDAP name for the 'givenName' attribute. To be overridden on the different LDAP implementations. This method must NOT be qualified with 'final' and/or 'static' to preserve polymorphic behavior.

Returns:
the standard LDAP name for the 'givenName' attribute

getGroupAttribute

public Object getGroupAttribute(String attributeName,
                                String commonName)
                         throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns a given attribute or null of it doesn't exists.

Specified by:
getGroupAttribute in interface ILDAPUtils
Parameters:
attributeName - the attribute name
commonName - the group common name
Returns:
the attribute with the given id
Throws:
LDAPOperationException - if the user attribute can't be fetched
See Also:
ILDAPUtils.getGroupAttribute(java.lang.String, java.lang.String)

getGroupAttributeName

public String getGroupAttributeName()
Description copied from interface: ILDAPUtils
Gets the name attribute name

Specified by:
getGroupAttributeName in interface ILDAPUtils
Returns:
The string containing the attribute name.
See Also:
ILDAPUtils.getGroupAttributeName()

getGroupAttributes

public Map<String,Object> getGroupAttributes(String commonName)
                                      throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the attribute map.

Specified by:
getGroupAttributes in interface ILDAPUtils
Parameters:
commonName - the group common name
Returns:
the attribute map
Throws:
LDAPOperationException - if the user attributes can't be fetched
See Also:
ILDAPUtils.getGroupAttributes(java.lang.String)

getGroupByCommonName

protected SearchResult getGroupByCommonName(String cn)
                                     throws LDAPOperationException
Finds an entity by common name. To be overridden on the different LDAP implementations.

Parameters:
cn - the common name
Returns:
the result of the search by common name
Throws:
LDAPOperationException - if operation cannot be performed

getGroupByDistinguishedName

protected LDAPGroup getGroupByDistinguishedName(String distinguishedName)
                                         throws LDAPOperationException
Finds a group by distinguished name.

Parameters:
distinguishedName - the distinguished name
Returns:
the group
Throws:
LDAPOperationException - if operation cannot be performed

getGroupClassName

protected abstract String getGroupClassName()
Returns the standard LDAP name for the 'group' attribute. To be implemented for the different LDAP technologies.

Returns:
the 'group' attribute name for each implementation

getGroupIdentifierName

protected final String getGroupIdentifierName()
Returns the group identifier name.

Returns:
the group identifier name

getGroupParentGroupAttributeName

public abstract String getGroupParentGroupAttributeName()
Returns the implementation dependent name for the LDAP attribute that stores the group's parent group. To be implemented for the different LDAP technologies.

Returns:
the parent group attribute name for each implementation

getLDAPContext

protected final LdapContext getLDAPContext()
                                    throws LDAPOperationException
Returns the LDAP context to use for search and modification operations.

Returns:
the LDAP context
Throws:
LDAPOperationException - if the context can't be created.

getMailAttributeName

public String getMailAttributeName()
Returns the standard LDAP name for the 'e-mail' attribute. To be overridden on the different LDAP implementations. This method must NOT be qualified with 'final' and/or 'static' to preserve polymorphic behavior.

Specified by:
getMailAttributeName in interface ILDAPUtils
Returns:
the standard LDAP name for the 'e-mail' attribute

getNameAttributeName

public String getNameAttributeName()
Returns the standard LDAP name for the 'name' attribute. To be overridden on the different LDAP implementations. This method must NOT be qualified with 'final' and/or 'static' to preserve polymorphic behavior.

Specified by:
getNameAttributeName in interface ILDAPUtils
Returns:
the standard LDAP name for the 'name' attribute

getNonAvailableValue

public String getNonAvailableValue()
Description copied from interface: ILDAPUtils
Get the Non Available Message.

Specified by:
getNonAvailableValue in interface ILDAPUtils
Returns:
the Non Available message.
See Also:
ILDAPUtils.getNonAvailableValue()

getObjectClassName

protected final String getObjectClassName()
Returns the 'objectClass' attribute name.

Returns:
the 'objectClass' attribute name

getPasswordAttributeName

protected String getPasswordAttributeName()
Returns the standard LDAP name for the 'password' attribute. To be overridden on the different LDAP implementations. This method must NOT be qualified with 'final' and/or 'static' to preserve polymorphic behavior.

Returns:
the standard LDAP name for the 'member' attribute

getSecureLDAPContext

protected final LdapContext getSecureLDAPContext()
                                          throws LDAPOperationException
Returns the LDAP context to use for search and modification operations with a secure connection.

Returns:
the LDAP context
Throws:
LDAPOperationException - if the context can't be created.

getSurnameAttributeName

protected String getSurnameAttributeName()
Returns the standard LDAP name for the 'surname' attribute. To be overridden on the different LDAP implementations. This method must NOT be qualified with 'final' and/or 'static' to preserve polymorphic behavior.

Returns:
the standard LDAP name for the 'surname' attribute

getUserAttribute

public Object getUserAttribute(String attributeName,
                               String loginName)
                        throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns a given attribute or null of it doesn't exists.

Specified by:
getUserAttribute in interface ILDAPUtils
Parameters:
attributeName - the attribute name
loginName - the user login name
Returns:
the attribute with the given id
Throws:
LDAPOperationException - if the user attribute can't be fetched
See Also:
ILDAPUtils.getUserAttribute(java.lang.String, java.lang.String)

getUserAttributes

public Map<String,Object> getUserAttributes(String loginName)
                                     throws LDAPOperationException
Description copied from interface: ILDAPUtils
Returns the attribute map.

Specified by:
getUserAttributes in interface ILDAPUtils
Parameters:
loginName - the user login name
Returns:
the attribute map
Throws:
LDAPOperationException - if the user attributes can't be fetched
See Also:
ILDAPUtils.getUserAttributes(java.lang.String)

getUserByDistinguishedName

protected LDAPUser getUserByDistinguishedName(String distinguishedName)
                                       throws LDAPOperationException
Finds an user by distinguished name.

Parameters:
distinguishedName - the distinguished name
Returns:
the user
Throws:
LDAPOperationException - if operation cannot be performed

getUserClassName

protected abstract String getUserClassName()
Returns the standard LDAP name for the 'user' attribute. To be implemented for the different LDAP technologies.

Returns:
the 'user' attribute name for each implementation

getUserIdentifierName

protected final String getUserIdentifierName()
Returns the user identifier name.

Returns:
the user identifier name

getUserInGroup

protected SearchResult getUserInGroup(String userLogin,
                                      String groupCN)
                               throws LDAPOperationException
Finds a user with a given login name on a given group.

Parameters:
userLogin - the user's login name
groupCN - the group's common name
Returns:
the user, if it exists, or null otherwise
Throws:
LDAPOperationException - if the user can't be fetched

getUserLoginAttributeName

public String getUserLoginAttributeName()
Description copied from interface: ILDAPUtils
Gets the user login attribute name

Specified by:
getUserLoginAttributeName in interface ILDAPUtils
Returns:
The string containing the attribute name.
See Also:
ILDAPUtils.getUserLoginAttributeName()

getUserParentGroupAttributeName

public String getUserParentGroupAttributeName()
Description copied from interface: ILDAPUtils
Returns the parent group attribute name.

Specified by:
getUserParentGroupAttributeName in interface ILDAPUtils
Returns:
A string containing the parent group attribute name
See Also:
ILDAPUtils.getUserParentGroupAttributeName()

groupContainsAttribute

public boolean groupContainsAttribute(String attributeName,
                                      String commonName)
                               throws LDAPOperationException
Group contains attribute.

Specified by:
groupContainsAttribute in interface ILDAPUtils
Parameters:
attributeName - the attribute name
commonName - the common name
Returns:
true, if successful
Throws:
LDAPOperationException - the lDAP operation exception
See Also:
ILDAPUtils.groupContainsAttribute(java.lang.String, java.lang.String)

groupExists

public boolean groupExists(String groupCN)
                    throws LDAPOperationException
Description copied from interface: ILDAPUtils
Checks if a given group exists on the LDAP tree.

Specified by:
groupExists in interface ILDAPUtils
Parameters:
groupCN - the group's CN
Returns:
T if the group is found on the LDAP tree, F otherwise
Throws:
LDAPOperationException - if the operation can't be executed
See Also:
ILDAPUtils.groupExists(java.lang.String)

isIdentityValid

public boolean isIdentityValid(String loginName,
                               String suppliedPassword)
                        throws LDAPOperationException
Description copied from interface: ILDAPUtils
Checks if the supplied password matches the one defined for a user with a given ID.

Specified by:
isIdentityValid in interface ILDAPUtils
Parameters:
loginName - the user ID
suppliedPassword - the supplied user password
Returns:
T if user if its identity is valid, F otherwise
Throws:
LDAPOperationException - if the operation cannot be executed
See Also:
ILDAPUtils.isIdentityValid(java.lang.String, java.lang.String)

isReadOnly

public boolean isReadOnly()
Description copied from interface: ILDAPUtils
Get the ldap readOnly configuration value.

Specified by:
isReadOnly in interface ILDAPUtils
Returns:
true or false
See Also:
ILDAPUtils.isReadOnly()

isUserInGroup

public boolean isUserInGroup(String groupCN,
                             String userLogin)
                      throws LDAPOperationException
Description copied from interface: ILDAPUtils
Checks if a given user belongs to a given group.

Specified by:
isUserInGroup in interface ILDAPUtils
Parameters:
groupCN - the group's CN
userLogin - the user's login name
Returns:
T if the user belongs to the given group, F otherwise
Throws:
LDAPOperationException - if the operation can't be executed
See Also:
ILDAPUtils.isUserInGroup(java.lang.String, java.lang.String)

modifyAttributes

protected final void modifyAttributes(String distinguishedName,
                                      ModificationItem[] mods,
                                      boolean secure)
                               throws LDAPOperationException
Modifies the passed attributes of an entity with the given DN.

Parameters:
distinguishedName - the DN of the entity to modify
mods - the attributes to modify
secure - if the connection is secure
Throws:
LDAPOperationException - if the attributes can't be modified

removeGroup

public void removeGroup(String groupCN)
                 throws LDAPOperationException
Description copied from interface: ILDAPUtils
Removes an existing group from the LDAP tree.

Specified by:
removeGroup in interface ILDAPUtils
Parameters:
groupCN - the group to add
Throws:
LDAPOperationException - if the group can't be removed
See Also:
ILDAPUtils.removeGroup(java.lang.String)

removeGroupAttribute

public void removeGroupAttribute(String commonName,
                                 String attributeName)
                          throws LDAPOperationException
Description copied from interface: ILDAPUtils
Removes an attribute from a given group.

Specified by:
removeGroupAttribute in interface ILDAPUtils
Parameters:
commonName - the group's common name
attributeName - the attribute name
Throws:
LDAPOperationException
See Also:
ILDAPUtils.removeGroupAttribute(java.lang.String, java.lang.String)

removeUser

public void removeUser(String loginName)
                throws LDAPOperationException
Description copied from interface: ILDAPUtils
Removes an existing user from the LDAP tree.

Specified by:
removeUser in interface ILDAPUtils
Parameters:
loginName - the id of the user to remove
Throws:
LDAPOperationException - if the user can't be removed
See Also:
ILDAPUtils.removeUser(java.lang.String)

removeUserAttribute

public void removeUserAttribute(String loginName,
                                String attributeName)
                         throws LDAPOperationException
Description copied from interface: ILDAPUtils
Removes an attribute from a given user.

Specified by:
removeUserAttribute in interface ILDAPUtils
Parameters:
loginName - the user login name
attributeName - the attribute name
Throws:
LDAPOperationException - if the attribute can't be added
See Also:
ILDAPUtils.removeUserAttribute(java.lang.String, java.lang.String)

removeUserFromGroup

public void removeUserFromGroup(String groupCN,
                                String userLogin)
                         throws LDAPOperationException
Description copied from interface: ILDAPUtils
Removes a user from a given group.

Specified by:
removeUserFromGroup in interface ILDAPUtils
Parameters:
groupCN - the CN of the group
userLogin - the login name of the user to remove
Throws:
LDAPOperationException - if the user groups can't be removed
See Also:
ILDAPUtils.removeUserFromGroup(java.lang.String, java.lang.String)

resetConfigurations

public void resetConfigurations()
Description copied from interface: ILDAPUtils
Resets the LDAP configurations. Forces the configurations to be re-read. VALIDATE: Viegas: This method is helpful to change the configurations in runtime. For example, a management interface user might choose to change the root username or password. The changes must be reflected immediately so the user can keep it's privileges. The management interface should call this method to reinitialize the configurations.

Specified by:
resetConfigurations in interface ILDAPUtils
See Also:
ILDAPUtils.resetConfigurations()

setGroupAttribute

public void setGroupAttribute(String commonName,
                              String attributeName,
                              Object value)
                       throws LDAPOperationException
Description copied from interface: ILDAPUtils
Sets a given attribute value.

Specified by:
setGroupAttribute in interface ILDAPUtils
Parameters:
commonName - the user login name
attributeName - the attribute name
value - the attribute value
Throws:
LDAPOperationException - if the attribute can't be set
See Also:
ILDAPUtils.setGroupAttribute(java.lang.String, java.lang.String, java.lang.Object)

setLogger

public void setLogger(pt.digitalis.log.ILogWrapper logger)
Description copied from interface: ILDAPUtils
Set the API logger

Specified by:
setLogger in interface ILDAPUtils
Parameters:
logger - the new logger value to set
See Also:
ILDAPUtils.setLogger(pt.digitalis.log.ILogWrapper)

setUserAttribute

public void setUserAttribute(String loginName,
                             String attributeName,
                             Object value)
                      throws LDAPOperationException
Description copied from interface: ILDAPUtils
Sets the a given attribute value.

Specified by:
setUserAttribute in interface ILDAPUtils
Parameters:
loginName - the user login name
attributeName - the attribute name
value - the attribute value
Throws:
LDAPOperationException - if the attribute can't be set
See Also:
ILDAPUtils.setUserAttribute(java.lang.String, java.lang.String, java.lang.Object)

updateGroup

public void updateGroup(LDAPGroup groupToUpdate,
                        String groupCN)
                 throws LDAPOperationException
Description copied from interface: ILDAPUtils
Updates an existing group on the LDAP tree. Does nothing if the user doesn't exist.

Specified by:
updateGroup in interface ILDAPUtils
Parameters:
groupToUpdate - the user to update
groupCN - the group ID
Throws:
LDAPOperationException - if the group cannot be updated
See Also:
Implementation note: the attribute 'name' is not eligible for modification (for AD, check other impls).

updateUser

public void updateUser(LDAPUser userToUpdate,
                       String userLogin)
                throws LDAPOperationException
Description copied from interface: ILDAPUtils
Updates an existing user on the LDAP tree. Does nothing if the user doesn't exist.

Specified by:
updateUser in interface ILDAPUtils
Parameters:
userToUpdate - the user to update
userLogin - the user's original login
Throws:
LDAPOperationException - if the operation cannot be executed
See Also:
ILDAPUtils.updateUser(pt.digitalis.utils.ldap.LDAPUser, java.lang.String)

userContainsAttribute

public boolean userContainsAttribute(String id,
                                     String loginName)
                              throws LDAPOperationException
Description copied from interface: ILDAPUtils
Checks if a given attribute belongs to the entity.

Specified by:
userContainsAttribute in interface ILDAPUtils
Parameters:
id - the attribute name
loginName - the user login name
Returns:
T if the entity has the attribute, F otherwise
Throws:
LDAPOperationException - if the user attribute can't be fetched
See Also:
ILDAPUtils.userContainsAttribute(java.lang.String, java.lang.String)

userExists

public boolean userExists(String loginName)
                   throws LDAPOperationException
Description copied from interface: ILDAPUtils
Checks if a user exists on the LDAP tree.

Specified by:
userExists in interface ILDAPUtils
Parameters:
loginName - the ID of the user
Returns:
T if the user exists, F otherwise
Throws:
LDAPOperationException - if the operation cannot be executed
See Also:
ILDAPUtils.userExists(java.lang.String)


Copyright © 2012 Digitalis Informática Lda. All Rights Reserved.