private void populateMap(ImmutableMap.Builder<String, Boolean> values, String prefix, Node currentNode) { if (currentNode.value != Tristate.UNDEFINED) { values.put(prefix, currentNode.value.asBoolean()); } for (Map.Entry<String, Node> ent : currentNode.children.entrySet()) { populateMap(values, prefix + '.' + ent.getKey(), ent.getValue()); } }
/** * Test whether the subject is permitted to perform an action corresponding * to the given permission string. * * <p>This must return the same boolean equivalent as * {@link #getPermissionValue(Set, String)}.</p> * * @param contexts The set of contexts that represents the subject's current * environment * @param permission The permission string * @return True if permission is granted */ default boolean hasPermission(Set<Context> contexts, String permission) { return getPermissionValue(contexts, permission).asBoolean(); }
@Override public CompletableFuture<Boolean> setPermission(Set<Context> contexts, String permission, Tristate value) { contexts = ImmutableSet.copyOf(contexts); while (true) { NodeTree oldTree = this.permissions.get(contexts); if (oldTree != null && oldTree.get(permission) == value) { return CompletableFuture.completedFuture(false); } if (oldTree == null && value != Tristate.UNDEFINED) { if (this.permissions.putIfAbsent(contexts, NodeTree.of(ImmutableMap.of(permission, value.asBoolean()))) == null) { break; } } else { if (oldTree == null || this.permissions.replace(contexts, oldTree, oldTree.withValue(permission, value))) { break; } } } return CompletableFuture.completedFuture(true); }
@Override public boolean hasPermission(Set<Context> contexts, String permission) { return getPermissionValue(contexts, permission).asBoolean(); }
private void populateMap(ImmutableMap.Builder<String, Boolean> values, String prefix, Node currentNode) { if (currentNode.value != Tristate.UNDEFINED) { values.put(prefix, currentNode.value.asBoolean()); } for (Map.Entry<String, Node> ent : currentNode.children.entrySet()) { populateMap(values, prefix + '.' + ent.getKey(), ent.getValue()); } }
/** * Test whether the subject is permitted to perform an action corresponding to the * given permission string. This must return the same boolean equivalent as * {@link #getPermissionValue(Set, String)}. * * @param contexts The set of contexts that represents the subject's current environment * @param permission The permission string * @return True if permission is granted */ default boolean hasPermission(Set<Context> contexts, String permission) { return getPermissionValue(contexts, permission).asBoolean(); }
@Override public Map<Subject, Boolean> getAllWithPermission(Set<Context> contexts, String permission) { final ImmutableMap.Builder<Subject, Boolean> ret = ImmutableMap.builder(); for (PEXSubject subject : subjectCache.asMap().values()) { Tristate permissionValue = subject.getPermissionValue(contexts == null ? subject.getActiveContexts() : contexts, permission); if (permissionValue != Tristate.UNDEFINED) { ret.put(subject, permissionValue.asBoolean()); } } return ret.build(); }
@Override public boolean setPermission(Set<Context> contexts, String permission, Tristate value) { contexts = ImmutableSet.copyOf(contexts); while (true) { NodeTree oldTree = this.permissions.get(contexts); if (oldTree != null && oldTree.get(permission) == value) { return false; } if (oldTree == null && value != Tristate.UNDEFINED) { if (this.permissions.putIfAbsent(contexts, NodeTree.of(ImmutableMap.of(permission, value.asBoolean()))) == null) { break; } } else { if (oldTree == null || this.permissions.replace(contexts, oldTree, oldTree.withValue(permission, value))) { break; } } } return true; }