55import org .keycloak .authentication .AuthenticationFlowContext ;
66import org .keycloak .authentication .AuthenticationFlowError ;
77import org .keycloak .authentication .authenticators .broker .IdpAutoLinkAuthenticator ;
8+ import org .keycloak .authentication .authenticators .broker .util .ExistingUserInfo ;
89import org .keycloak .authentication .authenticators .broker .util .SerializedBrokeredIdentityContext ;
910import org .keycloak .broker .provider .BrokeredIdentityContext ;
1011import org .keycloak .events .Errors ;
@@ -36,6 +37,12 @@ protected void authenticateImpl(AuthenticationFlowContext context, SerializedBro
3637 brokerContext .getIdpConfig ().getAlias (), brokerContext .getUsername ());
3738
3839 context .setUser (existingUser );
40+
41+ var shortAttributName = getShortAttributName (config );
42+
43+ ExistingUserInfo duplication = new ExistingUserInfo (existingUser .getId (), shortAttributName , existingUser .getFirstAttribute (shortAttributName ));
44+ context .getAuthenticationSession ().setAuthNote (EXISTING_USER_INFO , duplication .serialize ());
45+
3946 context .success ();
4047 } else {
4148 if (failOnNoMatch .equals ("true" )) {
@@ -47,6 +54,14 @@ protected void authenticateImpl(AuthenticationFlowContext context, SerializedBro
4754
4855 }
4956
57+ private static String getShortAttributName (AuthenticatorConfigModel config ) {
58+ var fullAttributeName = config .getConfig ().get (CustomAttributeIdpLinkingAuthenticatorFactory .CONFIG_IDP_ATTRIBUTE );
59+ return Optional .of (fullAttributeName )
60+ .filter (a -> a .contains ("." ))
61+ .map (a -> a .substring (a .lastIndexOf ("." ) + 1 ))
62+ .orElse (fullAttributeName );
63+ }
64+
5065 private AuthenticatorConfigModel validateConfig (AuthenticationFlowContext context ) {
5166 if (context .getAuthenticatorConfig () == null ) {
5267 log .warn ("Config must not be empty." );
0 commit comments