我遇到了Spring Security的麻烦。我想从spring覆盖内置的/login
端点,以便能够加载位于resources/templates/mylogin.html
下的mylogin.html页面。我认为这个问题来自下面的代码。此外,该课程使用@EnableWebSecurity
进行注释。
我项目中的安全bean配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
//The pages does not require login
http.authorizeRequests().antMatchers("/","/welcome","logout").permitAll();
// /userInfo page requires login as ROLE_ADMIN, ROLE_DOCTOR, ROLE_PATIENT
http.authorizeRequests().antMatchers("/userInfo").access("hasAnyRole('ROLE_ADMIN','ROLE_DOCTOR','ROLE_PATIENT')");
//For ADMIN only
http.authorizeRequests().antMatchers("/admin").access("hasRole('ROLE_ADMIN')");
http.authorizeRequests().and().exceptionHandling().accessDeniedPage("/403");
//Config for Login Form
http.authorizeRequests().anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/mylogin.html")
.permitAll(true)
.and()
.logout()
.logoutSuccessUrl("/mylogin.html?logout")
.permitAll();code here
}
有人可以帮助我吗?
答案 0 :(得分:0)
我建议你使用spring-boot-starter-thymeleaf库。你可以做到
.loginPage("/login")
然后使用Spring Controller,您可以在方法中捕获/ login请求。在此方法中,返回“mylogin”会将用户重定向到mylogin.html页面。