CAS实现URL扩展参数

CAS实现URL扩展参数

以前用CAS3.3.1实现了一个SSO单点登录,这次遇到一个新需求。
用户想用一个URL链接过来登录,同时要根据URL传递过来的参数转向到一个用户自己定义的页面。

比如,当一封邮件发送给用户后,用户能点击这个LINK直接转向到我们的系统,登录,并转向到用户想要看到的某个特定页面:
<a href="http://localhost:8088/cascenter2/login?auto=true&username=admin&password=111111&service=http://localhost:8088/itsmadmin/j_spring_cas_security_check?spring-security-redirect=http://localhost:8088/itsmadmin/user/list.do">Link</a>
这个链接里面传递了三个参数
username用户名
password密码
service是要转向的页面,其中分了两部分,
http://localhost:8088/itsmadmin/j_spring_cas_security_check 是要转向的WAR包的认证路径
spring-security-redirect 是专项该WAR认证成功后转向的URL

要完成这个功能,需要对CAS3.3.1的源码做稍微改动
org.jasig.cas.CentralAuthenticationServiceImpl 这个类为CAS认证TICKET的入口,不用改动
org.jasig.cas.ticket.ServiceTicketImpl 这个类里面的方法
public boolean isValidFor(final Service serviceToValidate) {
updateState();
return serviceToValidate.matches(this.service);
}
会去验证,这个service参数和spring-security配置里面的service是否一致
<beans:bean id="serviceProperties"
class="org.springframework.security.ui.cas.ServiceProperties">
<beans:property name="service" value="${cas.client.itsmadmin}/j_spring_cas_security_check" />
<beans:property name="sendRenew" value="false" />
</beans:bean>
但这里的service是WAR里面固定的,不会根据参数的不同而改变。所以不修改这里会导致
org.jasig.cas.CentralAuthenticationServiceImpl这个类里面的如下行报错:
if (!serviceTicket.isValidFor(service)) {
if (log.isErrorEnabled()) {
log.error("ServiceTicket [" + serviceTicketId
+ "] with service [" + serviceTicket.getService().getId() + " does not match supplied service [" + service + "]");
}
throw new TicketValidationException(serviceTicket.getService());
}

我用比较土的办法,修改了
org.jasig.cas.ticket.ServiceTicketImpl 这个类里面的方法
public boolean isValidFor(final Service serviceToValidate) {
updateState();
//return serviceToValidate.matches(this.service);
return true;
}

然后重新打包一下
到这个路径
E:\book\opensource\cas\cas-server-3.3.1\cas-server-core
命令:
mvn clean
mvn -DskipTests=true package
结果这个版本的pom.xml好像有点错误,报错找不到这个类:
找不到类MapAdaptable
org.springframework.binding.collection.MapAdaptable

我修改了pom.xml文件,增加了spring-binding
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-binding</artifactId>
<version>1.0.5</version>
<scope>compile</scope>
</dependency>
打包成功。

使用POST方式传递三个参数到过去已经可以正常登陆了。发现在URL传递的时候却要报错用户名和密码错误。
修改了cascenter2/WebContent/WEB-INF/view/jsp/customer/ui/casLoginView.jsp
里面的
<form style="display:none" method="post" action="<%=response.encodeRedirectURL("login" + (StringUtils.hasText(request.getQueryString()) ? "?" + request.getQueryString() : ""))%>">

<form style="display:none" method="post" action="<%=response.encodeRedirectURL("login")%>">

就OK了。

但是新问题出来了,当输入用户名和密码错误的时候,不能返回到登陆页面并提示,原来是因为我把QUERYSTRING省略了的原因
改为
<form style="display:none" method="post" action="<%=response.encodeRedirectURL("login" + "?auto=true")%>">
就OK了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值