Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.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 spring引导ldap组和受限制的终结点_Java_Rest_Spring Security_Spring Boot_Ldap - Fatal编程技术网

Java spring引导ldap组和受限制的终结点

Java spring引导ldap组和受限制的终结点,java,rest,spring-security,spring-boot,ldap,Java,Rest,Spring Security,Spring Boot,Ldap,我想限制某些rest端点仅用于特定组中的LDAP用户 我按照指南设置了LDAP身份验证,它工作得非常好。那么如何限制某些rest端点呢 我试过了 @PreAuthorize("hasRole('developers')") @RequestMapping("/foo") public String foo(HttpServletRequest request) { return "Welcome to FOO " + request.getRemoteUser(); } 但它仍然允许不

我想限制某些rest端点仅用于特定组中的LDAP用户

我按照指南设置了LDAP身份验证,它工作得非常好。那么如何限制某些rest端点呢

我试过了

@PreAuthorize("hasRole('developers')")
@RequestMapping("/foo")
public String foo(HttpServletRequest request) {
    return "Welcome to FOO " + request.getRemoteUser();
}

但它仍然允许不在开发人员组中的用户访问该端点

您可以将
WebSecurityConfigureAdapter
配置修改为类似以下内容:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .anyRequest().fullyAuthenticated()
            .and()
            .antMatchers("/foo").hasRole("developers")
            .and()
        .formLogin();
}
我不完全确定语法,也不确定第一条规则是否会覆盖第二条规则,但它将类似于第二条规则


或者,您可以尝试在方法基础上配置安全性,如

您可以将
websecurityConfigureAdapter
配置修改为以下内容:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .anyRequest().fullyAuthenticated()
            .and()
            .antMatchers("/foo").hasRole("developers")
            .and()
        .formLogin();
}
我不完全确定语法,也不确定第一条规则是否会覆盖第二条规则,但它将类似于第二条规则


或者,您可以尝试在方法基础上配置安全性,如

@EnableGlobalMethodSecurity(securedEnabled=true)
需要添加到WebSecurity配置中。一旦我这样做了,我就能够使用
@Secured(“ROLE\u DEVELOPERS”)
,然后该方法被限制在该角色上。

@EnableGlobalMethodSecurity(securedEnabled=true)
需要添加到WebSecurity配置中。一旦我这样做了,我就可以使用
@Secured(“ROLE\u DEVELOPERS”)
,然后该方法被限制为该角色。

不,它仍然允许所有用户访问/foo,如果您更改顺序,它似乎可以工作<代码>http.authorizeRequests().antMatchers(“/foo”).hasRole(“开发者”).antMatchers(“/**”).fullyAuthenticated()和().formLogin()和().httpBasic()否它仍然允许所有用户访问/foo,如果您更改排序,它似乎可以工作<代码>http.authorizeRequests().antMatchers(“/foo”).hasRole(“开发者”).antMatchers(“/**”).fullyAuthenticated()和().formLogin()和().httpBasic()