@Test public void testCreateAccountOverride() { AuthorizingRealm realm = new AllowAllRealm() { @Override protected AuthenticationInfo buildAuthenticationInfo(Object principal, Object credentials) { String username = (String) principal; UsernamePrincipal customPrincipal = new UsernamePrincipal(username); return new SimpleAccount(customPrincipal, credentials, getName()); } }; AuthenticationInfo info = realm.getAuthenticationInfo(new UsernamePasswordToken(USERNAME, PASSWORD, localhost)); assertNotNull(info); assertTrue(realm.hasRole(info.getPrincipals(), ROLE)); Object principal = info.getPrincipals().getPrimaryPrincipal(); assertTrue(principal instanceof UsernamePrincipal); assertEquals(USERNAME, ((UsernamePrincipal) principal).getUsername()); }
public boolean hasRole(PrincipalCollection principal, String roleIdentifier) { AuthorizationInfo info = getAuthorizationInfo(principal); return hasRole(roleIdentifier, info); }
AuthorizingRealm extends AuthenticatingRealm implements Authorizer, Initializable, PermissionResolverAware, RolePermissionResolverAware { public boolean hasRole(PrincipalCollection principal, String roleIdentifier) { AuthorizationInfo info = getAuthorizationInfo(principal); return hasRole(roleIdentifier, info); } }
AuthorizingRealm extends AuthenticatingRealm implements Authorizer, Initializable, PermissionResolverAware, RolePermissionResolverAware { public boolean hasRole(PrincipalCollection principal, String roleIdentifier) { AuthorizationInfo info = getAuthorizationInfo(principal); return hasRole(roleIdentifier, info); } AuthorizingRealm();  AuthorizingRealm(CacheManager cacheManager);  AuthorizingRealm(CredentialsMatcher matcher);  AuthorizingRealm(CacheManager cacheManager, CredentialsMatcher matcher); }
AuthorizingRealm extends AuthenticatingRealm implements Authorizer, Initializable, PermissionResolverAware, RolePermissionResolverAware { public boolean hasRole(PrincipalCollection principal, String roleIdentifier) { AuthorizationInfo info = getAuthorizationInfo(principal); return hasRole(roleIdentifier, info); } AuthorizingRealm();  AuthorizingRealm(CacheManager cacheManager);  AuthorizingRealm(CredentialsMatcher matcher);  AuthorizingRealm(CacheManager cacheManager, CredentialsMatcher matcher); void setName(String name); void setAuthorizationCache(Cache<Object, AuthorizationInfo> authorizationCache); Cache<Object, AuthorizationInfo> getAuthorizationCache(); String getAuthorizationCacheName(); @SuppressWarnings({"UnusedDeclaration"}) void setAuthorizationCacheName(String authorizationCacheName); boolean isAuthorizationCachingEnabled(); @SuppressWarnings({"UnusedDeclaration"}) void setAuthorizationCachingEnabled(boolean authenticationCachingEnabled); PermissionResolver getPermissionResolver(); void setPermissionResolver(PermissionResolver permissionResolver); RolePermissionResolver getRolePermissionResolver(); void setRolePermissionResolver(RolePermissionResolver permissionRoleResolver); boolean isPermitted(PrincipalCollection principals, String permission); boolean isPermitted(PrincipalCollection principals, Permission permission); boolean[] isPermitted(PrincipalCollection subjectIdentifier, String... permissions); boolean[] isPermitted(PrincipalCollection principals, List<Permission> permissions); boolean isPermittedAll(PrincipalCollection subjectIdentifier, String... permissions); boolean isPermittedAll(PrincipalCollection principal, Collection<Permission> permissions); void checkPermission(PrincipalCollection subjectIdentifier, String permission); void checkPermission(PrincipalCollection principal, Permission permission); void checkPermissions(PrincipalCollection subjectIdentifier, String... permissions); void checkPermissions(PrincipalCollection principal, Collection<Permission> permissions); boolean hasRole(PrincipalCollection principal, String roleIdentifier); boolean[] hasRoles(PrincipalCollection principal, List<String> roleIdentifiers); boolean hasAllRoles(PrincipalCollection principal, Collection<String> roleIdentifiers); void checkRole(PrincipalCollection principal, String role); void checkRoles(PrincipalCollection principal, Collection<String> roles); void checkRoles(PrincipalCollection principal, String... roles); }
AuthorizingRealm extends AuthenticatingRealm implements Authorizer, Initializable, PermissionResolverAware, RolePermissionResolverAware { public boolean hasRole(PrincipalCollection principal, String roleIdentifier) { AuthorizationInfo info = getAuthorizationInfo(principal); return hasRole(roleIdentifier, info); } AuthorizingRealm();  AuthorizingRealm(CacheManager cacheManager);  AuthorizingRealm(CredentialsMatcher matcher);  AuthorizingRealm(CacheManager cacheManager, CredentialsMatcher matcher); void setName(String name); void setAuthorizationCache(Cache<Object, AuthorizationInfo> authorizationCache); Cache<Object, AuthorizationInfo> getAuthorizationCache(); String getAuthorizationCacheName(); @SuppressWarnings({"UnusedDeclaration"}) void setAuthorizationCacheName(String authorizationCacheName); boolean isAuthorizationCachingEnabled(); @SuppressWarnings({"UnusedDeclaration"}) void setAuthorizationCachingEnabled(boolean authenticationCachingEnabled); PermissionResolver getPermissionResolver(); void setPermissionResolver(PermissionResolver permissionResolver); RolePermissionResolver getRolePermissionResolver(); void setRolePermissionResolver(RolePermissionResolver permissionRoleResolver); boolean isPermitted(PrincipalCollection principals, String permission); boolean isPermitted(PrincipalCollection principals, Permission permission); boolean[] isPermitted(PrincipalCollection subjectIdentifier, String... permissions); boolean[] isPermitted(PrincipalCollection principals, List<Permission> permissions); boolean isPermittedAll(PrincipalCollection subjectIdentifier, String... permissions); boolean isPermittedAll(PrincipalCollection principal, Collection<Permission> permissions); void checkPermission(PrincipalCollection subjectIdentifier, String permission); void checkPermission(PrincipalCollection principal, Permission permission); void checkPermissions(PrincipalCollection subjectIdentifier, String... permissions); void checkPermissions(PrincipalCollection principal, Collection<Permission> permissions); boolean hasRole(PrincipalCollection principal, String roleIdentifier); boolean[] hasRoles(PrincipalCollection principal, List<String> roleIdentifiers); boolean hasAllRoles(PrincipalCollection principal, Collection<String> roleIdentifiers); void checkRole(PrincipalCollection principal, String role); void checkRoles(PrincipalCollection principal, Collection<String> roles); void checkRoles(PrincipalCollection principal, String... roles);  }