我已经使用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匹配。当我在pac4j中设置withState = false
时,一切正常,但是我想使用状态来保证安全性。
在此question in a pac4j google group中,有人遇到了同样的问题,因为他没有使用标准端口,而我也这样做。但是更改为80/443并不能解决我的问题。我正在使用本地主机上具有自签名ssl证书的tomcat 9中运行。
还有其他建议吗?
编辑我几乎可以肯定,问题来自外部tomcat。但是到目前为止,我还没有找到有关如何正确设置外部tomcat的有效文档。公开征求意见。
更新诸如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
。