gpt4 book ai didi

ssl - 错误 "ERR_INVALID_REDIRECT"到表单登录

转载 作者:太空宇宙 更新时间:2023-11-03 13:05:14 34 4
gpt4 key购买 nike

为什么给用户授权的时候会出现这个错误。一切都按照指示进行。

它不适用于 HTTPS。在 HTTP 中一切正常。

一切正常,除了登录表单....

@EnableWebSecurity公共(public)类 ConfigSecurity 扩展 WebSecurityConfigurerAdapter{

@Autowired private UserDetailsService userDetailsService;

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
//auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
auth.userDetailsService(userDetailsService).passwordEncoder(NoOpPasswordEncoder.getInstance());
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/accaunt/company/**").hasRole("COMPANY")
.antMatchers("/accaunt/resume/**").hasRole("WORKER")
.antMatchers("/accaunt/**").authenticated()
.anyRequest().permitAll()
.and()
/*
* установка второго параметра (alwaysUse) в false
* говорит Spring Security что в случае успешной
* авторизации можно перенаправить пользователя на
* ту страничку, с которой он пришел на страницу аутентификации.
*/
.formLogin()
.defaultSuccessUrl("/accaunt/main", true)
.loginPage("/login")
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/login")
.permitAll()
.and()
.csrf().disable()
.requiresChannel() //config request to use the mapping to a required channel
.anyRequest().requiresSecure();

//maps the port 8080(http) to 8443(https)
http.portMapper().http(8080).mapsTo(8181);

}

最佳答案

在我的头顶上,

  1. servlet 容器未将请求标记为安全并设置 HttpServletRequest.getScheme 以返回正确的值
  2. 另一个过滤器正在捕获请求
  3. 3.

您可以在过滤器链的早期插入一个过滤器,以在请求进入时专门检查 HttpServletRequest.getScheme 值。这是 Spring Security 用来进行评估的。

如果 Web 容器 (tomcat/jetty) 没有在 HttpServletRequest 上正确设置方案,那么这是一个容器配置问题。

我创建了一些示例供您试用我要你特别注意test这可能发生在你的情况下

git clone https://github.com/fhanik/spring-security-community.git
cd spring-security-community
./gradlew :spring-security-community-samples-requires-secure-with-redirect:bootRun

此示例中的测试显示了一个工作示例并省略了对 Web 服务器的依赖

工作配置可能如下所示:

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
//application security
.authorizeRequests()
.mvcMatchers("/non-secure/**").permitAll()
.anyRequest().hasRole("USER")
.and()
.formLogin()
.and()
.requiresChannel().anyRequest().requiresSecure()
.and()
.portMapper().http(8080).mapsTo(8081)
;
// @formatter:on
}

}

我还创建了 integration tests验证此配置。

关于ssl - 错误 "ERR_INVALID_REDIRECT"到表单登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54087163/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com