UserSourceRealm extends AuthorizingRealm { @Override public void checkPermissions(PrincipalCollection subjectPrincipal, String... requiredPermissions) throws AuthorizationException { if (requiredPermissions.length > 0) { List<Permission> required = getPermissionResolver().resolvePermissions(requiredPermissions); checkPermissions(subjectPrincipal, required); } } UserSourceRealm(UserSource userSource); @Override boolean isAuthenticationCachingEnabled(); @Override boolean supports(AuthenticationToken token); @Override ShiroPermissionResolver getPermissionResolver(); @Override boolean isPermitted(PrincipalCollection subjectPrincipal, String requiredPermission); @Override boolean isPermitted(PrincipalCollection subjectPrincipal, Permission requiredPermission); @Override boolean isPermittedAll(PrincipalCollection subjectPrincipal, String... requiredPermissions); @Override boolean isPermittedAll(PrincipalCollection subjectPrincipal, Collection<Permission> requiredPermissions); @Override void checkPermission(PrincipalCollection subjectPrincipal, String requiredPermission); @Override void checkPermission(PrincipalCollection subjectPrincipal, Permission requiredPermission); @Override void checkPermissions(PrincipalCollection subjectPrincipal, String... requiredPermissions); @Override void checkPermissions(PrincipalCollection subjectPrincipal, Collection<Permission> requiredPermissions);  }
@Test public void testCheckPermissions_true() { final ShiroPermissionResolver resolver = new ShiroPermissionResolver(); UserSourceRealm realm = new UserSourceRealm(_userSource) { @Override protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) { SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); info.addObjectPermission(resolver.resolvePermission("Master:view")); info.addObjectPermission(resolver.resolvePermission("Source:view")); return info; } }; realm.setPermissionResolver(resolver); realm.checkPermissions(PRINCIPALS, "Master:view", "Source:view"); }
@Test(expectedExceptions = UnauthorizedException.class) public void testCheckPermissions_false() { final ShiroPermissionResolver resolver = new ShiroPermissionResolver(); UserSourceRealm realm = new UserSourceRealm(_userSource) { @Override protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) { SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); info.addObjectPermission(resolver.resolvePermission("Master:view")); info.addObjectPermission(resolver.resolvePermission("Source:view")); return info; } }; realm.setPermissionResolver(resolver); realm.checkPermissions(PRINCIPALS, "Master:view", "Source:edit"); }