Our model cas 6.6.6 is not exactly as yours (ours is DBMS/Azure rather than LDAP) but likely parallels the issue so may provide some perspective.
Authentication model where some users authenticated with DBMS name/pass and others through Azure. Challenge was how to make the released parameters consistent for the client application regardless of how authenticated.
For DBMS the primary id was the username, for Azure the primary id was the user's email (as the separate concept of the username was specific to the DBMS).
For DBMS name/pass not a problem as the username was already the primary id. For Azure to get translated to username authentication, had to add in a few additional configuration settings (shown below)
# config properties used with azure and property resolution
<other azure connection properties>
...
cas.authn.pac4j.oidc[0].azure.scope=...,email
...
cas.authn.pac4j.oidc[0].azure.principal-attribute-id=email
cas.authn.authentication-attribute-release.enabled=true
# included both primary attributes in attribute release (as well as other attributes not shown)
cas.authn.attribute-repository.core.default-attributes-to-release=username,email,...
# set the expiration time to 0 to disable caching these attributes in memory,
# so they will be retrieved each time
cas.authn.attribute-repository.core.expiration-time=0
# use cascade so that the attributes from initial queries can be used as the
# query for the next repository
cas.authn.attribute-repository.core.aggregation=CASCADE
# in our case set merger to REPLACE
cas.authn.attribute-repository.core.merger=REPLACE
...
# setup an attribute repository to be used as a person directory that in
# turn is used to translate Azure release attributes into DBMS username
# attribute AFTER the Azure authentication has taken place
cas.authn.attribute-repository.jdbc[0].id=azuretostandardusername
... (plus other jdbc connection settings)
# <user record view> has been defined to return at most one row per Azure email
# and that row will be the user record associated with the email
cas.authn.attribute-repository.jdbc[0].sql=SELECT * FROM <user record view> WHERE {0}
cas.authn.attribute-repository.jdbc[0].isolate-internal-queries=false
cas.authn.attribute-repository.jdbc[0].single-row=true
cas.authn.attribute-repository.jdbc[0].require-all-attributes=false
cas.authn.attribute-repository.jdbc[0].attributes.email=email
cas.authn.attribute-repository.jdbc[0].attributes.username=username
... <other attributes from the user record view also included in the repository>
cas.authn.attribute-repository.jdbc[0].username=email
cas.authn.attribute-repository.jdbc[0].case-insensitive-query-attributes=email->LOWER
...
#
# added for person directory resolution which is used to translate
# from Azure authentication results to DBMS username attribute
#
cas.person-directory.active-attribute-repository-ids=azuretostandardusername
cas.person-directory.attribute-resolution-enabled=true
## these lines left here as documentation
## these are ignored... they are overridden by the
## cas.authn.pac4j.oidc[0].azure.principal-attribute-id=email
## defined above
##
## cas.person-directory.principal-attribute=email
## cas.person-directory.principal-attribute=unique_name
cas.person-directory.principal-resolution-conflict-strategy=first
cas.person-directory.principal-resolution-failure-fatal=false
cas.person-directory.principal-transformation.case-conversion=LOWERCASE
cas.person-directory.return-null=true
# in this case principal id refers to email from azure
cas.person-directory.use-existing-principal-id=true
Added the following to service file to treat the resulting username as the primary attribute for both
authentication approaches so that after the above attribute repository (resolution) it would always use
the username as the "usernameAttribute" (for the benefit of the client app)
Note that in this case releasing attributes from azuretostandardusername
"usernameAttributeProvider" : {
"@class" : "org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider",
"usernameAttribute" : "username",
"canonicalizationMode" : "NONE"
},
"attributeReleasePolicy" : {
"principalAttributesRepository" : {
"@class" : "org.apereo.cas.authentication.principal.DefaultPrincipalAttributesRepository",
"ignoreResolvedAttributes": false,
"attributeRepositoryIds": ["java.util.HashSet", [ "azuretostandardusername" ]],
"mergingStrategy" : "SOURCE"
},
"@class" : "org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy",
"allowedAttributes" : [ "java.util.ArrayList", [ "email", "username", ...] ]
}