java - Spring Security 自定义登录页面不起作用
问题描述
我正在制作企业 webapp,我已经构建了我的自定义登录页面,但不知何故只有 spring 安全登录页面而不是我的自定义登录页面。下面是我的安全配置类。
请帮忙。
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth)
throws Exception {
auth.inMemoryAuthentication().withUser("test").password("pwd123")
.roles("USER", "ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login").permitAll()
.antMatchers("/", "/*todo*/**").access("hasRole('USER')").and()
.formLogin();
http.csrf().disable();
}
解决方案
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().antMatchers("/login").permitAll()
.anyRequest().authenticated().and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/home")
.failureUrl("/login?error=true")
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/login?logout=true")
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID")
.permitAll();
}
参考:https ://devkonline.com/tutorials/content/SPRING-SECURITY-5-CUSTOM-FORM-LOGIN-THYMELEAF
推荐阅读
- google-cloud-source-repos - Google Cloud 源代码库上的拉取请求
- javascript - 如何在使用 Promises 时将本地文件与 PapaParse 一起使用
- android - 为什么 JobService 没有重复?
- vue.js - 将 vuetify 与 i18n 和 eslint 插件一起使用
- parse-server - 通过 Parse-Server 命令行设置静态页面公共目录
- ios - 让我的 facebook 朋友在 iOS 应用程序中访问过的地方
- android - 在为电话状态注册广播接收器后,无法使用 action.call 拨打电话
- javascript - 即使通过 Node 调试器查看,ghost line 也不执行任何操作?
- javascript - NodeJS - LDAPJS 错误:events.js:160 throw er; // 未处理的“错误”事件
- sql - 计算线串上的点 a