2011-04-29 77 views
0

我在放置和方法級別具有網址級安全性。但是,一旦用戶在url級別進行了身份驗證,我的方法級安全性就會被繞過!我看着這個進一步,似乎以下網址級別的安全性:春季安全3:方法級別訪問失敗

intercept-url pattern="/**" access="ROLE_USER"

將覆蓋任何我的方法的安全級別(如下面的代碼片段)。

@PreAuthorize("hasRole('ROLE_SUPERVISOR')") 
public String supervisorRoleOnly() 
{ 
    return "success!!!" ; 
} 

我認爲這個方法會拋出一個訪問被拒絕的錯誤,但沒有,一旦他們在URL級別已完成認證的任何ROLE_USER可以訪問此方法。

我有這在我的security-config.xml

<global-method-security pre-post-annotations="enabled" > 
    <expression-handler ref="expressionHandler"/> 
</global-method-security> 

我缺少什麼?

回答

0

我想這更適用於未來的讀者,但是當你設置調試日誌記錄的Spring Security你看到類似以下內容:

Looking for Pre/Post annotations for method 'supervisorRoleOnly' on target class 'yourClassName' 
No expression annotations found 
Adding security method [CacheKey[yourClassName; public yourReturnType yourClassName.supervisorRoleOnly()]] with attributes [ROLE_USER] 

預授權很可能被忽略。