我刚刚经历了同样的问题。为了让它工作,我让 Wicket 重定向到 CAS,然后 CasAuthenticationFilter 验证令牌并处理身份验证。我不知道这是否是最好的解决方案,但我使用 RequestMapper 来处理 AuthenticatedWebSession 登录。
Spring 安全配置
<!-- https://cwiki.apache.org/WICKET/spring-security-and-wicket-auth-roles.html -->
<http use-expressions="true" auto-config="true" entry-point-ref="casEntryPoint">
<intercept-url pattern="/**" />
<custom-filter ref="casFilter" position="CAS_FILTER"/>
</http>
在 AuthenticatedApplication 中覆盖 restartResponseAtSignInPage
/**
* Stores original Url and redirects to CAS login for authentication. CAS will redirect back to this
* service using the service parameter.
*/
@Override
public void restartResponseAtSignInPage() {
Session.get().setAttribute("originalUrl", RequestCycle.get().getRequest().getOriginalUrl());
// This will be the URL back to the Spring CAS filter
String service = "service=https%3A%2F%2F" + casServiceHost + "%2Fapp%2Flogin";
throw new RedirectToUrlException("https://" + casServerHost + "/cas/login?" + service);
}
制作一个 IRequestMapper 来处理 AuthenticatedWebSession 登录和重定向。
@Override
public IRequestHandler mapRequest(Request request) {
logger.info("CasAuthMapper mapping {}", request.getUrl());
// The authentication will have been handled by Spring's CasAuthenticationFilter
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
// ... Do whatever you need to do here. I added a simple method to my web session to delegate to signIn(boolean).