use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrProjectProvider method createProject.
/**
* Creates a new user with the specified name.
*
* @param name the name of the Project
* @param ensure {@code true} to return the Project if it already exists, or {@code false} to throw an exception
* @return the Project
* @throws MetadataRepositoryException if the user could not be created
*/
@Nonnull
private Project createProject(@Nonnull final String name, final boolean ensure) {
final Session session = getSession();
final String projPath = ProjectPaths.projectPath(name).toString();
logger.debug("workspace= {}", session.getWorkspace().getName());
try {
Node projNode = session.getRootNode().getNode(ProjectPaths.PROJECTS.toString());
if (session.getRootNode().hasNode(projPath)) {
if (ensure) {
return JcrUtil.getJcrObject(projNode, name, JcrProject.class);
} else {
// TODO specialize me..
throw new RuntimeException(projPath);
}
} else {
// project does not yet exist
JcrProject newProject = JcrUtil.getOrCreateNode(projNode, name, JcrProject.NODE_TYPE, JcrProject.class);
// grant (or deny) current user access to the project he is creating
if (this.accessController.isEntityAccessControlled()) {
List<SecurityRole> roles = this.roleProvider.getEntityRoles(SecurityRole.PROJECT);
this.actionsProvider.getAvailableActions(AllowedActions.PROJECTS).ifPresent(actions -> newProject.enableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser(), roles));
} else {
this.actionsProvider.getAvailableActions(AllowedActions.PROJECTS).ifPresent(actions -> newProject.disableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser()));
}
return newProject;
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed attempting to create a new Project with name: " + name, e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrAccessControlUtil method removeHierarchyPermissions.
public static boolean removeHierarchyPermissions(Node node, Principal principal, Node toNode, String... privilegeNames) {
try {
Node current = node;
Node rootNode = toNode.getSession().getRootNode();
boolean removed = false;
while (!current.equals(toNode) && !current.equals(rootNode)) {
removed |= removePermissions(node.getSession(), current.getPath(), principal, privilegeNames);
current = current.getParent();
}
if (current.equals(rootNode) && !toNode.equals(rootNode)) {
throw new IllegalArgumentException("removeHierarchyPermissions: The \"toNode\" argument is not in the \"node\" argument's hierarchy: " + toNode);
} else {
removed |= removePermissions(node.getSession(), current.getPath(), principal, privilegeNames);
}
return removed;
} catch (AccessDeniedException e) {
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to remove permission(s) from hierarch from node " + node + " up to " + toNode, e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrAccessControlUtil method clearPermissions.
public static boolean clearPermissions(Session session, String path) {
try {
AccessControlManager acm = session.getAccessControlManager();
AccessControlPolicy[] acls = acm.getPolicies(path);
if (acls.length > 0) {
for (AccessControlPolicy policy : acm.getPolicies(path)) {
acm.removePolicy(path, policy);
}
return true;
} 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 addHierarchyPermissions.
/**
* Adds the specified privilege to the node hierarchy starting at a child node and proceeding through its parents until
* the destination node is reached.
*
* @param node the starting node on which the privilege is assigned
* @param principal the principal being given the privilege
* @param toNode the ending parent node
* @param privilegeNames the privilege being assigned
* @return true if any of the nodes had their privilege change for the principle (i.e. the privilege had not already existed)
*/
public static boolean addHierarchyPermissions(Node node, Principal principal, Node toNode, Collection<String> privilegeNames) {
try {
Node current = node;
Node rootNode = toNode.getSession().getRootNode();
AtomicBoolean added = new AtomicBoolean(false);
Deque<Node> stack = new ArrayDeque<>();
while (!current.equals(toNode) && !current.equals(rootNode)) {
stack.push(current);
current = current.getParent();
}
if (current.equals(rootNode) && !toNode.equals(rootNode)) {
throw new IllegalArgumentException("addHierarchyPermissions: The \"toNode\" argument is not in the \"node\" argument's hierarchy: " + toNode);
} else {
stack.push(current);
}
stack.stream().forEach((n) -> added.compareAndSet(false, addPermissions(n, principal, privilegeNames)));
return added.get();
} catch (AccessDeniedException e) {
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to add permission(s) to hierarchy from node " + node + " up to " + toNode, e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrAccessControlUtil method updatePermissions.
private static boolean updatePermissions(Session session, String path, Principal principal, boolean replace, Privilege... privileges) {
try {
AccessControlManager acm = session.getAccessControlManager();
AccessControlList acl = getAccessControlList(path, acm);
boolean changed = false;
if (replace) {
changed |= removeEntry(acl, principal);
}
if (privileges.length > 0) {
changed |= addEntry(session, acl, principal, privileges);
}
acm.setPolicy(path, acl);
return changed;
} catch (AccessDeniedException e) {
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to add permission(s) to node " + path + ": " + Arrays.toString(privileges), e);
}
}
Aggregations