Search in sources :

Example 31 with MetadataRepositoryException

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

the class JcrAccessControlUtil method removeHierarchyAllPermissions.

public static boolean removeHierarchyAllPermissions(Node node, Principal principal, Node toNode) {
    try {
        Node current = node;
        Node rootNode = toNode.getSession().getRootNode();
        boolean removed = false;
        while (!current.equals(toNode) && !current.equals(rootNode)) {
            removed |= removeAllPermissions(node.getSession(), current.getPath(), principal);
            current = current.getParent();
        }
        if (current.equals(rootNode) && !toNode.equals(rootNode)) {
            throw new IllegalArgumentException("removeHierarchyAllPermissions: The \"toNode\" argument is not in the \"node\" argument's hierarchy: " + toNode);
        } else {
            removed |= removeAllPermissions(node.getSession(), current.getPath(), principal);
        }
        return removed;
    } catch (AccessDeniedException e) {
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to remove all permission(s) from 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 32 with MetadataRepositoryException

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

the class JcrAccessControlUtil method getPrivileges.

public static Set<Privilege> getPrivileges(Session session, Principal principal, String path) {
    try {
        AccessControlManager acm = session.getAccessControlManager();
        AccessControlList acl = getAccessControlList(path, acm);
        for (AccessControlEntry entry : acl.getAccessControlEntries()) {
            if (matchesPrincipal(principal, entry)) {
                return new HashSet<>(Arrays.asList(entry.getPrivileges()));
            }
        }
        return Collections.emptySet();
    } 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) AccessControlEntry(javax.jcr.security.AccessControlEntry) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) HashSet(java.util.HashSet)

Example 33 with MetadataRepositoryException

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

the class JcrActionsGroupBuilder method build.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.security.action.config.ActionsModuleBuilder#build()
     */
@Override
public AllowedActions build() {
    try {
        Session session = this.protoActionsNode.getSession();
        JcrAccessControlUtil.addPermissions(this.protoActionsNode, this.managementPrincipal, Privilege.JCR_ALL);
        JcrAccessControlUtil.addPermissions(this.protoActionsNode, new UsernamePrincipal(session.getUserID()), Privilege.JCR_ALL);
        JcrAccessControlUtil.addPermissions(this.protoActionsNode, SimplePrincipal.EVERYONE, Privilege.JCR_READ);
        JcrAllowedActions protoAllowed = new JcrAllowedActions(this.protoActionsNode);
        return protoAllowed;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to build action", e);
    }
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 34 with MetadataRepositoryException

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

the class JcrAllowableAction method hashCode.

@Override
public int hashCode() {
    // Hierarchy is fixed so hash code need only be calculated once.
    if (this.hash == 0) {
        try {
            List<String> hierList = new ArrayList<>();
            Node current = getNode();
            while (JcrUtil.isNodeType(current, NODE_TYPE)) {
                hierList.add(0, current.getName());
                current = current.getParent();
            }
            this.hash = hierList.hashCode();
        } catch (RepositoryException e) {
            throw new MetadataRepositoryException("Failed to access action hierarchy of node: " + this.getNode(), e);
        }
    }
    return this.hash;
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Example 35 with MetadataRepositoryException

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

the class JcrAllowedEntityActionsProvider method getActions.

protected Optional<AllowedActions> getActions(String groupName, Path groupPath) {
    try {
        Session session = JcrMetadataAccess.getActiveSession();
        if (session.getRootNode().hasNode(groupPath.toString())) {
            Node node = session.getRootNode().getNode(groupPath.toString());
            JcrAllowedActions actions = new JcrAllowedActions(node);
            return Optional.of(actions);
        } else {
            return Optional.empty();
        }
    } catch (AccessDeniedException e) {
        return Optional.empty();
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to access allowable actions for module: " + groupName, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) 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