2014-12-03 41 views
0

我下面這個github project熟悉自己使用Spring Security。我已經啓動並運行了該項目。我對OAuth2ServerConfiguration.java文件進行了小小的修改,嘗試訪問控制器並驗證其他所有內容。我不知道是否有可能與2條規則或不能做到這一點,這裏是有問題的代碼:以上Spring Security的4 - 允許訪問控制和鑑定拍賣品

@Override 
    public void configure(HttpSecurity http) throws Exception { 
     // @formatter:off 
     http 
      .authorizeRequests() 
      .antMatchers("/homecontroller").permitAll() 
      .antMatchers("/greeting").authenticated(); 
     // @formatter:on 
    } 

的代碼工作正常,當我改變"/greeting"/**,一切都需要驗證。

回答

0

一個老問題,但因爲比我花了不少時間去熟悉Spring安全(我不是專家...)。

在Spring Security,你可以在同一configure()方法多HttpSecurity配置。請務必記住,antMatchers和規則的順序很重要。 Spring Security會找到第一場比賽並從那裏開始,它不會通過剩下的比賽來確定哪個是最好的。