檢查Spring Security 3.0,您可以通過使用Spring表達式語言來避免使用ACL。
例如,對於編輯一個論壇,你會確保這樣的方法:
@PreAuthorize("hasRole('ROLE_FORUM_MANAGER') and hasPermission(#forum,'update'))
public void updateForum(Forum forum) {
//some implementation
}
你可以這樣實現自定義權限評估調用hasPermission方法,如:
public class ForumPermissionEvaluator implements PermissionEvaluator {
public boolean hasPermission(Authentication authentication,
Object domainObject, Object permission) {
//implement
}
public boolean hasPermission(Authentication authentication,
Serializable targetId, String targetType, Object permission) {
//implement
}
}
最後,在應用程序配置中將它們連接在一起:
<beans:bean id="expressionHandler"
class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
<beans:property name="permissionEvaluator" ref="permissionEvaluator"/>
</beans:bean>
<beans:bean id="permissionEvaluator"
class="com.centrix.core.security.GroupPermissionEvaluator" />
是的,我以前見過它,但是因爲spring security 3不是正式版本,所以我不會使用它,但是我想我會稍微等一下使用它。 – 2009-12-22 16:40:42
要使用諸如「#forum」之類的方法參數來執行此操作,必須將調試信息留在生產JAR中....可能不是一個好主意。 – HDave 2010-06-01 01:54:41
在bean連線中,最後一個元素應該是「ForumPermissionEvaluator」而不是「GroupPermissionEvaluator」?另一個問題:如果你想擁有多個PermissionEvaluator,那麼這將如何連接,因爲只有一個expressionHandler? – 2011-05-25 00:15:50