Spring saml - how remember request parameter when initiate login on SP, and procesing them after IdP response

谁说胖子不能爱 提交于 2019-12-03 07:25:29

Spring SAML sample application behaves like this out of the box. When user hits a page which is protected by Spring Security and requires authentication system:

  • remembers parameters which were used to invoke the page (done automatically inside Spring Security using ExceptionTranslationFilter and HttpSessionRequestCache) by storing the information into the HTTP session
  • invokes Spring SAML's entry point (SAMLEntryPoint class) which redirects user to the IDP, possible after IDP selection
  • user authenticates at IDP and is redirected back to your application
  • Spring SAML verifies the response and invokes AuthenticationSuccessHandler, which (in the sample application) is of type org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler
  • the success handler checks whether there's a stored request (put there in the first step) and if so it makes user's browser to open the remembered page with the same set of parameters as initially
  • the security check should now pass, provided the authenticated user is authorized to access the page

You could of course implement this using relay state as you intended. The correct way to set relay state is by extending SAMLEntryPoint, overriding method getProfileOptions and returning your desired relay state in the returned WebSSOProfileOptions object.

You can then change the AuthenticationSuccessHandler to org.springframework.security.saml.SAMLRelayStateSuccessHandler which make redirect to the URL returned from the relay state after successful authentication.

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