use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class LockManagerImpl method writeLockProperties.
/**
* Add the lock related properties to the target node.
*
* @param node
* @param lockOwner
* @param isDeep
*/
protected void writeLockProperties(NodeImpl node, String lockOwner, boolean isDeep) throws RepositoryException {
boolean success = false;
SessionImpl editingSession = (SessionImpl) node.getSession();
WorkspaceImpl wsp = (WorkspaceImpl) editingSession.getWorkspace();
UpdatableItemStateManager stateMgr = wsp.getItemStateManager();
try {
acquireLockPropertiesLock();
if (stateMgr.inEditMode()) {
throw new RepositoryException("Unable to write lock properties.");
}
stateMgr.edit();
try {
// add properties to content
NodeId nodeId = node.getNodeId();
NodeState nodeState = (NodeState) stateMgr.getItemState(nodeId);
PropertyState propState;
if (!nodeState.hasPropertyName(NameConstants.JCR_LOCKOWNER)) {
propState = stateMgr.createNew(NameConstants.JCR_LOCKOWNER, nodeId);
propState.setType(PropertyType.STRING);
propState.setMultiValued(false);
} else {
propState = (PropertyState) stateMgr.getItemState(new PropertyId(nodeId, NameConstants.JCR_LOCKOWNER));
}
propState.setValues(new InternalValue[] { InternalValue.create(lockOwner) });
nodeState.addPropertyName(NameConstants.JCR_LOCKOWNER);
stateMgr.store(nodeState);
if (!nodeState.hasPropertyName(NameConstants.JCR_LOCKISDEEP)) {
propState = stateMgr.createNew(NameConstants.JCR_LOCKISDEEP, nodeId);
propState.setType(PropertyType.BOOLEAN);
propState.setMultiValued(false);
} else {
propState = (PropertyState) stateMgr.getItemState(new PropertyId(nodeId, NameConstants.JCR_LOCKISDEEP));
}
propState.setValues(new InternalValue[] { InternalValue.create(isDeep) });
nodeState.addPropertyName(NameConstants.JCR_LOCKISDEEP);
stateMgr.store(nodeState);
stateMgr.update();
success = true;
} catch (ItemStateException e) {
throw new RepositoryException("Error while creating lock.", e);
} finally {
if (!success) {
// failed to set lock meta-data content, cleanup
stateMgr.cancel();
try {
unlock(node);
} catch (RepositoryException e) {
// cleanup failed
log.error("error while cleaning up after failed lock attempt", e);
}
}
}
} finally {
releaseLockPropertiesLock();
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class LockManagerImpl method holdsLock.
/**
* {@inheritDoc}
*/
public boolean holdsLock(NodeImpl node) throws RepositoryException {
acquire();
try {
SessionImpl session = (SessionImpl) node.getSession();
PathMap.Element<LockInfo> element = lockMap.map(getPath(session, node.getId()), true);
if (element == null) {
return false;
}
return element.get() != null;
} catch (ItemNotFoundException e) {
return false;
} finally {
release();
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class PrivilegeManagerImpl method registerPrivilege.
/**
* Register a new custom privilege with the specified characteristics.
* <p>
* The current implementation has the following limitations and constraints:
*
* <ul>
* <li>the name may not be in use by another privilege</li>
* <li>the namespace URI must be a valid, registered namespace excluding
* those namespaces marked as being reserved</li>
* <li>an aggregate custom privilege is valid if all declared aggregate
* names can be resolved to registered privileges and if there exists
* no registered privilege with the same aggregated privileges.</li>
* </ul>
* <p>
* <strong>Please note</strong><br>
* Custom privilege(s) will not be enforced for any kind of repository
* operations. Those are exclusively covered by the built-in privileges.
* This also implies that the {@link Permission}s are not affected by
* custom privileges.
* <p>
* Applications making use of the custom privilege(s) are in charge of
* asserting whether the privileges are granted/denied according to their
* application specific needs.
*
* @param privilegeName The name of the new custom privilege.
* @param isAbstract Boolean flag indicating if the privilege is abstract.
* @param declaredAggregateNames An array of privilege names referring to
* registered privileges being aggregated by this new custom privilege.
* In case of a non aggregate privilege an empty array should be passed.
* @return the new privilege.
* @throws AccessDeniedException If the session this manager has been created
* lacks rep:privilegeManagement privilege.
* @throws RepositoryException If the privilege could not be registered due
* to constraint violations or if persisting the custom privilege fails.
* @see PrivilegeManager#registerPrivilege(String, boolean, String[])
*/
public Privilege registerPrivilege(String privilegeName, boolean isAbstract, String[] declaredAggregateNames) throws AccessDeniedException, RepositoryException {
if (resolver instanceof SessionImpl) {
SessionImpl sImpl = (SessionImpl) resolver;
sImpl.getAccessManager().checkRepositoryPermission(Permission.PRIVILEGE_MNGMT);
} else {
// cannot evaluate
throw new AccessDeniedException("Registering privileges is not allowed for the editing session.");
}
Name name = resolver.getQName(privilegeName);
Set<Name> daNames;
if (declaredAggregateNames == null || declaredAggregateNames.length == 0) {
daNames = Collections.emptySet();
} else {
daNames = new HashSet<Name>(declaredAggregateNames.length);
for (String declaredAggregateName : declaredAggregateNames) {
daNames.add(resolver.getQName(declaredAggregateName));
}
}
registry.registerDefinition(name, isAbstract, daNames);
return getPrivilege(privilegeName);
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class UserAccessControlProviderTest method testNoNodeForPrincipal.
/**
* @see <a href="https://issues.apache.org/jira/browse/JCR-2630">JCR-2630</a>
*/
public void testNoNodeForPrincipal() throws RepositoryException {
final Principal testPrincipal = getTestPrincipal();
String path = "/home/users/t/" + testPrincipal.getName();
while (s.nodeExists(path)) {
path += "_";
}
final String principalPath = path;
List<Set<Principal>> principalSets = new ArrayList<Set<Principal>>();
principalSets.add(Collections.<Principal>singleton(testPrincipal));
principalSets.add(Collections.<Principal>singleton(new ItemBasedPrincipal() {
public String getPath() {
return principalPath;
}
public String getName() {
return testPrincipal.getName();
}
}));
Path rootPath = ((SessionImpl) s).getQPath("/");
for (Set<Principal> principals : principalSets) {
CompiledPermissions cp = provider.compilePermissions(principals);
assertFalse(cp.canReadAll());
assertFalse(cp.grants(rootPath, Permission.READ));
assertTrue(cp.getPrivilegeSet(rootPath).isEmpty());
assertSame(CompiledPermissions.NO_PERMISSION, cp);
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class IndexNodeResolverTest method testFindNodesNonExactWithApostrophe.
public void testFindNodesNonExactWithApostrophe() throws NotExecutableException, RepositoryException {
UserImpl currentUser = getCurrentUser();
Value vs = superuser.getValueFactory().createValue("value ' with apostrophe");
currentUser.setProperty(propertyName1, vs);
save();
Name propName = ((SessionImpl) superuser).getQName(propertyName1);
try {
NodeResolver nr = createNodeResolver(currentUser.getNode().getSession());
NodeIterator result = nr.findNodes(propName, "value ' with apostrophe", UserConstants.NT_REP_USER, false);
assertTrue("expected result", result.hasNext());
assertEquals(currentUser.getNode().getPath(), result.nextNode().getPath());
assertFalse("expected no more results", result.hasNext());
} finally {
currentUser.removeProperty(propertyName1);
save();
}
}
Aggregations