2016-08-19 44 views
1

我想限制某些休息端點僅適用於特定組中的LDAP用戶。春季啓動ldap組和限制端點

我按照指南https://spring.io/guides/gs/authenticating-ldap/設置了完美工作的LDAP認證。那麼如何限制某些休息終點呢?

我試圖

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

,但它仍然可以讓用戶無法在端點上的開發組訪問

回答

0

@EnableGlobalMethodSecurity(securedEnabled=true)需要添加到webSecurityConfig。一旦我這樣做了,我就可以使用@Secured("ROLE_DEVELOPERS"),然後該方法僅限於該角色。

0

您可以通過修改WebSecurityConfigurerAdapter配置是這樣的:

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http 
     .authorizeRequests() 
      .anyRequest().fullyAuthenticated() 
      .and() 
      .antMatchers("/foo").hasRole("developers") 
      .and() 
     .formLogin(); 
} 

我不是完全確定語法,如果第一條規則會覆蓋你的第二條規則,但它會與此類似。

或者,您可以嘗試按方法基礎配置安全性方法,如this sample

+0

不允許它仍然允許所有用戶訪問/ foo – user971169

+0

如果您更改排序似乎工作。 ()。和()。formLogin()。和()。httpBasic().http://www.autodesk.com/downloads/details.asp );' – user971169