Class DataLayer

  • All Implemented Interfaces:
    Serializable

    public class DataLayer
    extends Object
    implements Serializable
    DataLayer (A PACKAGE SCOPE CLASS) to access LDAP or other database TODO: 1. Needs to subclass and isolate the current implementation of DataLayer as DSLayer for ldap specific operations 2. Improvements needed for _ldapPool: destroy(), initial bind user, tunning for MIN and MAX initial settings etc 3. May choose to extend implementation of _ldapPool from LDAPConnectionPool so that there is load balance between connections. Also _ldapPool may be implemented with a HashTable of (host,port) for mulitple pools of connections for mulitple (host,port) to DS servers instead of single host and port.
    See Also:
    Serialized Form
    • Method Detail

      • initConnectionParams

        public static void initConnectionParams()
      • getInstance

        public static DataLayer getInstance()
                                     throws UMSException
        Create the singleton DataLayer object if it doesn't exist already. Assumes the server instance for "LDAPUser.Type.AUTH_PROXY".
        Throws:
        UMSException
      • getConnection

        public org.forgerock.opendj.ldap.Connection getConnection​(Principal principal)
                                                           throws org.forgerock.opendj.ldap.LdapException
        Get connection from pool. Reauthenticate if necessary
        Returns:
        connection that is available to use.
        Throws:
        org.forgerock.opendj.ldap.LdapException
      • getAttributeString

        public String[] getAttributeString​(Principal principal,
                                           Guid guid,
                                           String attrName)
        Returns String values of the attribute.
        Parameters:
        principal - Authentication Principal.
        guid - distinguished name.
        attrName - attribute name.
      • getAttribute

        public Attr getAttribute​(Principal principal,
                                 Guid guid,
                                 String attrName)
        Returns Attr from the given attribute name.
        Parameters:
        principal - Authentication Principal.
        guid - Distinguished name.
        attrName - Attribute name.
      • getAttributes

        public Collection<Attr> getAttributes​(Principal principal,
                                              Guid guid,
                                              Collection<String> attrNames)
        Returns attributes for the given attribute names.
        Parameters:
        principal - Authentication Principal.
        guid - Distinguished name.
        attrNames - Attribute names.
        Returns:
        collection of Attr.
      • read

        public AttrSet read​(Principal principal,
                            Guid guid)
                     throws UMSException
        Read an ldap entry
        Parameters:
        guid - globally unique identifier for the entry
        Returns:
        an attribute set representing the entry in ldap, all non operational attributes are read
        Throws:
        EntryNotFoundException - if the entry is not found
        UMSException - Fail to read the entry
      • read

        public AttrSet read​(Principal principal,
                            Guid guid,
                            String[] attrNames)
                     throws UMSException
        Reads an ldap entry.
        Parameters:
        principal - Authentication Principal.
        guid - Globally unique identifier for the entry.
        attrNames - Attributes to read.
        Returns:
        an attribute set representing the entry in LDAP.
        Throws:
        EntryNotFoundException - if the entry is not found.
        UMSException - if fail to read the entry.
      • modify

        public void modify​(Principal principal,
                           Guid guid,
                           Collection<org.forgerock.opendj.ldap.Modification> modifications)
                    throws UMSException
        Modifies an ldap entry.
        Parameters:
        principal - Authentication Principal.
        guid - globally unique identifier for the entry.
        modifications - Set of modifications for the entry.
        Throws:
        AccessRightsException - if insufficient access
        EntryNotFoundException - if the entry is not found.
        UMSException - if failure
      • changePassword

        public void changePassword​(Guid guid,
                                   String attrName,
                                   String oldPassword,
                                   String newPassword)
                            throws UMSException
        Changes user password.
        Parameters:
        guid - globally unique identifier for the entry.
        attrName - password attribute name
        oldPassword - old password
        newPassword - new password
        Throws:
        AccessRightsException - if insufficient access
        EntryNotFoundException - if the entry is not found.
        UMSException - if failure
      • addAttributeValue

        public void addAttributeValue​(Principal principal,
                                      Guid guid,
                                      String name,
                                      String value)
                               throws UMSException
        Adds value for an attribute and saves the change in the database.
        Parameters:
        principal - Authenticated Principal.
        guid - ID of the entry to which to add the attribute value.
        name - name of the attribute to which value is being added.
        value - Value to be added to the attribute.
        Throws:
        UMSException - if there is any error while adding the value.
      • removeAttributeValue

        public void removeAttributeValue​(Principal principal,
                                         Guid guid,
                                         String name,
                                         String value)
                                  throws UMSException
        Removes value for an attribute and saves the change in the database.
        Parameters:
        principal - Authenticated Principal.
        guid - the id of the entry from which to remove the attribute value.
        name - Name of the attribute from which value is being removed
        value - Value to be removed from the attribute.
        Throws:
        UMSException - if there is any error while removing the value.
      • search

        public SearchResults search​(Principal principal,
                                    Guid guid,
                                    int scope,
                                    String searchFilter,
                                    String[] attrNames,
                                    boolean attrOnly,
                                    SearchControl searchControl)
                             throws UMSException
        Performs synchronous search based on specified ldap filter. This is low level API which assumes caller knows how to construct a data store filer.
        Parameters:
        principal - Authenticated Principal.
        guid - Unique identifier for the entry.
        scope - Scope can be either SCOPE_ONE, SCOPE_SUB or SCOPE_BASE.
        searchFilter - Search filter for this search.
        attrNames - Attribute name for retrieving.
        attrOnly - if true, returns the names but not the values of the attributes found.
        searchControl - Search Control.
        Throws:
        UMSException - if failure.
        InvalidSearchFilterException - if failure
      • searchIDs

        public SearchResults searchIDs​(Principal principal,
                                       Guid guid,
                                       int scope,
                                       String searchFilter,
                                       SearchControl searchControl)
                                throws InvalidSearchFilterException,
                                       UMSException
        Perform synchronous search based on specified ldap filter. This is low level API which assumes caller knows how to construct a data store filer.
        Parameters:
        principal - Authenticated Principal.
        guid - Unique identifier for the entry
        scope - Scope can be either SCOPE_ONE, SCOPE_SUB, SCOBE_BASE
        searchFilter - Search filter for this search.
        searchControl - Search Control.
        Throws:
        UMSException - if failure.
        InvalidSearchFilterException - if failure.
      • getSchema

        public org.forgerock.opendj.ldap.schema.Schema getSchema​(Principal principal)
                                                          throws UMSException
        Fetches the schema from the LDAP directory server. Retrieve the entire schema from the root of a Directory Server.
        Returns:
        the schema in the LDAP directory server
        Throws:
        AccessRightsException - insufficient access
        UMSException - Fail to fetch the schema.
        org.forgerock.opendj.ldap.LdapException - Error with LDAP connection.
      • readLDAPEntry

        public org.forgerock.opendj.ldap.Entry readLDAPEntry​(org.forgerock.opendj.ldap.Connection ld,
                                                             String dn,
                                                             String[] attrnames)
                                                      throws org.forgerock.opendj.ldap.LdapException
        Throws:
        org.forgerock.opendj.ldap.LdapException
      • readLDAPEntry

        public org.forgerock.opendj.ldif.ConnectionEntryReader readLDAPEntry​(Principal principal,
                                                                             org.forgerock.opendj.ldap.requests.SearchRequest request)
                                                                      throws UMSException
        Throws:
        UMSException
      • getConnNumRetry

        public static int getConnNumRetry()
      • getConnRetryInterval

        public static int getConnRetryInterval()
      • getRetryErrorCodes

        public static Set<org.forgerock.opendj.ldap.ResultCode> getRetryErrorCodes()