`
liuzhiyi7288
  • 浏览: 31159 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

CAS client 端添加初始化参数传到server端

    博客分类:
  • SSO
 
阅读更多
1. 修改client 端web应用的web.xml,如下:
<filter>
		<filter-name>CAS Authentication Filter</filter-name>
		<filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
		<init-param>
			<param-name>casServerLoginUrl</param-name>
			<!-- CAS服务端地址-->
			<param-value>http://192.168.104.123:8080/cas/login</param-value>
		</init-param>
		<init-param>
			<param-name>service</param-name>
			<!-- 本地地址-->
			<param-value>http://192.168.104.101:8080/*</param-value>
		</init-param>
		<init-param>
			<param-name>renew</param-name>
			<param-value>false</param-value>
			<!-- 这个如果为true 每次登录子系统都要验证,就不能实现登陆一次,可以访问其他子系统的需求 -->
		</init-param>
		<init-param>
			<param-name>webRootKey</param-name>
			<param-value>test</param-value>
		</init-param>
	</filter>

其中webRootKey参数为client添加的初始化参数,想传到server端

2. 修改org.jasig.cas.client.authentication.AuthenticationFilter.java如下:
添加属性webRootKey
/**
	 * the web app root key
	 */
	private String webRootKey;

提供set方法
public final  void setWebRootKey(final String webRootKey){
    	this.webRootKey = webRootKey;
    }

修改initInternal方法,添加
setWebRootKey(getPropertyFromInitParams(filterConfig, "webRootKey", null));
            log.trace("Loaded WebRootKey parameter: " + this.webRootKey);

修改init方法,添加
 CommonUtils.assertNotNull(this.webRootKey, "webRootKey cannot be null.");



3 自定义Credentials类继承UsernamePasswordCredentials,内容如下:
private static final long serialVersionUID = 179318697348051866L;
    
    /** the web root key */
    private String webRootKey;

	public String getWebRootKey() {
		return webRootKey;
	}

	public void setWebRootKey(String webRootKey) {
		this.webRootKey = webRootKey;
	}


4 修改自定义验证类(继承 AbstractJdbcUsernamePasswordAuthenticationHandler)的authenticateUsernamePasswordInternal方法如下:
FinalUserCredentials finalUserCredentials = (FinalUserCredentials) credentials;
		String username = finalUserCredentials.getUsername();
		String password = finalUserCredentials.getPassword();
		
		/** get web root key */
		String webRootKey = finalUserCredentials.getWebRootKey();
既可以获得webRootKey扩展参数。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics