我已经用LDAP / AD和数据库设置了CAS,它可以正常工作。现在,我想添加Keycloak,但是关于状态,我得到了一个例外。
Caused by: org.pac4j.core.exception.TechnicalException: State parameter is different from the one sent in authentication request. Session expired or possible threat of cross-site request forgery
为了测试,我添加了Google,但是发生了类似的问题。
DEBUG [org.pac4j.oauth.credentials.extractor.OAuth20CredentialsExtractor] - <sessionState: null / stateParameter: Optional[TST-1-v1va-S-4rLb45kax1568WxwP5aX-q2X]>
INFO [org.pac4j.oauth.client.Google2Client] - <Failed to retrieve or validate credentials: State parameter mismatch: session expired or possible threat of cross-site request forgery>
我可以在日志中看到两个keyloak / google都成功通过令牌进行的身份验证,这意味着keycloak / google原则上可以工作。问题似乎是,重定向回CAS之后,会话已经结束。上下文中的会话存储为空。因此,状态为null,无法与TST匹配。当我withState = false
在pac4j中进行设置时,一切正常,但是我想使用状态来提高安全性。
在pac4j google组中的这个问题中,有人遇到了同样的问题,因为他没有使用标准端口,我也这样做。但是更改为80/443并不能解决我的问题。我正在使用本地主机上具有自签名ssl证书的tomcat 9中运行。
还有其他建议吗?
编辑
我几乎可以肯定,问题来自外部tomcat。但是到目前为止,我还没有找到有关如何正确设置外部tomcat的有效文档。公开征求意见。
更新 Seams
就像cas-server-support-oauth-webflow
打破了pac4j Webflow一样。如果删除此依赖项,它将起作用。不知道这是一个错误还是应该以这种方式工作。没有OAuth-Webflow,我不会获得Ldap /数据库的access_token。
我有同样的问题,并设法用v6.2.0-RC2
cas版本处理它。添加后
cas.authn.pac4j.replicateSessions=false
对我etc/cas/config/cas.properties
来说,它解决了我的问题。
# cas.authn.pac4j.typedIdUsed=false
# cas.authn.pac4j.principalAttributeId=
# cas.authn.pac4j.name=
# cas.authn.pac4j.order=
# cas.authn.pac4j.lazyInit=true
# cas.authn.pac4j.replicateSessions=true
/**
* Indicates whether profiles and other session data,
* collected as part of pac4j flows and requests
* that are kept by the container session, should be replicated
* across the cluster using CAS and its own ticket registry.
* Without this option, profile data and other related
* pieces of information should be manually replicated
* via means and libraries outside of CAS.
*/
private boolean replicateSessions = true;
警告 - 对于群集,此属性的默认值为,不建议true
更改false
为。
作品,谢谢!