Class LdapAuthenticationHandler

  • All Implemented Interfaces:
    org.apereo.cas.authentication.AuthenticationHandler, org.apereo.cas.authentication.PrePostAuthenticationHandler, org.springframework.beans.factory.DisposableBean, org.springframework.core.Ordered

    public class LdapAuthenticationHandler
    extends org.apereo.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler
    implements org.springframework.beans.factory.DisposableBean
    LDAP authentication handler that uses the ldaptive Authenticator component underneath. This handler provides simple attribute resolution machinery by reading attributes from the entry corresponding to the DN of the bound user (in the bound security context) upon successful authentication.
    Since:
    4.0.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map<java.lang.String,​java.lang.Object> principalAttributeMap
      Mapping of LDAP attribute name to principal attribute name.
      • Fields inherited from class org.apereo.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler

        passwordPolicyHandlingStrategy
      • Fields inherited from class org.apereo.cas.authentication.AbstractAuthenticationHandler

        credentialSelectionPredicate, principalFactory, servicesManager
      • Fields inherited from interface org.apereo.cas.authentication.AuthenticationHandler

        SUCCESSFUL_AUTHENTICATION_HANDLERS
      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Constructor Summary

      Constructors 
      Constructor Description
      LdapAuthenticationHandler​(java.lang.String name, org.apereo.cas.services.ServicesManager servicesManager, org.apereo.cas.authentication.principal.PrincipalFactory principalFactory, java.lang.Integer order, org.ldaptive.auth.Authenticator authenticator, org.apereo.cas.authentication.AuthenticationPasswordPolicyHandlingStrategy strategy)
      Creates a new authentication handler that delegates to the given authenticator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.apereo.cas.authentication.AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal​(org.apereo.cas.authentication.credential.UsernamePasswordCredential upc, java.lang.String originalPassword)  
      protected java.util.Map<java.lang.String,​java.util.List<java.lang.Object>> collectAttributesForLdapEntry​(org.ldaptive.LdapEntry ldapEntry, java.lang.String username)
      Collect attributes for ldap entry.
      protected org.apereo.cas.authentication.principal.Principal createPrincipal​(java.lang.String username, org.ldaptive.LdapEntry ldapEntry)
      Creates a CAS principal with attributes if the LDAP entry contains principal attributes.
      void destroy()  
      protected java.lang.String getLdapPrincipalIdentifier​(java.lang.String username, org.ldaptive.LdapEntry ldapEntry)
      Gets ldap principal identifier.
      void initialize()
      Initialize the handler, setup the authentication entry attributes.
      • Methods inherited from class org.apereo.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler

        doAuthentication, getPasswordEncoder, getPasswordPolicyConfiguration, getPasswordPolicyHandlingStrategy, getPrincipalNameTransformer, matches, setPasswordEncoder, setPasswordPolicyConfiguration, setPasswordPolicyHandlingStrategy, setPrincipalNameTransformer, supports, supports, transformPassword, transformUsername
      • Methods inherited from class org.apereo.cas.authentication.handler.support.AbstractPreAndPostProcessingAuthenticationHandler

        authenticate, createHandlerResult, createHandlerResult
      • Methods inherited from class org.apereo.cas.authentication.AbstractAuthenticationHandler

        getCredentialSelectionPredicate, getName, getOrder, getPrincipalFactory, getServicesManager, setCredentialSelectionPredicate
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.apereo.cas.authentication.AuthenticationHandler

        getName, getOrder
      • Methods inherited from interface org.apereo.cas.authentication.PrePostAuthenticationHandler

        postAuthenticate, preAuthenticate
    • Field Detail

      • principalAttributeMap

        protected java.util.Map<java.lang.String,​java.lang.Object> principalAttributeMap
        Mapping of LDAP attribute name to principal attribute name.
    • Constructor Detail

      • LdapAuthenticationHandler

        public LdapAuthenticationHandler​(java.lang.String name,
                                         org.apereo.cas.services.ServicesManager servicesManager,
                                         org.apereo.cas.authentication.principal.PrincipalFactory principalFactory,
                                         java.lang.Integer order,
                                         org.ldaptive.auth.Authenticator authenticator,
                                         org.apereo.cas.authentication.AuthenticationPasswordPolicyHandlingStrategy strategy)
        Creates a new authentication handler that delegates to the given authenticator.
        Parameters:
        name - the name
        servicesManager - the services manager
        principalFactory - the principal factory
        order - the order
        authenticator - Ldaptive authenticator component.
        strategy - the strategy
    • Method Detail

      • destroy

        public void destroy()
        Specified by:
        destroy in interface org.springframework.beans.factory.DisposableBean
      • authenticateUsernamePasswordInternal

        protected org.apereo.cas.authentication.AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal​(org.apereo.cas.authentication.credential.UsernamePasswordCredential upc,
                                                                                                                          java.lang.String originalPassword)
                                                                                                                   throws java.security.GeneralSecurityException,
                                                                                                                          org.apereo.cas.authentication.PreventedException
        Specified by:
        authenticateUsernamePasswordInternal in class org.apereo.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler
        Throws:
        java.security.GeneralSecurityException
        org.apereo.cas.authentication.PreventedException
      • createPrincipal

        protected org.apereo.cas.authentication.principal.Principal createPrincipal​(java.lang.String username,
                                                                                    org.ldaptive.LdapEntry ldapEntry)
                                                                             throws javax.security.auth.login.LoginException
        Creates a CAS principal with attributes if the LDAP entry contains principal attributes.
        Parameters:
        username - Username that was successfully authenticated which is used for principal ID when principal id is not specified.
        ldapEntry - LDAP entry that may contain principal attributes.
        Returns:
        Principal if the LDAP entry contains at least a principal ID attribute value, null otherwise.
        Throws:
        javax.security.auth.login.LoginException - On security policy errors related to principal creation.
      • collectAttributesForLdapEntry

        protected java.util.Map<java.lang.String,​java.util.List<java.lang.Object>> collectAttributesForLdapEntry​(org.ldaptive.LdapEntry ldapEntry,
                                                                                                                       java.lang.String username)
        Collect attributes for ldap entry.
        Parameters:
        ldapEntry - the ldap entry
        username - the username
        Returns:
        the map
      • getLdapPrincipalIdentifier

        protected java.lang.String getLdapPrincipalIdentifier​(java.lang.String username,
                                                              org.ldaptive.LdapEntry ldapEntry)
                                                       throws javax.security.auth.login.LoginException
        Gets ldap principal identifier. If the principal id attribute is defined, it's retrieved. If no attribute value is found, a warning is generated and the provided username is used instead. If no attribute is defined, username is used instead.
        Parameters:
        username - the username
        ldapEntry - the ldap entry
        Returns:
        the ldap principal identifier
        Throws:
        javax.security.auth.login.LoginException - in case the principal id cannot be determined.
      • initialize

        public void initialize()
        Initialize the handler, setup the authentication entry attributes.