【发布时间】:2021-04-24 01:16:36
【问题描述】:
我有一个 Spring Boot 应用程序,它使用来自 WSO2 Identity Server 的 OAuth2 身份验证。 当我在 Spring Tool Suit 上运行应用程序时,它可以工作,所以我可以唱歌并使用我的网站。 但是当我在 Tomcat(9.0) 上运行我的应用程序时,我尝试访问一个页面,并重定向到登录页面,当我尝试登录时,我收到错误 ERR_TOO_MANY_REDIRECTS
错误示例:当我的 Spring Boot 应用在 Tomcat 上运行时,我尝试访问 html 页面:https://domain/chat/example.html
如果用户未通过身份验证, 重定向到登录页面 WSO2 身份服务器: https://domain/is/authenticationendpoint/login.do
登录后页面重定向到下面的url,并没有重定向到url(https://domain/chat/example.html)
- https://domain/is/oauth2/authorize
- https://domain/chat/oauth2/authorization/wso2
- https://domain/chat/login/oauth2/code/wso2
- https://domain/chat/login
这些页面返回错误ERR_TOO_MANY_REDIRECTS。
用户可以进行身份验证,但应用程序重定向并进入导致错误的循环,该循环位于 url 1、2、3、4 之间。
Spring Boot 配置:
LoginController.java
@Controller
public class LoginController {
@GetMapping("/oauth-login")
public String getLoginPage(Model model) {
return "redirect:/oauth2/authorization/wso2";
}
}
ConfigSecurity.java
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)//abilitar seguranca nos metodos
public class ConfigSecurity extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/oauth-login")
.permitAll()
.anyRequest()
.authenticated()
.and()
.oauth2Login().loginPage("/oauth-login")
.and()
.logout().logoutUrl("/applogout");
}
}
application.properties
server.port=8443
spring.security.oauth2.client.registration.wso2.client-name=WSO2 Identity Server
spring.security.oauth2.client.registration.wso2.client-id=asdasd
spring.security.oauth2.client.registration.wso2.client-secret=asdasd
spring.security.oauth2.client.registration.wso2.redirect-uri=https://domain/chat/login/oauth2/code/wso2
spring.security.oauth2.client.registration.wso2.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.wso2.scope=openid
#Identity Server Properties
spring.security.oauth2.client.provider.wso2.authorization-uri=https://domain/is/oauth2/authorize
spring.security.oauth2.client.provider.wso2.token-uri=https://domain/is/oauth2/token
spring.security.oauth2.client.provider.wso2.user-info-uri=https://domain/is/oauth2/userinfo
spring.security.oauth2.client.provider.wso2.jwk-set-uri=https://domain/is/oauth2/jwks
这是我的 git:https://github.com/Mingato/Root2
当我运行 .jar 文件时它可以工作,但是当我在 tomcat 上运行 .war 文件时它不起作用。
【问题讨论】:
标签: java spring tomcat spring-security spring-security-oauth2