Class PersonDirectoryPrincipalResolver

  • All Implemented Interfaces:
    org.apereo.cas.authentication.principal.PrincipalResolver

    public class PersonDirectoryPrincipalResolver
    extends java.lang.Object
    implements org.apereo.cas.authentication.principal.PrincipalResolver
    Resolves principals by querying a data source using the Jasig Person Directory API. The Principal.getAttributes() are populated by the results of the query and the principal ID may optionally be set by proving an attribute whose first non-null value is used; otherwise the credential ID is used for the principal ID.
    Since:
    4.0.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apereo.services.persondir.IPersonAttributeDao attributeRepository
      Repository of principal attributes to be retrieved.
      protected java.lang.String principalAttributeName
      Optional principal attribute name.
      protected org.apereo.cas.authentication.principal.PrincipalFactory principalFactory
      Factory to create the principal type.
      protected org.apereo.cas.authentication.handler.PrincipalNameTransformer principalNameTransformer
      Transform principal name.
      protected boolean returnNullIfNoAttributes
      return null if no attributes are found.
      protected boolean useCurrentPrincipalId
      Use the current principal id for extraction.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.apache.commons.lang3.tuple.Pair<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>> convertPersonAttributesToPrincipal​(java.lang.String extractedPrincipalId, java.util.Map<java.lang.String,java.util.List<java.lang.Object>> attributes)
      Convert person attributes to principal pair.
      protected java.lang.String extractPrincipalId​(org.apereo.cas.authentication.Credential credential, java.util.Optional<org.apereo.cas.authentication.principal.Principal> currentPrincipal)
      Extracts the id of the user from the provided credential.
      org.apereo.cas.authentication.principal.Principal resolve​(org.apereo.cas.authentication.Credential credential, java.util.Optional<org.apereo.cas.authentication.principal.Principal> currentPrincipal, java.util.Optional<org.apereo.cas.authentication.AuthenticationHandler> handler)  
      protected java.util.Map<java.lang.String,java.util.List<java.lang.Object>> retrievePersonAttributes​(java.lang.String principalId, org.apereo.cas.authentication.Credential credential)
      Retrieve person attributes map.
      boolean supports​(org.apereo.cas.authentication.Credential credential)  
      • 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.principal.PrincipalResolver

        getAttributeRepository, resolve, resolve
    • Field Detail

      • attributeRepository

        protected final org.apereo.services.persondir.IPersonAttributeDao attributeRepository
        Repository of principal attributes to be retrieved.
      • principalFactory

        protected final org.apereo.cas.authentication.principal.PrincipalFactory principalFactory
        Factory to create the principal type.
      • returnNullIfNoAttributes

        protected final boolean returnNullIfNoAttributes
        return null if no attributes are found.
      • principalNameTransformer

        protected final org.apereo.cas.authentication.handler.PrincipalNameTransformer principalNameTransformer
        Transform principal name.
      • principalAttributeName

        protected final java.lang.String principalAttributeName
        Optional principal attribute name.
      • useCurrentPrincipalId

        protected boolean useCurrentPrincipalId
        Use the current principal id for extraction.
    • Constructor Detail

      • PersonDirectoryPrincipalResolver

        public PersonDirectoryPrincipalResolver()
      • PersonDirectoryPrincipalResolver

        public PersonDirectoryPrincipalResolver​(org.apereo.services.persondir.IPersonAttributeDao attributeRepository,
                                                java.lang.String principalAttributeName)
      • PersonDirectoryPrincipalResolver

        public PersonDirectoryPrincipalResolver​(org.apereo.services.persondir.IPersonAttributeDao attributeRepository)
      • PersonDirectoryPrincipalResolver

        public PersonDirectoryPrincipalResolver​(boolean returnNullIfNoAttributes,
                                                java.lang.String principalAttributeName)
      • PersonDirectoryPrincipalResolver

        public PersonDirectoryPrincipalResolver​(org.apereo.services.persondir.IPersonAttributeDao attributeRepository,
                                                org.apereo.cas.authentication.principal.PrincipalFactory principalFactory,
                                                boolean returnNullIfNoAttributes,
                                                java.lang.String principalAttributeName)
    • Method Detail

      • supports

        public boolean supports​(org.apereo.cas.authentication.Credential credential)
        Specified by:
        supports in interface org.apereo.cas.authentication.principal.PrincipalResolver
      • resolve

        public org.apereo.cas.authentication.principal.Principal resolve​(org.apereo.cas.authentication.Credential credential,
                                                                         java.util.Optional<org.apereo.cas.authentication.principal.Principal> currentPrincipal,
                                                                         java.util.Optional<org.apereo.cas.authentication.AuthenticationHandler> handler)
        Specified by:
        resolve in interface org.apereo.cas.authentication.principal.PrincipalResolver
      • convertPersonAttributesToPrincipal

        protected org.apache.commons.lang3.tuple.Pair<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>> convertPersonAttributesToPrincipal​(java.lang.String extractedPrincipalId,
                                                                                                                                                            java.util.Map<java.lang.String,java.util.List<java.lang.Object>> attributes)
        Convert person attributes to principal pair.
        Parameters:
        extractedPrincipalId - the extracted principal id
        attributes - the attributes
        Returns:
        the pair
      • retrievePersonAttributes

        protected java.util.Map<java.lang.String,java.util.List<java.lang.Object>> retrievePersonAttributes​(java.lang.String principalId,
                                                                                                            org.apereo.cas.authentication.Credential credential)
        Retrieve person attributes map.
        Parameters:
        principalId - the principal id
        credential - the credential whose id we have extracted. This is passed so that implementations can extract useful bits of authN info such as attributes into the principal.
        Returns:
        the map
      • extractPrincipalId

        protected java.lang.String extractPrincipalId​(org.apereo.cas.authentication.Credential credential,
                                                      java.util.Optional<org.apereo.cas.authentication.principal.Principal> currentPrincipal)
        Extracts the id of the user from the provided credential. This method should be overridden by subclasses to achieve more sophisticated strategies for producing a principal ID from a credential.
        Parameters:
        credential - the credential provided by the user.
        currentPrincipal - the current principal
        Returns:
        the username, or null if it could not be resolved.