Java Spring Security OAuth2跳舞并获取参数
在Java Spring应用程序中,我通过外部OAuth2提供程序实现了OAuth2用户授权 在我的本地主机上,为了通过这个外部OAuth2提供程序对用户进行身份验证,我需要通过以下url:在OAuth2舞蹈之后,我可以对这个用户进行身份验证。到目前为止一切正常 但当我的登录url中有一些请求参数时,例如uid和级别: 在OAuth2舞蹈之后,我被重定向到并丢失了这些参数 在我的Chrome网络面板中,我可以看到以下一组呼叫: 因此,在第3步之后,我将丢失这些参数 是否可以配置Spring Security+OAuth2将这些参数也传递到步骤4 这是我的配置(这是一个基于此答案的解决方案),但它不起作用(Java Spring Security OAuth2跳舞并获取参数,java,spring,spring-security,spring-boot,spring-security-oauth2,Java,Spring,Spring Security,Spring Boot,Spring Security Oauth2,在Java Spring应用程序中,我通过外部OAuth2提供程序实现了OAuth2用户授权 在我的本地主机上,为了通过这个外部OAuth2提供程序对用户进行身份验证,我需要通过以下url:在OAuth2舞蹈之后,我可以对这个用户进行身份验证。到目前为止一切正常 但当我的登录url中有一些请求参数时,例如uid和级别: 在OAuth2舞蹈之后,我被重定向到并丢失了这些参数 在我的Chrome网络面板中,我可以看到以下一组呼叫: 因此,在第3步之后,我将丢失这些参数 是否可以配置Spri
AuthenticationProcessingFilterEntryPoint.Comment方法
未被调用):
有什么问题吗?我通过以下方式实现了这一点:
private Filter ssoFilter(ClientResources client, String path) {
OAuth2ClientAuthenticationProcessingFilter clientFilter = new OAuth2ClientAuthenticationProcessingFilter(path);
.......
clientFilter.setAuthenticationSuccessHandler(new UrlParameterAuthenticationHandler());
return clientFilter;
}
public class UrlParameterAuthenticationHandler extends SimpleUrlAuthenticationSuccessHandler {
@Override
protected void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
String targetUrl = determineTargetUrl(request, response);
if (response.isCommitted()) {
logger.debug("Response has already been committed. Unable to redirect to " + targetUrl);
return;
}
String queryString = HttpUtils.removeParams(request.getQueryString(), "state", "code");
targetUrl = !StringUtils.isEmpty(queryString) ? targetUrl + "?" + queryString : targetUrl;
getRedirectStrategy().sendRedirect(request, response, targetUrl);
}
}
当我的登录url中有GET参数时,如果有更好的方法
,请更正。。。我不太清楚。你能详细说明一下吗?你说的是http GET方法还是其他什么?我说的是这个url-https://127.0.0.1:8443/login/ok?uid=45134132&level=3
在GET parameters下,我的意思是url的这一部分-uid=45134132&level=3
步骤4是可疑的。在我看来,它不应该在那里。我想当执行/login/ok?level=…&uid=…
时,您的应用程序可能出现了问题。代码的某些部分可能会引发异常,异常处理程序会将您重定向到/
。总结一下我的印象:这个问题可能与您的安全配置没有直接关系。@ben75,谢谢您的回答。请看下面的代码。。它正在工作。。但我不确定我是否以正确的方式实施了它。
private Filter ssoFilter(ClientResources client, String path) {
OAuth2ClientAuthenticationProcessingFilter clientFilter = new OAuth2ClientAuthenticationProcessingFilter(path);
.......
clientFilter.setAuthenticationSuccessHandler(new UrlParameterAuthenticationHandler());
return clientFilter;
}
public class UrlParameterAuthenticationHandler extends SimpleUrlAuthenticationSuccessHandler {
@Override
protected void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
String targetUrl = determineTargetUrl(request, response);
if (response.isCommitted()) {
logger.debug("Response has already been committed. Unable to redirect to " + targetUrl);
return;
}
String queryString = HttpUtils.removeParams(request.getQueryString(), "state", "code");
targetUrl = !StringUtils.isEmpty(queryString) ? targetUrl + "?" + queryString : targetUrl;
getRedirectStrategy().sendRedirect(request, response, targetUrl);
}
}