具有多个登录页面的Spring Security仅接受订单1

gmpx:

我有一个Spring Boot应用程序,其中登录页面将位于index(nav)以及登录页面。我做了订单注释配置,但是它只能按预期的顺序运行1(通过切换订单进行测试,订单1只能正常运行)对于订单2错误:请求方法'POST'不支持,有什么想法吗?

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Qualifier("userDetailsServiceImpl")
    @Autowired
    private UserDetailsService userDetailsService;

    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }


    @Configuration
    @Order(1)
    public static class WebSecurityConfig1 extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.requestMatcher(new AntPathRequestMatcher("/**"))
                    .authorizeRequests()
                    .antMatchers("/resources/**", "/registration", "/**").permitAll()
                    .anyRequest().authenticated()
                    .and()
                    .formLogin()
                    .loginPage("/loginIndex")
                    .usernameParameter("username")
                    .passwordParameter("password")
                    .failureUrl("/loginIndex?error")
                    .loginProcessingUrl("/loginIndex")
                    .permitAll()
                    .and()
                    .logout()
                    .permitAll();
        }
    }
    @Configuration
    @Order(2)
    public static class WebSecurityConfig2 extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.requestMatcher(new AntPathRequestMatcher("/**"))
                    .authorizeRequests()
                    .antMatchers("/resources/**", "/registration","/**").permitAll()
                    .anyRequest().authenticated()
                    .and()
                    .formLogin()
                    .loginPage("/login")
                    .usernameParameter("username")
                    .passwordParameter("password")
                    .failureUrl("/login?error")
                    .loginProcessingUrl("/login")
                    .permitAll()
                    .and()
                    .logout()
                    .permitAll();
        }
    }

    @Bean
    public AuthenticationManager customAuthenticationManager() throws Exception {
        return authenticationManager();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
    }
Kavithakaran Kanapathippillai:

在您的配置中发出

  1. WebSecurityConfig1并且WebSecurityConfig2都配置为匹配每个网址。.ienew AntPathRequestMatcher("/**")
  2. 这意味着@Order(1)将始终满足所有要求。

因此,首先,您需要确定要将用户重定向到哪个URL,以及将用户重定向到第二登录页面。

例如,您可以说带有的网址/user转到,loginPage("/loginIndex")而其他所有内容都转到loginPage("/login")您可以通过在WebSecurityConfig1 new AntPathRequestMatcher("/**")中用(new AntPathRequestMatcher("/user*")代替来实现

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Spring Security 4中,如何配置一个具有多个登录页面的登录页面,这些登录页面会截取不同的URL模式

Metabox具有WooCommerce管理订单页面的多个自定义字段

Spring Security没有用于登录页面的控制器

具有多个页面的Android Wear Smartwatch通知-小图标仅显示在第一页上吗?

Spring Security 3.1.4具有表单登录名的多个http元素

Spring Security登录页面

如何使用python请求登录具有多个页面的CAS?

Spring Security登录页面-图像

在Spring Boot应用程序中为多个登录页面配置Spring Security

仅具有“注册”页面的Azure AD B2C自定义策略

成功登录后,Spring Security有时会重定向到默认页面而不是登录前页面

仅传输具有匹配订单标题的订单行

具有Spring Security的Spring Boot在有效登录时返回404

带有spring-boot的spring-security,自定义登录页面,错误403

在Spring Security中具有多个http节的NoUniqueBeanDefinitionException

将JSF登录页面与Spring Security集成

Spring security - 无法进入登录页面

仅重定向带有子页面的父页面

Spring Security登录始终落在没有消息的错误页面中

为什么我的自定义登录页面没有显示在Spring Security 4中?

带有JWT的Spring Security OAuth2重定向到登录页面

从具有多个页面的网站抓取数据

如何使用scrapy抓取具有多个页面的网站

如何解析具有多个页面的XML结果

创建具有多个页面的Apex表单

具有多个页面的简单PHP测验的结构

具有多个页面的子报表中断分页

python 抓取具有多个页面的站点

如何仅使用 Java 在 vaadin 中创建 spring security 登录页面?