2016-04-11 91 views
1

我正在嘗試在我們的Web服務中集成CAS認證,並使用基於Spring的webapp的Jasig CAS server(v.4.2)。Jasig CAS - 如何在登錄成功後自定義WebFlow重定向用戶?

不幸的是,Jasig CAS服務器在成功登錄後只能使用服務ID進行重定向。 這是不可接受的,因爲CAS服務器位於反向代理之後,我們不'使用DNS。 所以,登錄網址看起來像:

http://a.b.c.d/cas/login?service=http://x.x.x.x/context-path/auth-entry-point

其中

  • ABCD - 外部(代理)IP地址
  • XXXX - 內部(服務/ CAS客戶端)IP地址

我讀過Jasig文檔,但發現無法混淆服務URL。 現在我試圖實現自定義邏輯。我想通過重定向URL作爲單獨的PARAM:

http://a.b.c.d/login?service=<serviceUID_like_YYY-YYY-YYY>&redirect=<base64_encoded_URL>

..並使用此參數有關重定向,而不是服務ID。

根據doc Jasig CAS使用Spring Webflow實現登錄場景(login-webflow.xml)。 而這正是重定向造成的地方:

<end-state id="redirectView" view="externalRedirect:#{requestScope.response.url}"/>

因爲我不熟悉Spring Weblow的問題是:

我怎樣才能收到「重定向」 URL PARAM,解碼和使用重定向?

P.S.對不起,我的英文不好,我希望它至少可以解析:-)

回答

1

好的,這很簡單。對於任何人誰感興趣的是:

org.jasig.cas創建自定義的服務豆*包:

package org.jasig.cas.usercustom; 

import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import org.springframework.stereotype.Component; 
import org.springframework.util.Base64Utils; 

@Component("userCustomRedirectHelper") 
public class RedirectHelper { 

    final static Logger logger = LoggerFactory.getLogger(RedirectHelper.class); 

    public String decodeURLFromString(String src) { 
     String url = new String(Base64Utils.decodeFromString(src)); 
     logger.debug("Redirect URL: " + src); 
     return url; 
    } 
} 

修改登錄-webflow.xml如下:

<on-start> 
    <!-- get redirect param, decode and place into flowScope --> 
    <evaluate expression="userCustomRedirectHelper.decodeURLFromString(requestParameters.redirect)" result="flowScope.customRedirectURL" /> 
</on-start> 

<!-- redirect --> 
<end-state id="redirectView" view="externalRedirect:#{flowScope.customRedirectURL}"/>