3

我在尝试使用 Spring Security 使用现有(阅读:非常“传统”)单点登录解决方案来保护新的 Spring MVC 应用程序时遇到了一些问题。

免责声明:我对 Spring 整体比较熟悉,但对 Spring Security 完全不熟悉;请原谅我的无知。

SSO 服务的工作方式如下:

  1. 用户导航到他们选择的 Web 应用程序:http: //apps.myco.com/webapp123
  2. 用户未通过身份验证,因此他们被重定向到http://sso.myco.com/login并提示登录
  3. 用户通过身份验证并使用附加到查询字符串的令牌重定向回应用程序:http ://apps.myco.com/webapp123?token=ABCD1234
  4. 在每次页面加载(当前为 JSP 页面)时,用户的令牌会从查询字符串中提取出来,然后通过 SOAP 回调触发 SSO 服务,以检查令牌的有效性。SSO 服务对令牌表示赞成或反对(如果令牌有效且仍然是最新的,则表示赞成;否则,表示反对)
  5. 如果令牌有效,则可以进行另一个 SOAP 调用以获取用户名(如果需要)

SSO 服务不处理用于授权的用户凭据,因此必须在每个应用程序的基础上进行处理:(

据我了解,这里普遍接受的做法是使用 Spring Security 的预身份验证框架,但我 (a) 不确定我的假设是否正确,并且 (b) 不确定我需要附带的所有东西该解决方案。

目前,我LoginUrlAuthenticationEntryPoint定义了一个 bean,它将未经身份验证的用户定向到 SSO 站点:

<beans:bean id="customAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
    <beans:constructor-arg value="http://sso.myco.com/login" />
</beans:bean>

入口点的连接方式如下:

<http use-expressions="true" entry-point-ref="customAuthenticationEntryPoint">
    <intercept-url pattern="/" access="permitAll" />
    <intercept-url pattern="/edit/**" access="isAuthenticated()" />
    <intercept-url pattern="/setup/**" access="hasRole('setup')" />
    <intercept-url pattern="/admin/**" access="hasRole('admin')" />
</http>

对我来说,症结在于在哪里挂接以接收来自 SSO 服务的“回调”。我想要的是有一个 URL(比如http://apps.myco.com/webapp123/auth?token=ABCD1234)接受来自 SSO 服务的这些重定向,验证令牌并从 SSO 检索用户名,然后将所有这些信息保存在 Spring Security 上下文中。然而,我很有可能走错了路,或者我只是错过了一两块。

非常感谢任何帮助或指导。

4

2 回答 2

1

好的,这就是我要做的:

我会将 AbstractAuthenticationProcessingFilter 子类化,将 authenticationManager 设置为您在 Spring Security xml 中连接的身份验证管理器。你真的应该只需要覆盖 attemptAuthentication 方法。此方法接受请求和响应对象,允许访问您的 URL 参数等。

如果身份验证成功,您只需要返回一个 Authentication 对象,Spring 安全应该处理将用户放入上下文等。

这是文档:

http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/web/authentication/AbstractAuthenticationProcessingFilter.html

希望这可以帮助!

编辑:

可能想看看 Spring 的人如何实现它的直接子类,在这种情况下,UsernamePasswordAuthenticationFilter 位于此处:

http://www.jarvana.com/jarvana/view/org/springframework/security/spring-security-web/3.0.5.RELEASE/spring-security-web-3.0.5.RELEASE-sources.jar!/org /springframework/security/web/authentication/UsernamePasswordAuthenticationFilter.java?format=ok

于 2012-05-30T18:05:49.690 回答
0

我建议实现一个自定义 Voter,以根据令牌有效性和用户详细信息分配角色(设置、管理员等)。请参阅基于投票的 AccessDecisionManager 实现以及其中引用的博客:SPRING SECURITY CUSTOMIZATION(第 2 部分 - 实时调整安全会话)

于 2012-05-30T14:12:19.847 回答