1

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?

Uday Shankar
  • 844
  • 7
  • 20

2 Answers2

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
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