Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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 如何将匹配器添加到HttpSecurity spring web secure_Java_Spring_Spring Security - Fatal编程技术网

Java 如何将匹配器添加到HttpSecurity spring web secure

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

我尝试实现spring安全性,但是我有很多角色和特权,然后我想将这些角色动态地添加到其他资源中。喜欢它:

@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。