public Enumeration<Permission> elements() { final Enumeration<Permission> e1 = pc1.elements(); final Enumeration<Permission> e2 = pc2.elements(); return new Enumeration<Permission>() { public boolean hasMoreElements() { return e1.hasMoreElements() || e2.hasMoreElements(); } public Permission nextElement() { return e1.hasMoreElements() ? e1.nextElement() : e2.nextElement(); } }; }
/** * Create an iterable view over a permission collection. * * @param pc the permission collection (must not be {@code null}) * @return the iterable view (not {@code null}) */ public static Iterable<Permission> iterable(PermissionCollection pc) { return () -> { final Enumeration<Permission> elements = pc.elements(); return new Iterator<Permission>() { public boolean hasNext() { return elements.hasMoreElements(); } public Permission next() { return elements.nextElement(); } }; }; }
@Override public Enumeration<Permission> elements() { return delegate.getPermissions(domain).elements(); } };
private Set<String> filterRoles(HttpServletRequest request, PermissionCollection permissionCollection) { Set<String> roles = new HashSet<>(); for (Permission permission : list(permissionCollection.elements())) { if (permission instanceof WebRoleRefPermission) { String role = permission.getActions(); // Note that the WebRoleRefPermission is given for every Servlet in the application, even when // no role refs are used anywhere. This will also include Servlets like the default servlet and the // implicit JSP servlet. So if there are 2 application roles, and 3 application servlets, then // at least 6 WebRoleRefPermission elements will be present in the collection. if (!roles.contains(role) && request.isUserInRole(role)) { roles.add(role); } } } return roles; }
@Override public void addToExcludedPolicy(PermissionCollection permissions) throws PolicyContextException { checkNotNullParam("permissions", permissions); Enumeration<Permission> elements = permissions.elements(); while (elements.hasMoreElements()) { addToExcludedPolicy(elements.nextElement()); } }
@Override public void addToUncheckedPolicy(PermissionCollection permissions) throws PolicyContextException { checkNotNullParam("permissions", permissions); Enumeration<Permission> elements = permissions.elements(); while (elements.hasMoreElements()) { addToUncheckedPolicy(elements.nextElement()); } }
/** * Perform an action for each permission in the given collection. * * @param collection the collection (must not be {@code null}) * @param consumer the consumer to which each permission should be passed (must not be {@code null}) */ public static void forEachIn(PermissionCollection collection, Consumer<Permission> consumer) { Assert.checkNotNullParam("collection", collection); Assert.checkNotNullParam("consumer", consumer); final Enumeration<Permission> elements = collection.elements(); while (elements.hasMoreElements()) { consumer.accept(elements.nextElement()); } }
/** * Perform an action for each permission in the given collection. * * @param collection the collection (must not be {@code null}) * @param parameter the parameter to pass to the consumer * @param consumer the consumer to which each permission should be passed (must not be {@code null}) * @param <P> the type of the parameter * @return the {@code parameter} that was passed in */ public static <P> P forEachIn(PermissionCollection collection, BiConsumer<P, Permission> consumer, P parameter) { Assert.checkNotNullParam("collection", collection); Assert.checkNotNullParam("consumer", consumer); final Enumeration<Permission> elements = collection.elements(); while (elements.hasMoreElements()) { consumer.accept(parameter, elements.nextElement()); } return parameter; }
/** * Run a test for each permission in the given collection. If the predicate returns {@code false} for any element, * {@code false} is returned; otherwise, {@code true} is returned. * * @param collection the collection (must not be {@code null}) * @param predicate the predicate to apply to each element (must not be {@code null}) * @return {@code true} if the predicate matched all the permissions in the collection, {@code false} otherwise */ public static boolean forEachIn(PermissionCollection collection, Predicate<Permission> predicate) { Assert.checkNotNullParam("collection", collection); Assert.checkNotNullParam("predicate", predicate); final Enumeration<Permission> elements = collection.elements(); while (elements.hasMoreElements()) { if (! predicate.test(elements.nextElement())) { return false; } } return true; }
@Override public void addToRole(String roleName, PermissionCollection permissions) throws PolicyContextException { checkNotNullParam("roleName", roleName); checkNotNullParam("permissions", permissions); Enumeration<Permission> elements = permissions.elements(); while (elements.hasMoreElements()) { addToRole(roleName, elements.nextElement()); } }
/** * Run a test for each permission in the given collection. If the predicate returns {@code false} for any element, * {@code false} is returned; otherwise, {@code true} is returned. * * @param collection the collection (must not be {@code null}) * @param parameter the parameter to pass to the consumer * @param predicate the predicate to apply to each element (must not be {@code null}) * @param <P> the type of the parameter * @return {@code true} if the predicate matched all the permissions in the collection, {@code false} otherwise */ public static <P> boolean forEachIn(PermissionCollection collection, BiPredicate<P, Permission> predicate, P parameter) { Assert.checkNotNullParam("collection", collection); Assert.checkNotNullParam("predicate", predicate); final Enumeration<Permission> elements = collection.elements(); while (elements.hasMoreElements()) { if (! predicate.test(parameter, elements.nextElement())) { return false; } } return true; }
protected PermissionCollection getPermissions(CodeSource codeSource) { PermissionCollection perms; try { try { perms = super.getPermissions(codeSource); } catch (SecurityException e) { // We lied about our CodeSource and that makes URLClassLoader unhappy. perms = new Permissions(); } ProtectionDomain myDomain = AccessController.doPrivileged(new PrivilegedAction<ProtectionDomain>() { public ProtectionDomain run() { return getClass().getProtectionDomain(); } }); PermissionCollection myPerms = myDomain.getPermissions(); if (myPerms != null) { for (Enumeration<Permission> elements = myPerms.elements(); elements.hasMoreElements();) { perms.add(elements.nextElement()); } } } catch (Throwable e) { // We lied about our CodeSource and that makes URLClassLoader unhappy. perms = new Permissions(); } perms.setReadOnly(); return perms; }
@Override public Enumeration<Permission> elements() { return impl.elements(); } };
List<Permission> permList = Collections.list(pc.elements()); if (permList.size() == 1) { permsKey = permList.get(0);
for (Permission permission : Collections.list(permissions.elements())) { if (!emptyPolicy.implies(PluginSecurity.class.getProtectionDomain(), permission)) { actualPermissions.add(permission); return Collections.list(actualPermissions.elements()).stream().map(PluginSecurity::formatPermission).collect(Collectors.toSet());
public Enumeration<Permission> elements() { final Enumeration<Permission> e1 = pc1.elements(); final Enumeration<Permission> e2 = pc2.elements(); return new Enumeration<Permission>() { public boolean hasMoreElements() { return e1.hasMoreElements() || e2.hasMoreElements(); } public Permission nextElement() { return e1.hasMoreElements() ? e1.nextElement() : e2.nextElement(); } }; }
public void addToRole(final String roleName, final PermissionCollection permissions) throws PolicyContextException { if (state != OPEN) { throw new UnsupportedOperationException("Not in an open state"); } final Enumeration e = permissions.elements(); while (e.hasMoreElements()) { addToRole(roleName, (Permission) e.nextElement()); } }
private AuthorizationResult authorize(PermissionCollection userPermissions, PermissionCollection requiredPermissions) { final Enumeration<Permission> enumeration = requiredPermissions.elements(); while (enumeration.hasMoreElements()){ Permission requiredPermission = enumeration.nextElement(); if (!userPermissions.implies(requiredPermission)) { return new AuthorizationResult(AuthorizationResult.Decision.DENY, new ModelNode(ControllerLogger.ROOT_LOGGER.permissionDenied())); } } return AuthorizationResult.PERMITTED; }
@Override public void addToRole(String roleName, PermissionCollection permissions) throws PolicyContextException { checkNotNullParam("roleName", roleName); checkNotNullParam("permissions", permissions); Enumeration<Permission> elements = permissions.elements(); while (elements.hasMoreElements()) { addToRole(roleName, elements.nextElement()); } }
private static PermissionCollection copyPermissions(PermissionCollection permissionCollection) { final Permissions permissions = new Permissions(); final Enumeration<Permission> elements = permissionCollection.elements(); while (elements.hasMoreElements()) { permissions.add(elements.nextElement()); } permissions.setReadOnly(); return permissions; }