private boolean doHasAccess( Subject subject, List<? extends Authorizable> authorizables, Set<? extends Action> actions, ActiveRoleSet roleSet) { Set<String> groups = getGroups(subject); Set<String> hierarchy = new HashSet<String>(); for (Authorizable authorizable : authorizables) { hierarchy.add(KV_JOINER.join(authorizable.getTypeName(), authorizable.getName())); } List<String> requestPrivileges = buildPermissions(authorizables, actions); Iterable<Privilege> privileges = getPrivileges(groups, roleSet, authorizables.toArray(new Authorizable[0])); lastFailedPrivileges.get().clear(); for (String requestPrivilege : requestPrivileges) { for (Privilege permission : privileges) { /* * Does the permission granted in the policy file imply the requested action? */ boolean result = permission.implies(privilegeFactory.createPrivilege(requestPrivilege)); if (LOGGER.isDebugEnabled()) { LOGGER.debug( "ProviderPrivilege {}, RequestPrivilege {}, RoleSet, {}, Result {}", new Object[] {permission, requestPrivilege, roleSet, result}); } if (result) { return true; } } } lastFailedPrivileges.get().addAll(requestPrivileges); return false; }
private List<String> buildPermissions( List<? extends Authorizable> authorizables, Set<? extends Action> actions) { List<String> hierarchy = new ArrayList<String>(); List<String> requestedPermissions = new ArrayList<String>(); for (Authorizable authorizable : authorizables) { hierarchy.add(KV_JOINER.join(authorizable.getTypeName(), authorizable.getName())); } for (Action action : actions) { String requestPermission = AUTHORIZABLE_JOINER.join(hierarchy); requestPermission = AUTHORIZABLE_JOINER.join( requestPermission, KV_JOINER.join(PRIVILEGE_NAME, action.getValue())); requestedPermissions.add(requestPermission); } return requestedPermissions; }
@Test(expected = IllegalArgumentException.class) public void testEmptyPart() throws Exception { System.out.println( create(AUTHORIZABLE_JOINER.join(KV_JOINER.join("collection1", "coll1"), ""))); }
@Test(expected = IllegalArgumentException.class) public void testEmptyValue() throws Exception { System.out.println(create(KV_JOINER.join("", "coll1"))); }