UserSourceRealm extends AuthorizingRealm { @Override public boolean isPermittedAll(PrincipalCollection subjectPrincipal, String... requiredPermissions) { if (requiredPermissions.length == 0) { return true; } List<Permission> required = getPermissionResolver().resolvePermissions(requiredPermissions); return isPermittedAll(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 testIsPermittedAll_none() { 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); assertEquals(true, realm.isPermittedAll(PRINCIPALS)); }
@Test public void testIsPermittedAll_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); assertEquals(true, realm.isPermittedAll(PRINCIPALS, "Master:view", "Source:view")); }
@Test public void testIsPermittedAll_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); assertEquals(false, realm.isPermittedAll(PRINCIPALS, "Master:view", "Source:edit")); }