我有一個Spring Security的角色層次設置是這樣的:訪問Spring Security的角色層次結構編程方式
ROLE_ADMIN > ROLE_MANAGER
ROLE_MANAGER > ROLE_USER
ROLE_USER > ROLE_GUEST
我發現自己需要創建一個VetoableChangeListener,可以否決基於角色對PropertyChangeEvents(由於其中的一個愚蠢的傳統設計問題)。
因此,在我的vetoableChange()方法中,需要根據層次結構否決更改。例如,某個字段不能被定義層次結構中ROLE_MANAGER下面的任何角色所改變,因此如果ROLE_USER嘗試更改它,則會引發PropertyVetoException。
public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
String role = SecurityContextHolder.getContext().getAuthentication().getRoles().get(0);
String propertyName = evt.getPropertyName();
String requiredRole = getRequiredRole(propertyName);
// determine if the current role is equal to or greater than
// the required role, throw PropertyVetoException if not
}
任何人都可以協助嗎?