Spring Boot-如何配置多个登录页面

Spring Boot-如何配置多个登录页面,第1张

Spring Boot-如何配置多个登录页面

您应该能够通过使用不同的实例配置多个HttpSecurity对象来做到这一点的Spring
Security 文档。基本上,您可以在配置类中定义多个扩展WebSecurityConfigurerAdapter的静态类。我自己使用它来根据URLS配置不同类型的auth(表单/基本),并进行了快速测试以确认它。我相信您的示例中会出现以下情况(如果我正确阅读了您的意图):

@EnableWebSecuritypublic class MultiHttpSecurityConfig {    @Configuration    @Order(1)    public static class App1ConfigurationAdapter extends WebSecurityConfigurerAdapter {        protected void configure(HttpSecurity http) throws Exception { http         .authorizeRequests()         .antMatchers("/app1*.*")         .permitAll()         .antMatchers("/register.html")         .permitAll()         .anyRequest()         .authenticated()         // log in         .and()         .formLogin()         .loginPage("/login")         .failureUrl("/login?error=loginError")         .defaultSuccessUrl("/postLogin")      // logout         .and().logout().logoutUrl("logout")         .logoutSuccessUrl("/login").deletecookies("JSESSIONID").and()         .csrf()         .disable();        }    }    @Configuration    public static class App2ConfigurationAdapter extends WebSecurityConfigurerAdapter {        @Override        protected void configure(HttpSecurity http) throws Exception { http         .authorizeRequests()         .antMatchers("/app2logout")         .logoutSuccessUrl("/login2").deletecookies("JSESSIONID").and()         .csrf()         .disable();        }    }}

请注意,这些并不是真正不同的应用程序实例,因此,如果您以特定用户身份进行身份验证然后转到未授权的区域,则不会将您重定向到登录名。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5011976.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存