栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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();        }    }}

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



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/497112.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号