- 1、Spring Security配置
- 2、登录页 login.html
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
UserServiceImpl userService;
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userService).passwordEncoder(passwordEncoder());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/authentication/form")
.permitAll()
.and()
.csrf().disable();
}
}
.loginPage():中的url是自己写的login.html页面
2、登录页 login.html这里的action与配置类的 .loginProcessingUrl必须对应
该接口不用自己写,Spring Security会自行完成登录验证。



