当前位置: 首页 > 知识库问答 >
问题:

错误“err_invalid_redirect”到表单登录

景正文
2023-03-14

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

@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个答案

凤晨朗
2023-03-14

在我头顶上,

  1. servlet容器未将请求标记为安全,并将HttpServletRequest.GetScheme设置为返回正确的值
  2. 另一个筛选器正在捕获请求
  3. 3。

您可以在筛选器链的早期插入一个筛选器,以便在请求进入时特别查看HttpServletRequest.getScheme值。这是Spring Security用于进行评估的方法。

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

工作配置可能如下所示:

@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
    }

}

我还创建了验证此配置的集成测试。

 类似资料:
  • 我目前正在创建一个Symfony3应用程序,我无法使我的登录表单工作;我遵循以下步骤: http://symfony.com/doc/current/cookbook/security/form_login_setup.html http://symfony.com/doc/current/cookbook/doctrine/registration_form.html 注册系统正在工作,但我无法

  • 我试图通过本教程实现简单的登录页面(我使用的是symfony 2.4): http://symfony.com/doc/current/book/security.html 登录页面很好。但当我提交表单时,我出现了以下错误: 我在网上搜索,什么都试过了。我的配置有什么问题? security.yml 路由.yml

  • 很好的一天。我正在尝试使用php和xampp创建一个登录表单来运行代码。我在phpMyAdmin中已经有一个数据库,我得到了这个错误 连接! 致命错误:未捕获错误:调用C:\xampp\htdocs\login\connection中未定义的函数mysql\u query()。php:34堆栈跟踪:#0{main}在C:\xampp\htdocs\login\connection中抛出。第34行的

  • 我是Symfony的新手,我正在尝试为我的应用程序创建一个access登录表单,但当我尝试登录时,它只会一次又一次地将我重定向到表单登录。在此之前,我使用了HTTP基本表单,它工作得很好,但现在我尝试使用登录表单,这是不可能的。 这是我的代码: 用户类(带教义): 安全Controller.php: Security.yml login.html.twig 有什么想法吗?谢谢

  • 问题内容: 我正在一个springMVC项目中,其中用户身份验证基于Spring安全性。 这个想法是要拥有一个移动(android)应用程序,以便能够将某种数据发送到后端。 因此,在开始开发android之前,我决定使用cURL模拟登录表单的情况。 我们网站上的登录表单如下: 我使用以下命令: 但是我将获得登录页面,换句话说,我无法根据模拟情况通过用户身份验证。 只需注意:对于每一个请求,spri

  • 编辑:我发现了一个类似的问题,专门针对Facebook的登录。我正在使用电子邮件认证,但问题/解决方案可能是相同的。 userinfo={nsunderlyingerror=0x14704d4b0{Error domain=firauthinternalerrordomain code=3“(null)”userinfo={firautherroruserinfoderializedrespons