Search code examples
authenticationkerberoscasspnego

How to get LDAP user attributes with SPNEGO and CAS?


Using CAS 5.3.x and SPNEGO (Kerberos) authentication, how do I get more user attributes than just the SAMAccountName?

When I only use "standard" LDAP authentication handler, I can just put this configuration:

cas.authn.ldap[0].principalAttributeList=sAMAccountName,displayName,givenName,mail

But after a SPNEGO authentication I don't get those additional attributes.

Do you know a way to do it?


Solution

  • The ability to fetch attributes from external data stores has been present in CAS since the days of 3.x. This functionality was and, to this day, is provided by an Apereo project called Person Directory which is a Java framework for resolving persons and attributes from a variety of underlying sources. It consists of a collection of components that retrieve, cache, resolve, aggregate and merge person attributes from JDBC, LDAP and more. CAS attempts to take advantage of this framework through a concept called PrincipalResolver whose goal is to construct a final identifiable authenticated principal for CAS which carries a number of attributes inside it fetched from attribute repository sources. This meant that for instance, one could authenticate with SPNEGO in one query and then turn around the ask LDAP, a relational database and a Groovy script to fetch attributes for the resolved principal and combine all results into a final collection.

    Note that in most cases like in the case of direct LDAP authentication, and starting around CAS 4.x, the authentication engine has been enhanced to be able to retrieve and resolve attributes from the authentication source, which would eliminate the need for configuring a separate attribute repository/resolver especially if both the authentication and the attribute source are the same. Using separate resolvers and sources should only be required when sources are different, or when there is a need to tackle more advanced attribute resolution use cases such as cascading, merging, etc.

    To configure CAS to use an external LDAP for attribute repositories, use:

    cas.authn.attribute-repository.ldap[0].attributes.uid=uid
    cas.authn.attribute-repository.ldap[0].attributes.displayName=displayName
    cas.authn.attribute-repository.ldap[0].attributes.cn=commonName
    cas.authn.attribute-repository.ldap[0].attributes.memberOf=memberOf
    
    cas.authn.attribute-repository.ldap[0].ldapUrl=ldap://...
    cas.authn.attribute-repository.ldap[0].useSsl=false
    cas.authn.attribute-repository.ldap[0].useStartTls=false
    cas.authn.attribute-repository.ldap[0].baseDn=dc=example,dc=edu
    cas.authn.attribute-repository.ldap[0].searchFilter=uid={0}
    cas.authn.attribute-repository.ldap[0].bindDn=...
    cas.authn.attribute-repository.ldap[0].bindCredential=...