Search in sources :

Example 71 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrAccessControlUtil method clearHierarchyPermissions.

public static boolean clearHierarchyPermissions(Node node, Node toNode) {
    try {
        Node current = node;
        Node rootNode = toNode.getSession().getRootNode();
        boolean removed = false;
        while (!current.equals(toNode) && !current.equals(rootNode)) {
            removed |= clearPermissions(current);
            current = current.getParent();
        }
        if (current.equals(rootNode) && !toNode.equals(rootNode)) {
            throw new IllegalArgumentException("clearHierarchyPermissions: The \"toNode\" argument is not in the \"node\" argument's hierarchy: " + toNode);
        } else {
            removed |= clearPermissions(current);
        }
        return removed;
    } catch (AccessDeniedException e) {
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to add permission(s) to hierarch from node " + node + " up to " + toNode, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Example 72 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrAccessControlUtil method removeAllPermissions.

public static boolean removeAllPermissions(Session session, String path, Principal principal) {
    try {
        AccessControlManager acm = session.getAccessControlManager();
        AccessControlPolicy[] aclArray = acm.getPolicies(path);
        // Never remove permissions for "admin".
        if (aclArray.length > 0 && !principal.getName().equals(ModeShapeRoles.ADMIN)) {
            AccessControlList acl = (AccessControlList) aclArray[0];
            boolean removed = removeEntry(acl, principal);
            acm.setPolicy(path, acl);
            return removed;
        } else {
            return false;
        }
    } catch (AccessDeniedException e) {
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to remove all permission(s) from node " + path, e);
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessDeniedException(javax.jcr.AccessDeniedException) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Example 73 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrAccessControlUtil method getAllPrivileges.

public static Map<Principal, Set<Privilege>> getAllPrivileges(Session session, String path) {
    try {
        Map<Principal, Set<Privilege>> map = new HashMap<>();
        AccessControlManager acm = session.getAccessControlManager();
        AccessControlList acl = getAccessControlList(path, acm);
        for (AccessControlEntry entry : acl.getAccessControlEntries()) {
            Principal principal = derivePrincipal(entry);
            map.put(principal, new HashSet<>(Arrays.asList(entry.getPrivileges())));
        }
        return map;
    } catch (AccessDeniedException e) {
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to get the privileges for node " + path, e);
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) AccessControlEntry(javax.jcr.security.AccessControlEntry) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) GroupPrincipal(com.thinkbiganalytics.security.GroupPrincipal) UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) Principal(java.security.Principal) SimplePrincipal(org.modeshape.jcr.security.SimplePrincipal)

Example 74 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrAccessControlUtil method removePermissions.

public static boolean removePermissions(Session session, String path, Principal principal, Privilege... removes) {
    try {
        // There should always be an ACL entry for "admin".
        if (removes.length > 0 && !principal.getName().equals(ModeShapeRoles.ADMIN)) {
            AccessControlManager acm = session.getAccessControlManager();
            AccessControlPolicy[] aclArray = acm.getPolicies(path);
            if (aclArray.length > 0) {
                AccessControlList acl = (AccessControlList) aclArray[0];
                boolean removed = false;
                for (AccessControlEntry entry : acl.getAccessControlEntries()) {
                    if (matchesPrincipal(principal, entry)) {
                        Privilege[] newPrivs = Arrays.stream(entry.getPrivileges()).filter(p -> !Arrays.stream(removes).anyMatch(r -> r.equals(p))).toArray(Privilege[]::new);
                        if (entry.getPrivileges().length != newPrivs.length) {
                            acl.removeAccessControlEntry(entry);
                            if (newPrivs.length != 0) {
                                acl.addAccessControlEntry(entry.getPrincipal(), newPrivs);
                            }
                            removed = true;
                        }
                    }
                }
                acm.setPolicy(path, acl);
                return removed;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } catch (AccessDeniedException e) {
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to remove permission(s) from node " + path + ": " + Arrays.toString(removes), e);
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) Arrays(java.util.Arrays) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AccessControlEntry(javax.jcr.security.AccessControlEntry) HashMap(java.util.HashMap) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) ModeShapeRoles(org.modeshape.jcr.ModeShapeRoles) Deque(java.util.Deque) GroupPrincipal(com.thinkbiganalytics.security.GroupPrincipal) AccessDeniedException(javax.jcr.AccessDeniedException) HashSet(java.util.HashSet) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) Node(javax.jcr.Node) Map(java.util.Map) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) AccessControlList(javax.jcr.security.AccessControlList) UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) Session(javax.jcr.Session) Collection(java.util.Collection) Set(java.util.Set) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Principal(java.security.Principal) SimplePrincipal(org.modeshape.jcr.security.SimplePrincipal) Group(java.security.acl.Group) AccessControlException(java.security.AccessControlException) Optional(java.util.Optional) AccessControlManager(javax.jcr.security.AccessControlManager) JcrUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrUtil) Authentication(org.springframework.security.core.Authentication) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) Privilege(javax.jcr.security.Privilege) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessDeniedException(javax.jcr.AccessDeniedException) AccessControlEntry(javax.jcr.security.AccessControlEntry) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Privilege(javax.jcr.security.Privilege)

Example 75 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrActionsGroupBuilder method module.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.security.action.config.ActionsModuleBuilder#group(java.lang.String)
     */
@Override
public ActionsTreeBuilder<ActionsModuleBuilder> module(String name) {
    Session session = JcrMetadataAccess.getActiveSession();
    try {
        Node securityNode = session.getRootNode().getNode(SecurityPaths.SECURITY.toString());
        this.groupsNode = this.groupsNode == null || !this.groupsNode.getSession().isLive() ? session.getRootNode().getNode(this.protoModulesPath) : this.groupsNode;
        this.protoActionsNode = JcrUtil.getOrCreateNode(groupsNode, name, JcrAllowedActions.NODE_TYPE);
        return new JcrActionTreeBuilder<>(protoActionsNode, this);
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to access root node for allowable actions", e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Aggregations

MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)83 RepositoryException (javax.jcr.RepositoryException)79 Node (javax.jcr.Node)54 AccessDeniedException (javax.jcr.AccessDeniedException)29 AccessControlException (java.security.AccessControlException)28 Session (javax.jcr.Session)25 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)12 NodeIterator (javax.jcr.NodeIterator)12 Nonnull (javax.annotation.Nonnull)10 Value (javax.jcr.Value)10 Map (java.util.Map)9 Property (javax.jcr.Property)8 ItemNotFoundException (javax.jcr.ItemNotFoundException)7 QueryResult (javax.jcr.query.QueryResult)7 JcrObject (com.thinkbiganalytics.metadata.modeshape.common.JcrObject)6 AccessControlManager (javax.jcr.security.AccessControlManager)6 UserFieldDescriptor (com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor)5 List (java.util.List)5