如何解决OKTA成功登录后,Spring Boot应用程序进入无限循环
我正在尝试将SSO集成到我的Spring Boot应用程序中。我尝试遵循https://developer.okta.com/blog/2017/03/16/spring-boot-saml中提到的教程,并创建了一个示例应用程序,并且一切正常,我被重定向到Okta登录页面。但是,当我尝试在应用程序中使用具有上下文路径的同一教程时,该应用程序导航到OKTA登录页面,但随后进入无限循环。
我的application.properties文件:
server.port = 9090
server.ssl.enabled = true
server.ssl.key-alias = spring
server.ssl.key-store = classpath:keystore.jks
server.ssl.key-store-password = secret
security.saml2.Metadata-url = https://XxxxxXXXXXXXX/sso/saml/Metadata
application.baseUrl = https://localhost:9090/my_app
security.saml2.context-provider.lb.context-path=/my_app
我的okta配置为:
Single sign-on URL: https://localhost:9090/**my_apP**/saml/SSO
Audience URI (SP Entity ID) : https://localhost:9090/**my_apP**/saml/Metadata
有人可以告诉我如何使用上下文路径进行配置吗?
2020-10-16 09:18:14.202 INFO 9372 --- [nio-9090-exec-9] o.s.security.saml.log.SAMLDefaultLogger : AuthNRequest;SUCCESS;0:0:0:0:0:0:0:1;https://localhost:9090/saml/Metadata;http://www.okta.com/xxxxxxxxxxxxxxxxxx;;;
2020-10-16 09:18:14.996 INFO 9372 --- [nio-9090-exec-1] o.s.security.saml.log.SAMLDefaultLogger : AuthNRequest;SUCCESS;0:0:0:0:0:0:0:1;https://localhost:9090/saml/Metadata;http://www.okta.com/xxxxxxxxxxxxxxxxxx;;;
2020-10-16 09:18:15.779 INFO 9372 --- [nio-9090-exec-6] o.s.security.saml.log.SAMLDefaultLogger : AuthNRequest;SUCCESS;0:0:0:0:0:0:0:1;https://localhost:9090/saml/Metadata;http://www.okta.com/xxxxxxxxxxxxxxxxxx;;;
2020-10-16 09:18:16.512 INFO 9372 --- [nio-9090-exec-8] o.s.security.saml.log.SAMLDefaultLogger : AuthNRequest;SUCCESS;0:0:0:0:0:0:0:1;https://localhost:9090/saml/Metadata;http://www.okta.com/xxxxxxxxxxxxxxxxxx;;;
2020-10-16 09:18:17.558 INFO 9372 --- [nio-9090-exec-3] o.s.security.saml.log.SAMLDefaultLogger : AuthNRequest;SUCCESS;0:0:0:0:0:0:0:1;https://localhost:9090/saml/Metadata;http://www.okta.com/xxxxxxxxxxxxxxxxxx;;;
解决方法
我通过在安全配置文件中添加以下行来解决此问题:
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/saml*").permitAll()
.anyRequest().authenticated()
.and()
.apply(saml())
.serviceProvider()
.keyStore()
.storeFilePath(this.keyStoreFilePath)
.password(this.password)
.keyname(this.keyAlias)
.keyPassword(this.password)
.and()
.protocol("https")
.hostname(String.format("%s:%s","localhost",this.port))
**.basePath("/my_app")**
.and()
.identityProvider()
.metadataFilePath(this.metadataUrl);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。