I'm trying to configure authentication (SSO- SP initiated) with OKTA as IDP where my spring boot application will be working as a Service Provider through SAML. I am trying to retrieve relaystate parameter sent by IDP in http post request body. I am retrieving saml response using @authenticationPrincipal but I am not able to find any sample code or documentation to get relayState. Can someone help me with this? Sample code will be appreciated.
Asked
Active
Viewed 536 times
1 Answers
0
In case of SP-initiated
flow, it's Service provider (SP) that pass the relay params and want to receive the same after the authentication from the IdP.
If you've the Authentication
object you can easily get the relay state as mentioned below:
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
SAMLCredentials credentials = (SAMLCredentials) authentication.getCredentials();
String relayState = credentials.getRelayState();

b.s
- 2,409
- 2
- 16
- 26
-
Thanks for the response. I tried using this but getting the exception: java.lang.String cannot be cast to class org.springframework.security.saml.SAMLCredential (java.lang.String is in module java.base of loader 'bootstrap'; org.springframework.security.saml.SAMLCredential is in unnamed module of loader 'app') – SIMRAN KHOLIA Aug 15 '22 at 13:48
-
Which version of springboot, spring security and spring-security-saml2 are you using? – b.s Aug 19 '22 at 10:35