【发布时间】:2023-04-01 19:10:01
【问题描述】:
我使用带有代码授权类型的 Spring Security 的 OAuth2 客户端身份验证来进行匿名身份验证。
内置的OAuth2AuthorizationCodeGrantFilter 在匿名主体成功认证后进行重定向。
它重定向到通过存储在 RequestCache 中的请求获得的 URL,或使用从查询参数中剥离的默认 url (oauth2/code/{registrationId})。
OAuth2AuthorizationCodeGrantFilter 的代码有问题:
String redirectUrl = authorizationResponse.getRedirectUri();
SavedRequest savedRequest = this.requestCache.getRequest(request, response);
if (savedRequest != null) {
redirectUrl = savedRequest.getRedirectUrl();
this.requestCache.removeRequest(request, response);
}
this.redirectStrategy.sendRedirect(request, response, redirectUrl);
我可以利用请求缓存来存储重定向请求。但是RequestCache 的界面不允许我为重定向指定任意 URL,只能使用现有的(不可变的)HttpServletRequest。
我需要根据一些业务逻辑重定向到特定的 URL。如何强制使用任意重定向 URL?
【问题讨论】:
标签: spring-security spring-security-oauth2 http-redirect