当前位置: 首页 > 知识库问答 >
问题:

Spring Oauth2。未重定向到OAuth/Authorize AuthorizationEndpoint

姬承教
2023-03-14

有一个重定向到登录页面,在输入凭据并提交表单后,身份验证在服务器上成功。

之后,我希望流继续授权,并转到irder中org.springframework.security.oauth2.provider.endpoint.authorizationendpoint中的oauth/authorizeendpoint,生成授权代码并将其发送回客户端应用程序。但事实并非如此。

请帮我说清楚为什么?为什么在succesfull身份验证之后,流不转到OAuth/Authorizeendpoint。

这是我的登录和点配置:

<security:http pattern="/mylogin"
               create-session="stateless"
               entry-point-ref="oauthAuthenticationEntryPoint">
    <security:intercept-url pattern="/mylogin" access="permitAll"/>
    <security:csrf disabled="true"/>
    <security:custom-filter before="PRE_AUTH_FILTER" ref="customAuthenticationFilter"/>
    <security:custom-filter ref="authRequestFilter" after="SECURITY_CONTEXT_FILTER" />
    <security:logout logout-url="/logout" />
    <security:anonymous />
    <security:expression-handler ref="oauthWebExpressionHandler" />
    <security:headers>
        <security:frame-options policy="DENY" />
    </security:headers>
</security:http>

这是我的自定义身份验证筛选器:

public class CustomAuthenticationFilter extends AbstractAuthenticationProcessingFilter {

private static Logger logger = LoggerFactory.getLogger(CustomAuthenticationFilter.class);

public CustomAuthenticationFilter() {
    super("/mylogin");
}

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
    if (!HttpMethod.POST.name().equals(request.getMethod())) {
        if(logger.isDebugEnabled()) {
            logger.debug("Authentication method not supported. Request method: " + request.getMethod());
        }
        throw new AuthenticationServiceException("Authentication method not supported");
    }
    String username = request.getParameter("j_username");
    String password = request.getParameter("j_password");
    if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
        throw new AuthenticationServiceException("Username or Password not provided");
    }
    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
    setDetails(request, authRequest);
    Authentication auth = this.getAuthenticationManager().authenticate(authRequest);
    return auth;
}

protected void setDetails(HttpServletRequest request,
                          UsernamePasswordAuthenticationToken authRequest) {
    authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
}
<oauth:authorization-server 
    client-details-service-ref="defaultOAuth2ClientDetailsEntityService"
    authorization-request-manager-ref="connectOAuth2RequestFactory" 
    token-services-ref="defaultOAuth2ProviderTokenService" 
    user-approval-handler-ref="tofuUserApprovalHandler" 
    request-validator-ref="oauthRequestValidator"
    redirect-resolver-ref="blacklistAwareRedirectResolver"
    authorization-endpoint-url="/authorize" 
    token-endpoint-url="/token"
    error-page="/error">

    <oauth:authorization-code authorization-code-services-ref="defaultOAuth2AuthorizationCodeService"/>
    <oauth:implicit />
    <oauth:refresh-token/>
    <oauth:client-credentials/>
    <oauth:password/>
    <oauth:custom-grant token-granter-ref="chainedTokenGranter" />
    <oauth:custom-grant token-granter-ref="jwtAssertionTokenGranter" />
    <oauth:custom-grant token-granter-ref="deviceTokenGranter" />

</oauth:authorization-server>

<bean id="oauthAccessDeniedHandler" class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler" />

共有1个答案

石喜
2023-03-14

我已经找到原因了。

create-session=“stateless”是未将身份验证保存在安全上下文中的原因。

这就是为什么在处理授权请求的阶段(在成功的身份验证之后),在FilterSecurityInterceptor中有一个访问被拒绝的异常。

 类似资料:
  • 我试图在我的spring应用程序中使用OAuth2。 下面是我的pom.xml 在 这里怎么了?我错过了什么?

  • 当我试图通过添加以下application.yml spring boot没有将我重定向到https://www.facebook.com/dialog/oauth,而是将我重定向到http://localhost:8080/login&显示localhost重定向您太多次错误,我做错了什么?为什么spring不将请求重定向到https://www.facebook.com/dialog/oaut

  • 我试图在Angular应用程序中调用我的登录服务,但我遇到了CORS错误。我已经在WebSecurity配置适配器上添加了cors配置。我已经尝试了下面的一些配置。邮递员一切都很好。 授权服务器配置RADAPTER 资源服务器配置RADAPTER Web安全配置r适配器

  • 我的Spring启动应用程序在从Okta服务器重定向后给我一个错误为404。请给我一些帮助来解决这个问题。我的配置如下。 这是我的Okta服务器重定向 https://dev-40483106.okta.com/oauth2/default/v1/authorize?响应类型=代码 这是我收到404错误的重定向URI http://localhost:8082/mms-sso/auth?code=

  • 问题内容: TextPanel.java FormPanel.java JumpHosts.java 因此,每当我单击任何按钮时,输出都将被重定向到仅一个文本区域,而其他似乎无法使用。即到最后创建的标签。我希望当我单击按钮1时,它应该写入选项卡1,而当我单击按钮2时,它应该写入选项卡2,依此类推。 我不熟悉Java的例子 问题答案: 在JumpHosts中: 您创建一个实例,该实例在程序中没有其他

  • 我在laravel中遇到了一个用户登录的问题,我可以正确地登录用户,但是问题是,在用户登录后,他被重定向到login POST方法,而不是home,我已经将