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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations