Integrate Single Sign On using Spring Security

前端 未结 1 417
情书的邮戳
情书的邮戳 2020-12-23 15:06

I\'m using Spring Security and I would like to use another site as one of my authentication providers. I have a basic form based login on my site. I want to have a link on

相关标签:
1条回答
  • 2020-12-23 15:38

    The general approach is:

    1) Subclass AbstractAuthenticationToken for your XML logins, let's call it XMLAuthenticationToken.

    2) Subclass AbstractAuthenticationProcessingFilter and add it to the filter chain after UsernamePasswordAuthenticationFilter. It should create a XMLAuthenticationToken based on the data in the XML. You can use UsernamePasswordAuthenticationFilter as an example for the general structure of the filter (that's most likely the filter that you are currently using for your regular Spring Security logins).

    <http>
      <custom-filter after="FORM_LOGIN_FILTER" ref="xmlAuthenticationFilter"/>
    </http>
    

    The filter should set a filterProcessesUrl that is different from the UsernamePasswordFilter. This is the URL the external system will post the XML to. For example:

    public XmlAuthenticationFilter() {
        super("/xml_security_check");
    }
    

    3) Subclass AbstractUserDetailsAuthenticationProvider. Have it look up the user from the UserDetailsService based on the info in the token, and then authenticate it. Use DaoAuthenticationProvider as an example. You will need to register the new provider with the AuthenticationManager.

    <authentication-manager>
      <authentication-provider user-service-ref='myUserDetailsService'/>
      <authentication-provider ref="xmlAuthenticationProvider" />
    </authentication-manager>
    

    You might be able to get away with reusing UsernamePasswordAuthenticationToken (for #1, it has a nice "details" extension mechanism) and DaoAuthenticationProvider (or subclassing it) for #3.

    0 讨论(0)
提交回复
热议问题