Class LdapService

    • Constructor Detail

      • LdapService

        public LdapService()
    • Method Detail

      • setLdapCtxFactory

        public void setLdapCtxFactory​(String ldapCtxFactory)
        Set another factory class to be used as JNDI parameter Context.INITIAL_CONTEXT_FACTORY. This is primarily useful for unit testing. The default value is com.sun.jndi.ldap.LdapCtxFactory.
        Parameters:
        ldapCtxFactory - an alternative context factory class to be used.
      • loginUser

        public boolean loginUser​(Site site,
                                 String username,
                                 char[] password)
        Tries to login the user with the given username and password.
        Parameters:
        site - the Site the user wants to login at
        username - The plain name of the user without base-DN. This name will be mapped to an LDAP principal according to the value of "ldapPrincipalScheme".
        password - the password of the user
        Returns:
        true if the user could be successfully logged in, null otherwise
      • loginGroup

        public List<String> loginGroup​(Site site,
                                       String username,
                                       char[] password,
                                       SubjectImpl subject,
                                       List<String> groupNames)
        Tries to login the user as a member of at least one of the given groups. Therefore two steps are necessary. First, the login of the user with the given password must be successful. Second, the user must be a member of at least one group.
        Note that to determine the memberships a service user with credentials taken from "ldapUser" and "ldapPassword", will be used. This username may be specified as Distinguished Name (DN) e.g. "cn=Service User, dc=mycompany, dc=com". If this is the case, it will be used as LDAP principal without mapping. If it is not a DN, it will be mapped as described in loginUser(Site, String, char[]).
        Parameters:
        site - the Site the user wants to login at
        username - the name of the user
        password - the password of the user
        subject - a SubjectImpl where the name and real name are set, in case the user belongs to at least one of the given groups
        groupNames - a list containing the names of all groups to check group membership for (without base-DN, this is set in the site-property "ldapGroupBaseDn")
        Returns:
        the names of all groups that the user is a member of (may be empty)
      • getMembersOfGroup

        public List<SubjectImpl> getMembersOfGroup​(Site site,
                                                   String groupName)
        Fetches the members of a given group and returns them as a List of SubjectImpl objects. Members are LDAP Objects in the member attribute(s) of "ldapIdAttribute"=groupName,"ldapGroupBaseDn".
        Parameters:
        site - the Site in which the application using this group is running
        groupName - the name of the group whose members should be fetched
        Returns:
        the members of the groupName (may be empty)