that is true! I tried PrincipalIdAttribute, the flow made no difference.
But the problem remains. say user johnsmith in CAS maps to jsmith in Okta. I can do some validation so that when Okta authenticates jsmith, CAS returns principal as johnsmith, I still want CAS to store johnsmith somewhere Before it delegates to Okta. (It is possible multiple users in CAS maps to the same Okta user, thus we want to know the username entered in CAS -before- delegating to Okta). This is similar to how CAS handles relay_state in SAML delegated authN.
this following is my idea, but did not work.
public class MyDelegatedClientAuthenticationWebflowStateContributor extends DefaultDelegatedClientAuthenticationWebflowStateContributor {
@Override
public Map<String, Serializable> store(final RequestContext requestContext, final WebContext webContext,
final Client client) throws Throwable {
// user enters username: johnsmith in CAS UI, CAS looks up external IdP, it is Okta.
// we store username johnsmith before delegated authN
// but I do not know how to get the username that user entered earlier in CAS UI
String userBeforeDelegateAuthN = (String) ..... ??
Map<String, Serializable> properties = new HashMap<>(super.store(requestContext, webContext, client));
properties.put("userBeforeDelegateAuthN", userBeforeDelegateAuthN);
return properties;
}
@Override
public Service restore(final RequestContext requestContext,
final WebContext webContext,
final Optional<TransientSessionTicket> givenSessionTicket,
final Client client) {
val service = super.restore(requestContext, webContext, givenSessionTicket, client);
val properties = givenSessionTicket.get().getProperties();
// we put username back into request attribute as SAML response comes from Okta
// then, somewhere else (such as authenticationHandler), I get this attribute, create the principal using this attribute: johnsmith (CAS username),
// copying Okta attributes for jsmith
webContext.setRequestAttribute("userBeforeDelegateAuthN", properties.get("userBeforeDelegateAuthN"));
return service;
}
}