项目场景:
使用CAS5实现单点登录,同时需要集成其他OAuth认证方式。对外提供OAuth2.0和OIDC服务,支持Client_ID及secret的动态管理,同时与业务系统进行关联。
问题描述
在对外提供Oauth2.0服务,同时调用委托认证的情况下,会发现用360浏览器时第一次认证后,第二次仍然会要求委托认证。
原因分析:
360浏览器在两次连接过程中,cookie里中的 userAgent 和request 请求获取到的不一致,CAS在异常处理后会清除前次保存的Cookie内容。导致第一次认证无效。
解决方案:
修改源代码,将字符串equals改为部分相同。
DefaultCasCookieValueManager.java 中
final String agent = HttpRequestUtils.getHttpServletRequestUserAgent(request);
String agent1 = "";
String userAgent1 ="";
try{
agent1 = agent.split(";")[0];
userAgent1 = userAgent.split(";")[0];
}
catch (Exception e){
e.printStackTrace();
}
if (!userAgent1.equals(agent1)) {
throw new IllegalStateException("Invalid cookie. Required user-agent " + userAgent + " does not match " + agent);
}
/* if (!userAgent.equals(agent)) {
throw new IllegalStateException("Invalid cookie. Required user-agent " + userAgent + " does not match " + agent);
}*/
return value;