@@ -550,9 +550,9 @@ protected String prepareLoginPage(HttpServletRequest request, AuthenticationCont
550
550
String callbackurl = getCallbackUrl (authenticatorProperties , context );
551
551
552
552
String state = getStateParameter (request , context , authenticatorProperties );
553
- context .setProperty (OIDCAuthenticatorConstants . AUTHENTICATOR_NAME + STATE_PARAM_SUFFIX , state );
553
+ context .setProperty (getName () + STATE_PARAM_SUFFIX , state );
554
554
String nonce = UUID .randomUUID ().toString ();
555
- context .setProperty (OIDC_FEDERATION_NONCE , nonce );
555
+ context .setProperty (getName () + OIDC_FEDERATION_NONCE , nonce );
556
556
boolean isPKCEEnabled = Boolean .parseBoolean (
557
557
authenticatorProperties .get (OIDCAuthenticatorConstants .IS_PKCE_ENABLED ));
558
558
@@ -591,7 +591,7 @@ protected String prepareLoginPage(HttpServletRequest request, AuthenticationCont
591
591
592
592
String scope = paramValueMap .get (OAuthConstants .OAuth20Params .SCOPE );
593
593
scope = getScope (scope , authenticatorProperties );
594
- context .setProperty (OIDCAuthenticatorConstants . AUTHENTICATOR_NAME + SCOPE_PARAM_SUFFIX , scope );
594
+ context .setProperty (getName () + SCOPE_PARAM_SUFFIX , scope );
595
595
596
596
if (StringUtils .isNotBlank (queryString ) && queryString .toLowerCase ().contains ("scope=" ) && queryString
597
597
.toLowerCase ().contains ("redirect_uri=" )) {
@@ -642,7 +642,7 @@ protected String prepareLoginPage(HttpServletRequest request, AuthenticationCont
642
642
loginPage = loginPage + queryString ;
643
643
}
644
644
}
645
- context .setProperty (OIDCAuthenticatorConstants . AUTHENTICATOR_NAME + REDIRECT_URL_SUFFIX , loginPage );
645
+ context .setProperty (getName () + REDIRECT_URL_SUFFIX , loginPage );
646
646
return loginPage ;
647
647
} else {
648
648
if (LOG .isDebugEnabled ()) {
@@ -668,6 +668,21 @@ protected String prepareLoginPage(HttpServletRequest request, AuthenticationCont
668
668
}
669
669
}
670
670
671
+ /**
672
+ * This method can be used to add the authentication error message content into the context.
673
+ *
674
+ * @param errorMessage ErrorMessage object.
675
+ * @param context AuthenticationContext.
676
+ */
677
+ protected static void setAuthenticatorMessageToContext (ErrorMessages errorMessage ,
678
+ AuthenticationContext context ) {
679
+
680
+ AuthenticatorMessage authenticatorMessage = new AuthenticatorMessage (FrameworkConstants .
681
+ AuthenticatorMessageType .ERROR , errorMessage .
682
+ getCode (), errorMessage .getMessage (), null );
683
+ context .setProperty (AUTHENTICATOR_MESSAGE , authenticatorMessage );
684
+ }
685
+
671
686
/**
672
687
* This method is used to append the application side requested scopes after validating.
673
688
* The application can request the scopes for federated token sharing either via adaptive scripts
@@ -925,15 +940,6 @@ private String getQueryParameter(AuthenticationContext context, String queryPara
925
940
return null ;
926
941
}
927
942
928
- private static void setAuthenticatorMessageToContext (ErrorMessages errorMessage ,
929
- AuthenticationContext context ) {
930
-
931
- AuthenticatorMessage authenticatorMessage = new AuthenticatorMessage (FrameworkConstants .
932
- AuthenticatorMessageType .ERROR , errorMessage .
933
- getCode (), errorMessage .getMessage (), null );
934
- context .setProperty (AUTHENTICATOR_MESSAGE , authenticatorMessage );
935
- }
936
-
937
943
private String getStateParameter (HttpServletRequest request , AuthenticationContext context ,
938
944
Map <String , String > authenticatorProperties ) {
939
945
@@ -1047,12 +1053,13 @@ protected void processAuthenticationResponse(HttpServletRequest request, HttpSer
1047
1053
LOG .debug ("Retrieved the User Information:" + jwtAttributeMap );
1048
1054
}
1049
1055
1050
- if (StringUtils .isNotBlank ((String ) context .getProperty (OIDC_FEDERATION_NONCE ))) {
1056
+ String nonceKey = getName () + OIDC_FEDERATION_NONCE ;
1057
+ if (StringUtils .isNotBlank ((String ) context .getProperty (nonceKey ))) {
1051
1058
String nonce = (String ) jwtAttributeMap .get (NONCE );
1052
1059
if (nonce == null ) {
1053
1060
LOG .debug ("OIDC provider does not support nonce claim in id_token." );
1054
1061
}
1055
- if (nonce != null && !nonce .equals (context .getProperty (OIDC_FEDERATION_NONCE ))) {
1062
+ if (nonce != null && !nonce .equals (context .getProperty (nonceKey ))) {
1056
1063
setAuthenticatorMessageToContext (ErrorMessages .NONCE_MISMATCH , context );
1057
1064
1058
1065
throw new AuthenticationFailedException (ErrorMessages .NONCE_MISMATCH .getCode (),
@@ -1829,26 +1836,25 @@ private static AdditionalData getAdditionalData(
1829
1836
AuthenticationContext context , boolean isNativeSDKBasedFederationCall ) {
1830
1837
1831
1838
AdditionalData additionalData = new AdditionalData ();
1839
+ String currentAuthenticator = StringUtils .isNotBlank (context .getCurrentAuthenticator ()) ?
1840
+ context .getCurrentAuthenticator () : OIDCAuthenticatorConstants .AUTHENTICATOR_NAME ;
1832
1841
1833
1842
if (isNativeSDKBasedFederationCall ) {
1834
1843
Map <String , String > additionalAuthenticationParams = new HashMap <>();
1835
1844
1836
- String nonce = (String ) context .getProperty (OIDC_FEDERATION_NONCE );
1845
+ String nonce = (String ) context .getProperty (currentAuthenticator + OIDC_FEDERATION_NONCE );
1837
1846
if (StringUtils .isNotBlank (nonce )) {
1838
1847
additionalAuthenticationParams .put (NONCE , nonce );
1839
1848
}
1840
1849
additionalAuthenticationParams .put (OIDCAuthenticatorConstants .CLIENT_ID_PARAM ,
1841
1850
context .getAuthenticatorProperties ().get (OIDCAuthenticatorConstants .CLIENT_ID ));
1842
- String scope = (String ) context .getProperty (OIDCAuthenticatorConstants .AUTHENTICATOR_NAME +
1843
- SCOPE_PARAM_SUFFIX );
1851
+ String scope = (String ) context .getProperty (currentAuthenticator + SCOPE_PARAM_SUFFIX );
1844
1852
additionalAuthenticationParams .put (OIDCAuthenticatorConstants .SCOPE , scope );
1845
1853
additionalData .setAdditionalAuthenticationParams (additionalAuthenticationParams );
1846
1854
} else {
1847
- additionalData .setRedirectUrl ((String ) context .getProperty (OIDCAuthenticatorConstants .AUTHENTICATOR_NAME +
1848
- REDIRECT_URL_SUFFIX ));
1855
+ additionalData .setRedirectUrl ((String ) context .getProperty (currentAuthenticator + REDIRECT_URL_SUFFIX ));
1849
1856
Map <String , String > additionalAuthenticationParams = new HashMap <>();
1850
- String state = (String ) context .getProperty (OIDCAuthenticatorConstants .AUTHENTICATOR_NAME +
1851
- STATE_PARAM_SUFFIX );
1857
+ String state = (String ) context .getProperty (currentAuthenticator + STATE_PARAM_SUFFIX );
1852
1858
additionalAuthenticationParams .put (OIDCAuthenticatorConstants .OAUTH2_PARAM_STATE , state );
1853
1859
additionalData .setAdditionalAuthenticationParams (additionalAuthenticationParams );
1854
1860
}
0 commit comments