Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 即使我允许进入,也被禁止_Java_Spring Boot_Spring Security - Fatal编程技术网

Java 即使我允许进入,也被禁止

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

我使用SpringSecurity创建了一个项目

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();
}