2013-10-19 77 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並不需要。另外,我擺脫了不必要的代理接收器配置。它現在運作良好。