Java 即使我允许进入,也被禁止
我使用SpringSecurity创建了一个项目 在Java 即使我允许进入,也被禁止,java,spring-boot,spring-security,Java,Spring Boot,Spring Security,我使用SpringSecurity创建了一个项目 在configure(HttpSecurity http)中,我仅为用户设置了对“/home”的访问权限,但在我登录后,它显示: 403禁止 我创建了一个名为User implementing UserDetails的实体类,并在getAuthorities()中重新运行了Arrays.asList(新的SimpleGrantedAuthority(“用户”) 对于http对象,我尝试直接使用.hasRole('USER')方法而不是.acce
configure(HttpSecurity http)
中,我仅为用户设置了对“/home”
的访问权限,但在我登录后,它显示:
403禁止
我创建了一个名为User implementing UserDetails的
实体类,并在getAuthorities()
中重新运行了Arrays.asList(新的SimpleGrantedAuthority(“用户”)代码>
对于http对象,我尝试直接使用.hasRole('USER')
方法而不是.access(“hasRole('USER')”)
,问题也是一样的
@Override
protected void configure(HttpSecurity http) throws Exception{
http
.authorizeRequests()
.antMatchers("/home")
.access("hasRole('USER')")
.antMatchers("/","/**").access("permitAll")
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.httpBasic();
}
您需要使用权限,而不是角色
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/home").hasAuthority("USER")
.antMatchers("/","/**").access("permitAll")
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.httpBasic();
}