@Override public int compare(AccessControlEntry o1, AccessControlEntry o2) { // compare role int compareTo = StringUtils.trimToEmpty(o1.getRole()).compareTo(StringUtils.trimToEmpty(o2.getRole())); if (compareTo != 0) return compareTo; // compare action compareTo = StringUtils.trimToEmpty(o1.getAction()).compareTo(StringUtils.trimToEmpty(o2.getAction())); if (compareTo != 0) return compareTo; // compare allow return Boolean.valueOf(o1.isAllow()).compareTo(o2.isAllow()); } };
JSONObject singleJsonEntry = new JSONObject(); jsonAcl.put(ACE, singleJsonEntry); singleJsonEntry.put(ACTION, singleEntry.getAction()); singleJsonEntry.put(ROLE, singleEntry.getRole()); singleJsonEntry.put(ALLOW, singleEntry.isAllow()); for (AccessControlEntry entry : entries) { JSONObject jsonEntry = new JSONObject(); jsonEntry.put(ACTION, entry.getAction()); jsonEntry.put(ROLE, entry.getRole()); jsonEntry.put(ALLOW, entry.isAllow());
/** * Reduces an access control list by an access control entry * * @param acl * the access control list to reduce * @param role * the role of the access control entry to remove * @param action * the action of the access control entry to remove * @return the reduced access control list or the same if already contained */ public static AccessControlList reduceAcl(AccessControlList acl, String role, String action) { AccessControlList newAcl = new AccessControlList(); for (AccessControlEntry ace : acl.getEntries()) { if (!ace.getAction().equalsIgnoreCase(action) || !ace.getRole().equalsIgnoreCase(role)) { newAcl.getEntries().add(ace); } } return newAcl; }
boolean foundAce = false; for (AccessControlEntry ace : acl.getEntries()) { if (ace.getAction().equalsIgnoreCase(action) && ace.getRole().equalsIgnoreCase(role)) { if (ace.isAllow() == allow) {
if (!action.toString().equals(entry.getAction())) continue;