概要
授权安全管理器继承了授权器,拥有了授权的各种行为,又使用授权器具体实现授权的各种行为。
Authorizer授权器
package com.wjz.core; public interface Authorizer { boolean checkRole(String role); }
AuthorizingSecurityManager授权安全管理器
package com.wjz.core; public class AuthorizingSecurityManager implements Authorizer { private Authorizer authorizer; public AuthorizingSecurityManager() { authorizer = new ModularRealmAuthorizer(); } @Override public boolean checkRole(String role) { return authorizer.checkRole(role); } }
ModularRealmAuthorizer
package com.wjz.core; public class ModularRealmAuthorizer implements Authorizer { @Override public boolean checkRole(String role) { if ("admin".equals(role)) { return true; } return false; } }