use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class NodeTypeRegistry method reregisterNodeType.
/**
* Internal implementation of {@link #reregisterNodeType(QNodeTypeDefinition)}.
*
* @param ntd node type definition
* @param external whether this invocation should be considered external
* @return the new effective node type
* @throws NoSuchNodeTypeException if <code>ntd</code> refers to an
* unknown node type
* @throws InvalidNodeTypeDefException if the node type definition
* is invalid
* @throws RepositoryException if another error occurs
*/
private EffectiveNodeType reregisterNodeType(QNodeTypeDefinition ntd, boolean external) throws NoSuchNodeTypeException, InvalidNodeTypeDefException, RepositoryException {
EffectiveNodeType entNew;
synchronized (this) {
Name name = ntd.getName();
if (!registeredNTDefs.containsKey(name)) {
throw new NoSuchNodeTypeException(name.toString());
}
if (builtInNTDefs.contains(name)) {
throw new RepositoryException(name.toString() + ": can't reregister built-in node type.");
}
/**
* validate new node type definition
*/
ntd = checkNtBaseSubtyping(ntd, registeredNTDefs);
validateNodeTypeDef(ntd, entCache, registeredNTDefs, nsReg, false);
/**
* build diff of current and new definition and determine type of change
*/
QNodeTypeDefinition ntdOld = registeredNTDefs.get(name);
NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntdOld, ntd);
if (!diff.isModified()) {
// the definition has not been modified, there's nothing to do here...
return getEffectiveNodeType(name);
}
// make sure existing content would not conflict
// with new node type definition
checkForConflictingContent(ntd, diff);
/**
* re-register node type definition and update caches &
* notify listeners on re-registration
*/
internalUnregister(name);
// remove old node type definition from store
customNTDefs.remove(name);
entNew = internalRegister(ntd);
// add new node type definition to store
customNTDefs.add(ntd);
// persist node type definitions
persistCustomNodeTypeDefs(customNTDefs);
// notify listeners
notifyReRegistered(name);
}
// inform cluster if this is not an external invocation
if (!external && eventChannel != null) {
eventChannel.reregistered(ntd);
}
return entNew;
}
use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class EffectiveNodeType method getApplicableChildNodeDef.
/**
* Returns the applicable child node definition for a child node with the
* specified name and node type. If there are multiple applicable definitions
* named definitions will take precedence over residual definitions.
*
* @param name
* @param nodeTypeName
* @param ntReg
* @return
* @throws NoSuchNodeTypeException
* @throws ConstraintViolationException if no applicable child node definition
* could be found
*/
public QNodeDefinition getApplicableChildNodeDef(Name name, Name nodeTypeName, NodeTypeRegistry ntReg) throws NoSuchNodeTypeException, ConstraintViolationException {
EffectiveNodeType entTarget;
if (nodeTypeName != null) {
entTarget = ntReg.getEffectiveNodeType(nodeTypeName);
} else {
entTarget = null;
}
// try named node definitions first
QItemDefinition[] defs = getNamedItemDefs(name);
for (QItemDefinition def : defs) {
if (def.definesNode()) {
QNodeDefinition nd = (QNodeDefinition) def;
Name[] types = nd.getRequiredPrimaryTypes();
// node definition with that name exists
if (entTarget != null && types != null) {
// check 'required primary types' constraint
if (entTarget.includesNodeTypes(types)) {
// found named node definition
return nd;
}
} else if (nd.getDefaultPrimaryType() != null) {
// found node definition with default node type
return nd;
}
}
}
// no item with that name defined;
// try residual node definitions
QNodeDefinition[] nda = getUnnamedNodeDefs();
for (QNodeDefinition nd : nda) {
if (entTarget != null && nd.getRequiredPrimaryTypes() != null) {
// check 'required primary types' constraint
if (!entTarget.includesNodeTypes(nd.getRequiredPrimaryTypes())) {
continue;
}
// found residual node definition
return nd;
} else {
// it must be determined from the default node type;
if (nd.getDefaultPrimaryType() != null) {
// found residual node definition with default node type
return nd;
}
}
}
// no applicable definition found
throw new ConstraintViolationException("no matching child node definition found for " + name);
}
use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class PrivilegeRegistry method getBits.
/**
* Best effort approach to calculate bits for built-in privileges. Throws
* <code>UnsupportedOperationException</code> if the workaround fails.
*
* @param privileges An array of privileges.
* @return The privilege bits.
* @throws AccessControlException If the specified array is null
* or if it contains an unregistered privilege.
* @see #getPrivileges(int)
* @deprecated Use {@link PrivilegeManagerImpl#getBits(javax.jcr.security.Privilege...)} instead.
*/
public static int getBits(Privilege[] privileges) throws AccessControlException {
if (privileges == null || privileges.length == 0) {
throw new AccessControlException("Privilege array is empty or null.");
}
Map<String, String> lookup = new HashMap<String, String>(2);
lookup.put(Name.NS_REP_PREFIX, Name.NS_REP_URI);
lookup.put(Name.NS_JCR_PREFIX, Name.NS_JCR_URI);
int bits = NO_PRIVILEGE;
for (Privilege priv : privileges) {
String prefix = Text.getNamespacePrefix(priv.getName());
if (lookup.containsKey(prefix)) {
Name n = NAME_FACTORY.create(lookup.get(prefix), Text.getLocalName(priv.getName()));
if (PRIVILEGE_NAMES.containsKey(n)) {
bits |= PRIVILEGE_NAMES.get(n);
} else if (NameConstants.JCR_WRITE.equals(n)) {
bits |= createJcrWriteDefinition().bits.longValue();
} else if (REP_WRITE_NAME.equals(n)) {
Definition jcrWrite = createJcrWriteDefinition();
bits |= createRepWriteDefinition(jcrWrite).bits.longValue();
} else if (NameConstants.JCR_ALL.equals(n)) {
for (Name pn : PRIVILEGE_NAMES.keySet()) {
bits |= PRIVILEGE_NAMES.get(pn);
}
} else {
throw new AccessControlException("Unknown privilege '" + priv.getName() + "'.");
}
} else {
throw new AccessControlException("Unknown privilege '" + priv.getName() + "'.");
}
}
return bits;
}
use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class PrivilegeRegistry method registerDefinition.
//-----------------------------------< methods used by PrivilegeManager >---
/**
* Validates and registers a new custom privilege definition with the
* specified characteristics. Upon successful registration the new custom
* definition is persisted in the corresponding file system resource.<p/>
*
* <p>The validation includes the following steps:</p>
*
* <ul>
* <li>assert uniqueness of the specified privilegeName</li>
* <li>make sure the name doesn't use a reserved namespace</li>
* <li>assert that all names referenced in the specified name set refer
* to existing privilege definitions.</li>
* </ul>
*
* @param privilegeName
* @param isAbstract
* @param declaredAggregateNames
* @throws RepositoryException If the privilege could not be registered due
* to constraint violations or if persisting the custom privilege fails.
*/
void registerDefinition(Name privilegeName, boolean isAbstract, Set<Name> declaredAggregateNames) throws RepositoryException {
PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, isAbstract, declaredAggregateNames);
Map<Name, PrivilegeDefinition> stubs = Collections.singletonMap(privilegeName, def);
registerCustomDefinitions(stubs);
// inform clustering about the new privilege.
if (eventChannel != null) {
eventChannel.registeredPrivileges(stubs.values());
}
}
use of org.apache.jackrabbit.spi.Name 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()));
}
Aggregations