找不到Spring安全性OAuth重定向终结点



我已经将Spring Security添加到现有的JEE应用程序中,以便将OAuth添加到该应用程序中。安全配置被设置为保护RESTneneneba API,并且该部分似乎工作正常。当UI请求受保护的URL时,响应包含重定向到"oauth2/authorize/keycloft"。

但故事到此结束,因为对"oauth2/authorize/keycloft"的请求本身返回404。

我对spring安全性已经很过时了(大约8年前,我最后一次在spring应用程序中使用它(,我不知道应该在哪里找到端点"oauth2/authorize/keycloft"的实现,以找出我的设置中缺少或错误的地方。

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

[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/**"

我一直在挖掘spring源代码,以找到端点"oauth2/authorize/keycloft"的实现,但这不是一项容易的任务。

因此,寻找一个可以帮助我指出我的配置中可能缺失/错误的人。

默认情况下,OAuth 2.0登录页面由DefaultLoginPageGeneratingFilter自动生成
客户端的登录页面默认为:OAuth2AuthorizationRequestRedirectFilter.DEFAULT_AUTHORIZATION_REQUEST_BASE_URI + "/{registrationId}"。根据您的配置,registrationId: "keycloak",这意味着(/oauth2/authorization/keycloak(。

请检查您的WebSecurityConfigurerAdapter配置。尝试通过配置oauth2Login((.loginPage((和(可选(oauth2Login((.authorizationEndpoint((.baseUri((.来覆盖默认登录页

以下列表显示了一个示例:

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

请检查OAuth 2.0登录-有关详细信息,请参阅高级配置。

最新更新