只需要在配置类中继承WebSecurityConfigurerAdapter类,重写configure方法即可
.loginPage(“login.html”) // 登录页面设置
.loginProcessingUrl("/user/login") // 登录页面的访问路径
.defaultSuccessUrl("/index") // 权限认证成功(登录成功)后跳转的页面 .and().authorizeRequests() .antMatchers("/", “/index”, “/user/login”).permitAll() // 设置哪些路径可以直接访问,不需要认证
.anyRequest().authenticated()
.and().csrf().disable(); // 关闭CSRF防护
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin() // 自定义登录页面
.loginPage("login.html") // 登录页面设置
.loginProcessingUrl("/user/login") // 登录页面的访问路径
.defaultSuccessUrl("/index") // 权限认证成功(登录成功)后跳转的页面
.and().authorizeRequests()
.antMatchers("/", "/index", "/user/login").permitAll() // 设置哪些路径可以直接访问,不需要认证
.anyRequest().authenticated()
.and().csrf().disable(); // 关闭CSRF防护
}