use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class ACLEditor method setPolicy.
/**
* @see AccessControlEditor#setPolicy(String,AccessControlPolicy)
*/
public void setPolicy(String nodePath, AccessControlPolicy policy) throws RepositoryException {
checkProtectsNode(nodePath);
checkValidPolicy(nodePath, policy);
NodeImpl aclNode = getAclNode(nodePath);
if (aclNode != null) {
// remove all existing aces
for (NodeIterator aceNodes = aclNode.getNodes(); aceNodes.hasNext(); ) {
NodeImpl aceNode = (NodeImpl) aceNodes.nextNode();
removeItem(aceNode);
}
} else {
// create the acl node
aclNode = (nodePath == null) ? createRepoAclNode() : createAclNode(nodePath);
}
AccessControlEntry[] entries = ((ACLTemplate) policy).getAccessControlEntries();
for (AccessControlEntry entry : entries) {
AccessControlEntryImpl ace = (AccessControlEntryImpl) entry;
Name nodeName = getUniqueNodeName(aclNode, ace.isAllow() ? "allow" : "deny");
Name ntName = (ace.isAllow()) ? NT_REP_GRANT_ACE : NT_REP_DENY_ACE;
ValueFactory vf = session.getValueFactory();
// create the ACE node
NodeImpl aceNode = addNode(aclNode, nodeName, ntName);
// write the rep:principalName property
String principalName = ace.getPrincipal().getName();
setProperty(aceNode, P_PRINCIPAL_NAME, vf.createValue(principalName));
// ... and the rep:privileges property
Privilege[] pvlgs = ace.getPrivileges();
Value[] names = getPrivilegeNames(pvlgs, vf);
setProperty(aceNode, P_PRIVILEGES, names);
// store the restrictions:
Set<Name> restrNames = ace.getRestrictions().keySet();
for (Name restrName : restrNames) {
Value value = ace.getRestriction(restrName);
setProperty(aceNode, restrName, value);
}
}
// mark the parent modified.
markModified(((NodeImpl) aclNode.getParent()));
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class RetentionManagerImpl method getHolds.
//---------------------------------------------------< RetentionManager >---
/**
* @see RetentionManager#getHolds(String)
*/
public Hold[] getHolds(String absPath) throws PathNotFoundException, AccessDeniedException, RepositoryException {
NodeImpl n = (NodeImpl) session.getNode(absPath);
session.getAccessManager().checkPermission(session.getQPath(absPath), Permission.RETENTION_MNGMT);
Hold[] holds;
if (n.isNodeType(REP_RETENTION_MANAGEABLE) && n.hasProperty(REP_HOLD)) {
holds = HoldImpl.createFromProperty(n.getProperty(REP_HOLD), n.getNodeId());
} else {
holds = new Hold[0];
}
return holds;
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class RetentionManagerImpl method getRetentionPolicy.
/**
* @see RetentionManager#getRetentionPolicy(String)
*/
public RetentionPolicy getRetentionPolicy(String absPath) throws PathNotFoundException, AccessDeniedException, RepositoryException {
NodeImpl n = (NodeImpl) session.getNode(absPath);
session.getAccessManager().checkPermission(session.getQPath(absPath), Permission.RETENTION_MNGMT);
RetentionPolicy rPolicy = null;
if (n.isNodeType(REP_RETENTION_MANAGEABLE) && n.hasProperty(REP_RETENTION_POLICY)) {
String jcrName = n.getProperty(REP_RETENTION_POLICY).getString();
rPolicy = new RetentionPolicyImpl(jcrName, n.getNodeId(), session);
}
return rPolicy;
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class RetentionManagerImpl method removeHold.
/**
* @see RetentionManager#removeHold(String, Hold)
*/
public void removeHold(String absPath, Hold hold) throws PathNotFoundException, AccessDeniedException, LockException, VersionException, RepositoryException {
NodeImpl n = (NodeImpl) session.getNode(absPath);
if (hold instanceof HoldImpl && n.getNodeId().equals(((HoldImpl) hold).getNodeId()) && n.isNodeType(REP_RETENTION_MANAGEABLE) && n.hasProperty(REP_HOLD)) {
PropertyImpl p = n.getProperty(REP_HOLD);
Value[] vls = p.getValues();
List<Value> newValues = new ArrayList<Value>(vls.length - 1);
for (Value v : vls) {
if (!hold.equals(HoldImpl.createFromValue(v, n.getNodeId(), session))) {
newValues.add(v);
}
}
if (newValues.size() < vls.length) {
if (newValues.size() == 0) {
removeItem(p);
} else {
setProperty(n, REP_HOLD, newValues.toArray(new Value[newValues.size()]));
}
} else {
// no matching hold.
throw new RepositoryException("Cannot remove '" + hold.getName() + "' at " + absPath + ".");
}
} else {
// invalid hold or no hold at absPath
throw new RepositoryException("Cannot remove '" + hold.getName() + "' at " + absPath + ".");
}
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class RetentionManagerImpl method addHold.
/**
* @see RetentionManager#addHold(String, String, boolean)
*/
public Hold addHold(String absPath, String name, boolean isDeep) throws PathNotFoundException, AccessDeniedException, LockException, VersionException, RepositoryException {
NodeImpl n = (NodeImpl) session.getNode(absPath);
if (!n.isNodeType(REP_RETENTION_MANAGEABLE)) {
n.addMixin(REP_RETENTION_MANAGEABLE);
}
HoldImpl hold = new HoldImpl(session.getQName(name), isDeep, n.getNodeId(), session);
Value[] vls;
if (n.hasProperty(REP_HOLD)) {
Value[] vs = n.getProperty(REP_HOLD).getValues();
// check if the same hold already exists
for (Value v : vs) {
if (hold.equals(HoldImpl.createFromValue(v, n.getNodeId(), session))) {
throw new RepositoryException("Hold already exists.");
}
}
vls = new Value[vs.length + 1];
System.arraycopy(vs, 0, vls, 0, vs.length);
} else {
vls = new Value[1];
}
// add the value of the new hold
vls[vls.length - 1] = hold.toValue(session.getValueFactory());
setProperty(n, REP_HOLD, vls);
return hold;
}
Aggregations