我已经开始学习Spring Security,并希望使用方法级别的安全性。
我有简单的控制器
@Controller
public class AppController {
@GetMapping("/")
@PermitAll
public String welcomePage() {
return "index";
}
@GetMapping("/user")
@RolesAllowed({Role.USER,Role.ADMIN})
public String userPage() {
return "user";
}
}
安全配置:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(jsr250Enabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin().permitAll()
.and()
.anonymous()
.and()
.authorizeRequests().anyRequest().authenticated();
}
@Override
public void configure(AuthenticationmanagerBuilder builder)
throws Exception {
builder.inmemoryAuthentication()
.withUser("user").password("user").roles("USER")
.and()
.withUser("admin").password("admin").roles("ADMIN");
}
}
问题索引页需要使用此配置登录,但我设置了@PermitAll。
您能帮忙吗