Java spring引导ldap组和受限制的终结点
我想限制某些rest端点仅用于特定组中的LDAP用户 我按照指南设置了LDAP身份验证,它工作得非常好。那么如何限制某些rest端点呢 我试过了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(); } 但它仍然允许不
@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()代码>