spring-boot - 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);
}
推荐阅读
- java - 这两种代码风格的区别有名称吗?
- django - 如何解决 Django 中的相同 URL 模式冲突?
- c++ - 无法分配给返回值,因为函数 'operator->' 返回一个 const 值
- python - 断言 Scipy 单变量样条严格增加
- javascript - 拖放当前元素JS
- angular - 读取 URL 参数 - 以 # 开头
- html - 如何将两种不同字体大小的文本放在网页的中心?
- reactjs - 如何传入使用“this | that | other thing”语法定义的道具的值?
- linux - 跟踪用户写入目录
- python - 如何为切片的 3D numpy 数组的所有元素添加值?