I am using spring security saml extension for sso in my application. I am able to successfully integrate with adfs. Now I need the exact encoded SAML response we get from adfs to be passed to webservices downstream. How to get that SAML response string?
Asked
Active
Viewed 3,910 times
2 Answers
4
If your SAML token is encrypted:
You can extend default SAMLAuthenticationProvider and override authenticate method. Inside this method you can get the complete SAML Response as follows:
SAMLAuthenticationToken token = (SAMLAuthenticationToken) authentication;
SAMLMessageContext context = token.getCredentials();
try {
String assertion = XMLHelper.nodeToString(SAMLUtil.marshallMessage(context.getInboundMessage()));
System.out.println(assertion);
} catch (MessageEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
If your SAML token is not encrypted, you can use this:
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
SAMLCredential credential = (SAMLCredential) authentication.getCredentials();
Assertion assertion = credential.getAuthenticationAssertion().getParent();

Uday Shankar
- 844
- 7
- 20

Agam
- 1,015
- 2
- 11
- 21
-
I got a compile error: Type mismatch: cannot convert from XMLObject to Assertion – Henry Sep 15 '20 at 06:43
2
See chapter 9.5 in the manual, it discusses how to keep the Assertion in the original format using the releaseDOM
flag and how to extract it (in the same way as Agam writes).

Vladimír Schäfer
- 15,375
- 2
- 51
- 71