Java 如何将匹配器添加到HttpSecurity spring web secure
我尝试实现spring安全性,但是我有很多角色和特权,然后我想将这些角色动态地添加到其他资源中。喜欢它:Java 如何将匹配器添加到HttpSecurity spring web secure,java,spring,spring-security,Java,Spring,Spring Security,我尝试实现spring安全性,但是我有很多角色和特权,然后我想将这些角色动态地添加到其他资源中。喜欢它: @Override protected void configure(HttpSecurity http) throws Exception { super.configure(http); //PageRequest p = new PageRequest(0, 1000); List<RolePrivilegeConfig> rolePrivil
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
//PageRequest p = new PageRequest(0, 1000);
List<RolePrivilegeConfig> rolePrivilegesConfig=rolePrivilegeConfigService.findAll();
for (RolePrivilegeConfig rolePrivilegeConfig : rolePrivilegesConfig) {
http.authorizeRequests()
.antMatchers("/login").permitAll()
.antMatchers(rolePrivilegeConfig.getResource())
.access(rolePrivilegeConfig.getRoleName())
.anyRequest().authenticated();
} }
@覆盖
受保护的无效配置(HttpSecurity http)引发异常{
super.configure(http);
//PageRequest p=新的PageRequest(0,1000);
List rolePrivilegesConfig=rolePrivilegeConfigService.findAll();
for(角色权限配置角色权限配置:角色权限配置){
http.authorizeRequests()
.antMatchers(“/login”).permitAll()
.antMatchers(rolePrivilegeConfig.getResource())
.access(rolePrivilegeConfig.getRoleName())
.anyRequest().authenticated();
} }
我有一个错误:
未能实例化[javax.servlet.Filter]:工厂方法
“springSecurityFilterChain”引发异常;嵌套异常是
java.lang.IllegalStateException:无法在
任何请求
如何将所有匹配器和调用请求放在后面?@Override
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
//PageRequest p = new PageRequest(0, 1000);
List<RolePrivilegeConfig> rolePrivilegesConfig=rolePrivilegeConfigService.findAll();
http.authorizeRequests()
.antMatchers("/login").permitAll();
for (RolePrivilegeConfig rolePrivilegeConfig : rolePrivilegesConfig) {
http.authorizeRequests()
.antMatchers(rolePrivilegeConfig.getResource())
.access(rolePrivilegeConfig.getRoleName());
}
http.authorizeRequests()
.anyRequest().authenticated();
}
受保护的无效配置(HttpSecurity http)引发异常{
super.configure(http);
//PageRequest p=新的PageRequest(0,1000);
List rolePrivilegesConfig=rolePrivilegeConfigService.findAll();
http.authorizeRequests()
.antMatchers(“/login”).permitAll();
for(角色权限配置角色权限配置:角色权限配置){
http.authorizeRequests()
.antMatchers(rolePrivilegeConfig.getResource())
.access(rolePrivilegeConfig.getRoleName());
}
http.authorizeRequests()
.anyRequest().authenticated();
}
只需在循环外部调用httpSecurity.authorizeRequests().anyRequest().authenticated()
即可。我得到:org.springframework.beans.beanInstationException:未能实例化[javax.servlet.Filter]:工厂方法“springSecurityFilterChain”引发异常;嵌套的异常是java.lang.IllegalStateException:无法配置任何请求。谢谢,它适合我,而且我在web.xml中没有springSecurityFilterChain。