2013-10-19 78 views
1

我为几个应用程序设置了一个Spring Jasig CAS SSO。这使用CasAuthenticationFilter。所以我有这样的webapps设置 -为CasAuthenticationFilter设置预授权过滤器

Cas Server (Cas 3.5.2) - Cas.war,App1 - App1.warApp2 - App2.war。应用程序使用Spring 3.2.3和Spring Security 3.1.4.RELEASE。

Spring Security Confighttp://pastie.org/private/qxcx1h8i9ys0w3lmwegiw

事情似乎与此设置正常工作。现在,当我在Cas服务器上启用OAuth(而不是通过Spring Cas)时,我无法将该身份验证与我设置的通常基于表单的身份验证集成在一起。 Facebook的OAuth集成似乎工作正常,因为我可以看到在日志中成功检索的Facebook配置文件属性。问题是,后facebook的登录,CasAuthenticationFilter尝试验证用户“FacebookProfile#XYZXYZ”与基于窗体的登录类似的机制,显然它没有在用户的数据库表中找到该用户。我的猜测是,我需要写一个扩展AbstractPreAuthenticatedProcessingFilterPRE_AUTH_FILTER前位置(查看以上的pastie配置),并且应该以某种方式设置Authentication权利,所以CasAuthenticationFilter应该知道用户已经登录在自定义过滤器。

这是URL被CasAuthenticationFilter认证为每日志 - /j_spring_cas_security_proxyreceptor?pgtIou=PGTIOU-1-pR9r9LVJvB5EkezbMJHN-talenteye.in&pgtId=TGT-2-QXvAHIRciBNR9HU5FOvpOaHcJaBj5OJTUPPz5ZwA7yK1xH54iL-myorg.in

实施CasAuthenticationFilterrequiresAuthentication看起来是这样的:

protected boolean requiresAuthentication(final HttpServletRequest request, final HttpServletResponse response) { 
    final boolean serviceTicketRequest = serviceTicketRequest(request, response); 
    final boolean result = serviceTicketRequest || proxyReceptorRequest(request) || (proxyTicketRequest(serviceTicketRequest, request)); 
    if(logger.isDebugEnabled()) { 
     logger.debug("requiresAuthentication = "+result); 
    } 
    return result; 
} 

和日志s说 -

19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter -  serviceTicketRequest = false 
19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - proxyReceptorConfigured = true 
19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - proxyReceptorRequest = true 
19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - requiresAuthentication = true 
19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - Request is to process authentication 
19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - proxyReceptorConfigured = true 
19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - proxyReceptorRequest = true 
19:23:42.835 [http-bio-8080-exec-8] DEBUG o.s.s.c.web.CasAuthenticationFilter - Responding to proxy receptor request 

我很困惑如何使这项工作在一起。我想知道我是否有点太复杂了。任何指针都会非常有用,因为我已经浪费了几天的时间。

回答

1

我自己解决了这个问题,因此在这里发布给面临类似问题的其他人。

使用CAS的重点是集中认证。我写了一个扩展AbstractCasAssertionUserDetailsService的自定义类。这不会执行身份验证。它必须在CAS服务器上完成。这只准备CAS客户端Web应用程序使用的一个UserDetails对象。所以,在我的情况下,PRE-AUTH并不需要。另外,我摆脱了不必要的代理接收器配置。它现在运作良好。