Spring Boot:OAuth终结点重定向到8443

编程入门 行业动态 更新时间:2024-10-21 05:36:26
本文介绍了Spring Boot:OAuth终结点重定向到8443的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在端口8080上有一个Web应用程序,它只使用SSL(不允许使用http)运行:

server: ssl: key-store-type: PKCS12 key-store: file:${SERVER_KEYSTORE_PATH} key-store-password: ${SERVER_CERT_PASSWORD} port: 8080

当我启动应用程序时,我在日志中看到:

2020-03-17 17:32:29.836 INFO 90960 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (https)

我的一个终结点(实际上是根终结点)受Spring Security OAuth2:

保护 @Override protected void configure(HttpSecurity http) throws Exception { String baseURI = redirectURI.substring(redirectURI.lastIndexOf("/")); http.csrf().disable() .authorizeRequests() .antMatchers("/").authenticated() .antMatchers("/**").permitAll() .and() .oauth2Login() .defaultSuccessUrl("/") .redirectionEndpoint().baseUri(baseURI); } 问题是,当我转到localhost:8080时,它会将我重定向到localhost:8443/oauth2/authorization/oauth,因此,出于某种原因,端口8080被8443覆盖。

根据我对类似问题的理解,这是因为Tomcat试图将用户从普通端点(Http)重定向到启用了SSL的端点(HTTPS)。但是我的端点已经启用了SSL,所以我真的不明白为什么会发生这种情况。如果我转到任何其他端点,它都可以使用HTTPS和8080端口--所以只有受保护的端点才有问题。

我尝试使用ConnectorCustomizers自定义TomcatServletWebServerFactory并将那里的重定向端口设置为8080,但无济于事。

有关如何禁用此无用重定向的建议?

推荐答案

根据github/spring-projects/spring-security/issues/8140#issuecomment-600980028:

@Override protected void configure(HttpSecurity http) throws Exception { PortMapperImpl portMapper = new PortMapperImpl(); portMapper.setPortMappings(Collections.singletonMap("8080","8080")); PortResolverImpl portResolver = new PortResolverImpl(); portResolver.setPortMapper(portMapper); LoginUrlAuthenticationEntryPoint entryPoint = new LoginUrlAuthenticationEntryPoint( "/login"); entryPoint.setPortMapper(portMapper); entryPoint.setPortResolver(portResolver); http .exceptionHandling() .authenticationEntryPoint(entryPoint) .and() //... ; }

更多推荐

Spring Boot:OAuth终结点重定向到8443

本文发布于:2023-11-14 10:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586917.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   Boot   Spring   OAuth

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!