How to get SAML response string after successful login from spring security saml

假装没事ソ 提交于 2019-12-10 12:15:41

问题


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?


回答1:


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();



回答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).



来源:https://stackoverflow.com/questions/48656560/how-to-get-saml-response-string-after-successful-login-from-spring-security-saml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!