Spring security 将.permitAll()方法替换为只能访问用户和COMP角色的方法

Spring security 将.permitAll()方法替换为只能访问用户和COMP角色的方法,spring-security,Spring Security,我想将.permitAll()方法替换为只能访问用户和COMP角色的方法 @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers("/success/**").permitAll() //instead of .permiitAll() I want to define access only for "USER" and "COMP

我想将.permitAll()方法替换为只能访问用户和COMP角色的方法

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/success/**").permitAll() //instead of .permiitAll() I want to define access only for "USER" and "COMP" roles
        .antMatchers("/userProfileHomePage/**").access("hasRole('USER')")
        .antMatchers("/companyHome/**").access("hasRole('COMP')")
        .and().formLogin().loginPage("/login")
        .failureUrl("/login?error").usernameParameter("userName").passwordParameter("password")
        .defaultSuccessUrl("/success").and().logout().logoutSuccessUrl("/login?logout").and().csrf()
        .disable().exceptionHandling().accessDeniedPage("/error");
}

你的问题是什么?预期结果与实际结果是什么?
.antMatchers(/success/**”).hasAnyRole(“用户”、“COMP”)
@Ritesh:当我使用:-.antMatchers(/success/**)时。hasAnyRole(“用户”、“COMP”)在控制台上收到成功URL的404错误消息:org.springframework.security.access.AccessDeniedException:access is denied是否可以检查(或共享代码)查看如何将角色分配给用户?您可能需要使用“ROLE\u USER”或“ROLE\u COMP”作为角色名称,或使用“hasAnyAuthority”而不是“hasAnyRole”。