Oauth 2.0 未找到Spring security OAuth重定向终结点

Oauth 2.0 未找到Spring security OAuth重定向终结点,oauth-2.0,spring-security-oauth2,java-ee-7,Oauth 2.0,Spring Security Oauth2,Java Ee 7,我已将Spring安全性添加到现有JEE应用程序中,以将OAuth添加到应用程序中。 安全配置被设置为保护RESTAPI,这一部分似乎工作正常。 当UI请求受保护的URL时,响应包含重定向到“oauth2/authorize/keydrope” 但这就是故事的结尾,因为对“oauth2/authorize/keydrope”的请求本身返回404 我对spring security已经非常过时了(上次在spring应用程序中使用它大约是在8年前),我不知道应该在哪里找到端点“oauth2/auth

我已将Spring安全性添加到现有JEE应用程序中,以将OAuth添加到应用程序中。 安全配置被设置为保护RESTAPI,这一部分似乎工作正常。 当UI请求受保护的URL时,响应包含重定向到“oauth2/authorize/keydrope”

但这就是故事的结尾,因为对“oauth2/authorize/keydrope”的请求本身返回404

我对spring security已经非常过时了(上次在spring应用程序中使用它大约是在8年前),我不知道应该在哪里找到端点“oauth2/authorize/keydove”的实现,以便找出我的设置中缺少或错误的地方

我的依赖关系树的相关部分如下所示:

[INFO] |  +- com.mycompany.auth:authentication-sso-configuration:jar:1.0.0-SNAPSHOT:compile
[INFO] |  |  +- org.reactivestreams:reactive-streams:jar:1.0.3:compile
[INFO] |  |  +- org.springframework.security:spring-security-oauth2-client:jar:5.3.3.RELEASE:compile
[INFO] |  |  |  +- com.nimbusds:oauth2-oidc-sdk:jar:7.5:compile
[INFO] |  |  |  |  +- com.github.stephenc.jcip:jcip-annotations:jar:1.0-1:compile
[INFO] |  |  |  |  +- com.nimbusds:content-type:jar:2.0:compile
[INFO] |  |  |  |  +- net.minidev:json-smart:jar:2.3:compile (version selected from constraint [1.3.1,2.3])
[INFO] |  |  |  |  |  \- net.minidev:accessors-smart:jar:1.2:compile
[INFO] |  |  |  |  |     \- org.ow2.asm:asm:jar:5.0.4:compile
[INFO] |  |  |  |  \- com.nimbusds:lang-tag:jar:1.4.4:compile
[INFO] |  |  |  +- org.springframework.security:spring-security-oauth2-core:jar:5.3.3.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-core:jar:5.2.6.RELEASE:compile
[INFO] |  |  |     \- org.springframework:spring-jcl:jar:5.2.6.RELEASE:compile
[INFO] |  |  +- org.springframework.security:spring-security-oauth2-jose:jar:5.3.3.RELEASE:compile
[INFO] |  |  |  \- com.nimbusds:nimbus-jose-jwt:jar:8.18.1:compile
[INFO] |  |  +- org.springframework.security:spring-security-oauth2-resource-server:jar:5.3.3.RELEASE:compile
[INFO] |  |  +- org.springframework.security:spring-security-core:jar:5.3.3.RELEASE:compile
[INFO] |  |  |  +- org.springframework:spring-aop:jar:5.2.6.RELEASE:compile
[INFO] |  |  |  +- org.springframework:spring-beans:jar:5.2.6.RELEASE:compile
[INFO] |  |  |  +- org.springframework:spring-context:jar:5.2.6.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-expression:jar:5.2.6.RELEASE:compile
[INFO] |  |  +- org.springframework.security:spring-security-web:jar:5.3.3.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-web:jar:5.2.6.RELEASE:compile
[INFO] |  |  +- org.springframework.security:spring-security-config:jar:5.3.3.RELEASE:compile
[INFO] |  |  +- org.springframework.security:spring-security-saml2-service-provider:jar:5.3.3.RELEASE:compile
[INFO] |  |  |  +- org.opensaml:opensaml-core:jar:3.4.5:compile
[INFO] |  |  |  |  +- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile
[INFO] |  |  |  |  \- net.shibboleth.utilities:java-support:jar:7.5.1:compile
[INFO] |  |  |  +- org.opensaml:opensaml-saml-api:jar:3.4.5:compile
[INFO] |  |  |  |  +- org.opensaml:opensaml-xmlsec-api:jar:3.4.5:compile
[INFO] |  |  |  |  |  \- org.opensaml:opensaml-security-api:jar:3.4.5:compile
[INFO] |  |  |  |  +- org.opensaml:opensaml-soap-api:jar:3.4.5:compile
[INFO] |  |  |  |  +- org.opensaml:opensaml-messaging-api:jar:3.4.5:compile
[INFO] |  |  |  |  +- org.opensaml:opensaml-profile-api:jar:3.4.5:compile
[INFO] |  |  |  |  \- org.opensaml:opensaml-storage-api:jar:3.4.5:compile
[INFO] |  |  |  \- org.opensaml:opensaml-saml-impl:jar:3.4.5:compile
[INFO] |  |  |     +- org.opensaml:opensaml-security-impl:jar:3.4.5:compile
[INFO] |  |  |     +- org.opensaml:opensaml-xmlsec-impl:jar:3.4.5:compile
[INFO] |  |  |     |  \- org.apache.santuario:xmlsec:jar:2.0.10:compile
[INFO] |  |  |     |     \- com.fasterxml.woodstox:woodstox-core:jar:5.0.3:compile
[INFO] |  |  |     |        \- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[INFO] |  |  |     +- org.opensaml:opensaml-soap-impl:jar:3.4.5:compile
[INFO] |  |  |     \- org.apache.velocity:velocity:jar:1.7:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-api:jar:2.13.3:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-core:jar:2.13.3:compile
[INFO] |  |  +- org.yaml:snakeyaml:jar:1.26:compile
[INFO] |  |  +- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] |  |  +- org.bouncycastle:bcprov-jdk15on:jar:1.66:compile
[INFO] |  |  +- org.cryptacular:cryptacular:jar:1.2.4:compile
[INFO] |  |  \- org.apache.commons:commons-configuration2:jar:2.7:compile
[INFO] |  |     \- org.apache.commons:commons-text:jar:1.8:compile
这是OAuth的配置

# OAuth2 login manifest
oauth2Login:
  authorizationCode:
    authorizationUri: "http://localhost:8180/auth/realms/master/protocol/openid-connect/auth"
    scope:
      - "openid"
      - "finx"
    redirectUriTemplate: "{baseUrl}/login/oauth2/code/{registrationId}"
    tokenUri: "http://localhost:8180/auth/realms/master/protocol/openid-connect/token"
    userInfoUri: "http://localhost:8180/auth/realms/master/protocol/openid-connect/userinfo"
    jwkSetKeyUri: "http://localhost:8180/auth/realms/master/protocol/openid-connect/certs"
    registrationId: "keycloak"
    clientId: "finx_oauth2"
    clientSecret:
      vaultType: PLAIN_TEXT
      secret: "my-secret"
    clientName: "FinX"
    entryPoints:
      - pathMatcher: "/ledger-api/**"
      - pathMatcher: "/ledger-api-internal/**"
      - pathMatcher: "/ledger-api-ui/**"
# OAuth2 resource server
oauth2ResourceServer:
  keySetUri: "http://localhost:8180/auth/realms/master/protocol/openid-connect/certs"
  pathMatchers:
    - "/api/**"
    - "/orchestration-api/**"
为了找到端点“oauth2/authorize/keydrope”的实现,我一直在深入研究spring源代码,但这不是一项容易的任务


因此,希望有人能帮助我指出我的配置中可能缺少/错误的地方。

默认情况下,OAuth 2.0登录页面由
DefaultLoginPageGeneratingFilter
自动生成
客户端的登录页面默认为:
OAuth2AuthorizationRequestRedirectFilter.DEFAULT\u AUTHORIZATION\u REQUEST\u BASE\u URI+“/{registrationId}”
。根据您的配置,
registrationId:“keydape”
,这意味着(
/oauth2/authorization/keydape

请检查您的
网站安全配置适配器
配置。通过配置oauth2Login().loginPage()和(可选)oauth2Login().authorizationEndpoint().baseUri()尝试覆盖默认登录页

下面的列表显示了一个示例:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .oauth2Login()
            .loginPage("/login/oauth2")
            ...
            .authorizationEndpoint()
                .baseUri("/login/oauth2/authorization")
                ....
}

请查看更多信息。

谢谢你,维杰。这就是我要找的信息。似乎问题出在我的配置上。将以下内容添加到“oauth2Login.authorizationCode.entryPoints”中会产生一个技巧-pathMatcher:“/oauth2/**”anonymous:true-pathMatcher:“/login/**”anonymous:true-pathMatcher:“/logout/**”anonymous:truely奇怪,因为如果这是问题,如果问题是由于路径“/oauth2/**”受到保护,我更希望出现某种无休止的循环或堆栈溢出错误,而不是404。