Java 在permission-Spring security中获取另一个权限
我正在为我的项目使用Java 在permission-Spring security中获取另一个权限,java,spring,spring-boot,spring-security,Java,Spring,Spring Boot,Spring Security,我正在为我的项目使用Spring-security,这是我的配置 protected void configure(HttpSecurity http) throws Exception { http. authorizeRequests() .antMatchers("/home").hasRole("USER") .antM
Spring-security
,这是我的配置
protected void configure(HttpSecurity http) throws Exception {
http.
authorizeRequests()
.antMatchers("/home").hasRole("USER")
.antMatchers("/edit-information/**").hasRole("USER")
.antMatchers("/admin/**").hasAnyRole("ADMIN_STAFF","ADMIN_MANAGER")
.antMatchers("/admin/employee").hasRole("ADMIN_MANAGER")
.and()
.formLogin()
.loginPage("/home/login")
.loginProcessingUrl("/j_spring_security_check")
.usernameParameter("email")
.passwordParameter("password")
.defaultSuccessUrl("/",true)
.failureUrl("/home/login-fail")
.and()
.exceptionHandling()
.accessDeniedPage("/403");
}
这就是我的想法。我希望所有的管理员都可以登录到
/ADMIN/**
,但在/ADMIN/**
中,我有/ADMIN/employee
。我只想让角色管理者只能在这里登录。但是
.antMatchers(“/admin/**”).hasAnyRole(“admin\u STAFF”,“admin\u MANAGER”)
已经允许管理员员工登录到/admin/employee
。我试图添加.antMatchers(“/admin/employee”).hasRole(“admin\u MANAGER”)
,但没有成功 我确信问题在于antMatchers
的订购。规则的顺序很重要,更具体的规则应该放在第一位,因此,与此相反:
.antMatchers(“/admin/**”).hasAnyRole(“管理员员工”、“管理员经理”)
.antMatchers(“/admin/employee”).hasRole(“管理员/员工”)
您可以尝试以下方法:
.antMatchers(“/admin/employee”).hasRole(“管理员/经理”)
.antMatchers(“/admin/**”).hasAnyRole(“管理员员工”、“管理员经理”)
我确信问题在于蚂蚁匹配器的订购。规则的顺序很重要,更具体的规则应该放在第一位,因此,与此相反:
.antMatchers(“/admin/**”).hasAnyRole(“管理员员工”、“管理员经理”)
.antMatchers(“/admin/employee”).hasRole(“管理员/员工”)
您可以尝试以下方法:
.antMatchers(“/admin/employee”).hasRole(“管理员/经理”)
.antMatchers(“/admin/**”).hasAnyRole(“管理员员工”、“管理员经理”)