Author: sergiykarpenko
Date: 2010-09-29 08:40:05 -0400 (Wed, 29 Sep 2010)
New Revision: 3218
Added:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLockPermissions.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
Log:
EXOJCR-979: lock/unlock operations now checks does session have SET_PROPERTY permission
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-09-29
09:52:33 UTC (rev 3217)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-09-29
12:40:05 UTC (rev 3218)
@@ -218,8 +218,8 @@
}
// Validate
- if (session.getWorkspace().getNodeTypesHolder()
- .isNodeType(type.getName(), nodeData().getPrimaryTypeName(),
nodeData().getMixinTypeNames()))
+ if (session.getWorkspace().getNodeTypesHolder().isNodeType(type.getName(),
nodeData().getPrimaryTypeName(),
+ nodeData().getMixinTypeNames()))
{
throw new ConstraintViolationException("Can not add mixin type " +
mixinName + " to " + getPath());
}
@@ -285,8 +285,8 @@
// find node type
NodeDefinitionData nodeDef =
- session.getWorkspace().getNodeTypesHolder()
- .getChildNodeDefinition(name, nodeData().getPrimaryTypeName(),
nodeData().getMixinTypeNames());
+ session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(name,
nodeData().getPrimaryTypeName(),
+ nodeData().getMixinTypeNames());
if (nodeDef == null)
{
@@ -357,16 +357,16 @@
checkValid();
NodeTypeData type =
- session.getWorkspace().getNodeTypesHolder()
- .getNodeType(locationFactory.parseJCRName(mixinName).getInternalName());
+ session.getWorkspace().getNodeTypesHolder().getNodeType(
+ locationFactory.parseJCRName(mixinName).getInternalName());
if (type == null)
{
throw new NoSuchNodeTypeException("Nodetype not found (mixin) " +
mixinName);
}
- if (session.getWorkspace().getNodeTypesHolder()
- .isNodeType(type.getName(), nodeData().getPrimaryTypeName(),
nodeData().getMixinTypeNames()))
+ if (session.getWorkspace().getNodeTypesHolder().isNodeType(type.getName(),
nodeData().getPrimaryTypeName(),
+ nodeData().getMixinTypeNames()))
{
return false;
}
@@ -789,8 +789,8 @@
for (int i = 1; i < myPath.getDepth(); i++)
{
ancestor = (NodeData)dataManager.getItemData(ancestor,
myPath.getEntries()[i], ItemType.NODE);
- if (corrSession.getWorkspace().getNodeTypesHolder()
- .isNodeType(Constants.MIX_REFERENCEABLE, ancestor.getPrimaryTypeName(),
ancestor.getMixinTypeNames()))
+ if
(corrSession.getWorkspace().getNodeTypesHolder().isNodeType(Constants.MIX_REFERENCEABLE,
+ ancestor.getPrimaryTypeName(), ancestor.getMixinTypeNames()))
{
NodeData corrAncestor =
(NodeData)corrDataManager.getItemData(ancestor.getIdentifier());
if (corrAncestor == null)
@@ -859,8 +859,8 @@
new NodeDefinitionData(null, null, true, true,
OnParentVersionAction.ABORT, false,
new InternalQName[]{requiredName}, null, true);
this.nodeDefinition =
- new NodeDefinitionImpl(ntData, nodeTypesHolder, nodeTypeManager,
sysLocFactory,
- session.getValueFactory(), session.getTransientNodesManager());
+ new NodeDefinitionImpl(ntData, nodeTypesHolder, nodeTypeManager,
sysLocFactory, session
+ .getValueFactory(), session.getTransientNodesManager());
}
}
else
@@ -869,8 +869,8 @@
NodeData parent = (NodeData)dataManager.getItemData(getParentIdentifier());
this.definition =
- nodeTypesHolder.getChildNodeDefinition(getInternalName(),
parent.getPrimaryTypeName(),
- parent.getMixinTypeNames());
+ nodeTypesHolder.getChildNodeDefinition(getInternalName(),
parent.getPrimaryTypeName(), parent
+ .getMixinTypeNames());
if (definition == null)
{
@@ -886,8 +886,8 @@
}
nodeDefinition =
- new NodeDefinitionImpl(definition, nodeTypesHolder, nodeTypeManager,
sysLocFactory,
- session.getValueFactory(), session.getTransientNodesManager());
+ new NodeDefinitionImpl(definition, nodeTypesHolder, nodeTypeManager,
sysLocFactory, session
+ .getValueFactory(), session.getTransientNodesManager());
}
}
@@ -1468,8 +1468,8 @@
{
checkValid();
- return session.getWorkspace().getNodeTypesHolder()
- .isNodeType(qName, nodeData().getPrimaryTypeName(),
nodeData().getMixinTypeNames());
+ return session.getWorkspace().getNodeTypesHolder().isNodeType(qName,
nodeData().getPrimaryTypeName(),
+ nodeData().getMixinTypeNames());
}
/**
@@ -1559,8 +1559,8 @@
}
this.definition =
- session.getWorkspace().getNodeTypesHolder()
- .getChildNodeDefinition(getInternalName(), parent.getPrimaryTypeName(),
parent.getMixinTypeNames());
+
session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(getInternalName(),
+ parent.getPrimaryTypeName(), parent.getMixinTypeNames());
if (definition == null)
{
@@ -1591,6 +1591,15 @@
throw new LockException("Node is not lockable " + getPath());
}
+ // session.checkPermission(getPath(), PermissionType.SET_PROPERTY) is not used
because RepositoryException
+ // is wrapped into AccessControlException
+ if (!session.getAccessManager().hasPermission(getACL(), new
String[]{PermissionType.SET_PROPERTY},
+ session.getUserState().getIdentity()))
+ {
+ throw new AccessDeniedException("Access denied: lock operation " +
getPath() + " for: " + session.getUserID()
+ + " item owner " + getACL().getOwner());
+ }
+
if (dataManager.hasPendingChanges(getInternalPath()))
{
throw new InvalidItemStateException("Node has pending unsaved changes
" + getPath());
@@ -1631,6 +1640,15 @@
throw new LockException("Node is not lockable " + getPath());
}
+ // session.checkPermission(getPath(), PermissionType.SET_PROPERTY) is not used
because RepositoryException
+ // is wrapped into AccessControlException
+ if (!session.getAccessManager().hasPermission(getACL(), new
String[]{PermissionType.SET_PROPERTY},
+ session.getUserState().getIdentity()))
+ {
+ throw new AccessDeniedException("Access denied: lock operation " +
getPath() + " for: " + session.getUserID()
+ + " item owner " + getACL().getOwner());
+ }
+
if (dataManager.hasPendingChanges(getInternalPath()))
{
throw new InvalidItemStateException("Node has pending unsaved changes
" + getPath());
@@ -1962,7 +1980,7 @@
QPath destPath = locationFactory.parseRelPath(relPath).getInternalPath();
NodeImpl destParent =
(NodeImpl)dataManager.getItem(nodeData(),
destPath.makeParentPath().getEntries(), false, ItemType.NODE);
-
+
if (destParent == null)
{
throw new PathNotFoundException("Parent not found for " +
relPath);
@@ -2125,8 +2143,8 @@
checkValid();
- return doUpdateProperty(this,
locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
@@ -2139,8 +2157,8 @@
checkValid();
- return doUpdateProperty(this,
locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
@@ -2153,8 +2171,8 @@
checkValid();
- return doUpdateProperty(this,
locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
/**
@@ -2166,8 +2184,8 @@
checkValid();
- return doUpdateProperty(this,
locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
/**
@@ -2179,8 +2197,8 @@
checkValid();
- return doUpdateProperty(this,
locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
@@ -2193,8 +2211,8 @@
checkValid();
- return doUpdateProperty(this,
locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
@@ -2207,8 +2225,8 @@
checkValid();
- return doUpdateProperty(this,
locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
@@ -2221,8 +2239,8 @@
checkValid();
- return doUpdateProperty(this,
locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value, type), false, type);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
valueFactory.createValue(
+ value, type), false, type);
}
/**
@@ -2344,6 +2362,15 @@
throw new InvalidItemStateException("Node has pending unsaved changes
" + getPath());
}
+ // session.checkPermission(getPath(), PermissionType.SET_PROPERTY) is not used
because RepositoryException
+ // is wrapped into AccessControlException
+ if (!session.getAccessManager().hasPermission(getACL(), new
String[]{PermissionType.SET_PROPERTY},
+ session.getUserState().getIdentity()))
+ {
+ throw new AccessDeniedException("Access denied: unlock operation " +
getPath() + " for: "
+ + session.getUserID() + " item owner " + getACL().getOwner());
+ }
+
doUnlock();
session.getActionHandler().postUnlock(this);
@@ -2433,8 +2460,8 @@
}
// Check if node is not protected
NodeDefinitionData childNodeDefinition =
- session.getWorkspace().getNodeTypesHolder()
- .getChildNodeDefinition(name, nodeData().getPrimaryTypeName(),
nodeData().getMixinTypeNames());
+ session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(name,
nodeData().getPrimaryTypeName(),
+ nodeData().getMixinTypeNames());
if (childNodeDefinition == null)
{
throw new ConstraintViolationException("Can't find child node
definition for "
@@ -2651,16 +2678,16 @@
QPath.makeChildPath(newData.getQPath().makeParentPath(),
newData.getQPath().getName(), sameNameIndex);
newData =
- new TransientNodeData(siblingPath, newData.getIdentifier(),
newData.getPersistedVersion(),
- newData.getPrimaryTypeName(), newData.getMixinTypeNames(), j,
newData.getParentIdentifier(),
- newData.getACL());
+ new TransientNodeData(siblingPath, newData.getIdentifier(),
newData.getPersistedVersion(), newData
+ .getPrimaryTypeName(), newData.getMixinTypeNames(), j,
newData.getParentIdentifier(), newData
+ .getACL());
}
else
{
newData =
new TransientNodeData(newData.getQPath(), newData.getIdentifier(),
newData.getPersistedVersion(),
- newData.getPrimaryTypeName(), newData.getMixinTypeNames(), j,
newData.getParentIdentifier(),
- newData.getACL());
+ newData.getPrimaryTypeName(), newData.getMixinTypeNames(), j,
newData.getParentIdentifier(), newData
+ .getACL());
}
/*
@@ -2774,9 +2801,8 @@
}
TransientPropertyData tdata =
- new TransientPropertyData(QPath.makeChildPath(getInternalPath(), name),
existed.getIdentifier(),
- existed.getPersistedVersion(), existed.getType(),
existed.getParentIdentifier(), existed.isMultiValued(),
- values);
+ new TransientPropertyData(QPath.makeChildPath(getInternalPath(), name),
existed.getIdentifier(), existed
+ .getPersistedVersion(), existed.getType(), existed.getParentIdentifier(),
existed.isMultiValued(), values);
return tdata;
}
@@ -2794,9 +2820,8 @@
}
TransientPropertyData tdata =
- new TransientPropertyData(QPath.makeChildPath(getInternalPath(), name),
existed.getIdentifier(),
- existed.getPersistedVersion(), existed.getType(),
existed.getParentIdentifier(), existed.isMultiValued(),
- value);
+ new TransientPropertyData(QPath.makeChildPath(getInternalPath(), name),
existed.getIdentifier(), existed
+ .getPersistedVersion(), existed.getType(), existed.getParentIdentifier(),
existed.isMultiValued(), value);
return tdata;
}
@@ -2858,9 +2883,9 @@
}
mergeFailed =
- new TransientPropertyData(mergeFailed.getQPath(),
mergeFailed.getIdentifier(),
- mergeFailed.getPersistedVersion(), mergeFailed.getType(),
mergeFailed.getParentIdentifier(),
- mergeFailed.isMultiValued(), mergeFailedRefs);
+ new TransientPropertyData(mergeFailed.getQPath(),
mergeFailed.getIdentifier(), mergeFailed
+ .getPersistedVersion(), mergeFailed.getType(),
mergeFailed.getParentIdentifier(), mergeFailed
+ .isMultiValued(), mergeFailedRefs);
state = ItemState.UPDATED;
}
@@ -2914,8 +2939,8 @@
{
NodeDefinitionData def =
- session.getWorkspace().getNodeTypesHolder()
- .getChildNodeDefinition(nameToAdd, parentNode.getPrimaryTypeName(),
parentNode.getMixinTypeNames());
+ session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(nameToAdd,
parentNode.getPrimaryTypeName(),
+ parentNode.getMixinTypeNames());
boolean allowSns = def.isAllowsSameNameSiblings();
@@ -2973,8 +2998,8 @@
// create new nodedata, [PN] fix of use index as persisted version
NodeData nodeData =
- new TransientNodeData(path, identifier, -1, primaryTypeName, mixinTypeNames,
orderNum,
- parentNode.getInternalIdentifier(), acl);
+ new TransientNodeData(path, identifier, -1, primaryTypeName, mixinTypeNames,
orderNum, parentNode
+ .getInternalIdentifier(), acl);
// Create new Node
ItemState state = ItemState.createAddedState(nodeData, false);
@@ -3062,10 +3087,9 @@
// to jcr:predecessors (with doneMerge) or just removed from
// jcr:mergeFailed (with cancelMerge) the jcr:mergeFailed
// property is automatically remove
- changesLog.add(ItemState.createDeletedState(
- new TransientPropertyData(mergeFailed.getQPath(),
mergeFailed.getIdentifier(), mergeFailed
- .getPersistedVersion(), mergeFailed.getType(),
mergeFailed.getParentIdentifier(), mergeFailed
- .isMultiValued(), mergeFailed.getValues()), true));
+ changesLog.add(ItemState.createDeletedState(new
TransientPropertyData(mergeFailed.getQPath(), mergeFailed
+ .getIdentifier(), mergeFailed.getPersistedVersion(), mergeFailed.getType(),
mergeFailed
+ .getParentIdentifier(), mergeFailed.isMultiValued(),
mergeFailed.getValues()), true));
}
}
@@ -3073,9 +3097,9 @@
{
NodeData nodeData = (NodeData)data;
data =
- new TransientNodeData(nodeData.getQPath(), nodeData.getIdentifier(),
nodeData.getPersistedVersion(),
- nodeData.getPrimaryTypeName(), nodeData.getMixinTypeNames(),
nodeData.getOrderNumber(),
- nodeData.getParentIdentifier(), acl);
+ new TransientNodeData(nodeData.getQPath(), nodeData.getIdentifier(),
nodeData.getPersistedVersion(), nodeData
+ .getPrimaryTypeName(), nodeData.getMixinTypeNames(),
nodeData.getOrderNumber(), nodeData
+ .getParentIdentifier(), acl);
}
private void updateMixin(List<InternalQName> newMixin) throws
RepositoryException
@@ -3086,9 +3110,8 @@
NodeData nodeData = (NodeData)data;
data =
- new TransientNodeData(nodeData.getQPath(), nodeData.getIdentifier(),
nodeData.getPersistedVersion(),
- nodeData.getPrimaryTypeName(), mixins, nodeData.getOrderNumber(),
nodeData.getParentIdentifier(),
- nodeData.getACL());
+ new TransientNodeData(nodeData.getQPath(), nodeData.getIdentifier(),
nodeData.getPersistedVersion(), nodeData
+ .getPrimaryTypeName(), mixins, nodeData.getOrderNumber(),
nodeData.getParentIdentifier(), nodeData.getACL());
// ((TransientNodeData)data).setMixinTypeNames(mixins);
Added:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLockPermissions.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLockPermissions.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLockPermissions.java 2010-09-29
12:40:05 UTC (rev 3218)
@@ -0,0 +1,250 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.api.lock;
+
+import org.exoplatform.services.jcr.JcrAPIBaseTest;
+import org.exoplatform.services.jcr.access.PermissionType;
+import org.exoplatform.services.jcr.core.CredentialsImpl;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+
+import java.security.AccessControlException;
+import java.util.HashMap;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.lock.Lock;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: TestLockPermissions.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class TestLockPermissions extends JcrAPIBaseTest
+{
+
+ private Node lockedNode = null;
+
+ public void setUp() throws Exception
+ {
+
+ super.setUp();
+
+ if (lockedNode == null)
+ try
+ {
+ lockedNode = root.addNode("rootLockPermissionsTest");
+ // if (lockedNode.canAddMixin("mix:lockable"))
+ // lockedNode.addMixin("mix:lockable");
+ root.save();
+ }
+ catch (RepositoryException e)
+ {
+ fail("Child node must be accessible and readable. But error occurs:
" + e);
+ }
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ lockedNode.remove();
+ session.save();
+ super.tearDown();
+ }
+
+ public void testLockAccessDeniedException() throws RepositoryException
+ {
+ Session session1 = repository.login(new CredentialsImpl("root",
"exo".toCharArray()), "ws");
+ NodeImpl nodeToLockSession1 =
+
(NodeImpl)session1.getRootNode().getNode("rootLockPermissionsTest").addNode("testLockSesssionScoped");
+ nodeToLockSession1.addMixin("mix:lockable");
+ nodeToLockSession1.addMixin("exo:owneable");
+ nodeToLockSession1.addMixin("exo:privilegeable");
+
+ // change permission
+ HashMap<String, String[]> perm = new HashMap<String, String[]>();
+ perm.put("john", new String[]{PermissionType.READ});
+ nodeToLockSession1.setPermissions(perm);
+ session1.save();
+
+ nodeToLockSession1.lock(true, false);// boolean isSessionScoped=false
+ assertTrue(nodeToLockSession1.isLocked());
+ nodeToLockSession1.unlock();
+ assertFalse(nodeToLockSession1.isLocked());
+
+ Session session2 = repository.login(new CredentialsImpl("john",
"exo".toCharArray()), "ws");
+ session2.checkPermission(nodeToLockSession1.getPath(), PermissionType.READ);
+ try
+ {
+ session2.checkPermission(nodeToLockSession1.getPath(),
PermissionType.SET_PROPERTY);
+ fail("AccessControlException should have been thrown ");
+ }
+ catch (AccessControlException e)
+ {
+ //ok
+ }
+
+ Node nodeToLockSession2 =
+
session2.getRootNode().getNode("rootLockPermissionsTest").getNode("testLockSesssionScoped");
+ assertFalse(nodeToLockSession2.isLocked());
+ try
+ {
+ try
+ {
+ // trying to lock
+ nodeToLockSession2.lock(true, false);
+ fail("Node locked. An AccessDeniedException should be thrown on set
property but doesn't");
+ }
+ catch (AccessDeniedException e)
+ {
+ // ok
+ }
+ }
+ finally
+ {
+ if (nodeToLockSession1.isLocked())
+ {
+ nodeToLockSession1.unlock();
+ }
+ session1.logout();
+ session2.logout();
+ }
+ }
+
+ public void testLockTimedAccessDeniedException() throws RepositoryException
+ {
+ Session session1 = repository.login(new CredentialsImpl("root",
"exo".toCharArray()), "ws");
+ NodeImpl nodeToLockSession1 =
+
(NodeImpl)session1.getRootNode().getNode("rootLockPermissionsTest").addNode("testLockTimed");
+ nodeToLockSession1.addMixin("mix:lockable");
+ nodeToLockSession1.addMixin("exo:owneable");
+ nodeToLockSession1.addMixin("exo:privilegeable");
+
+ // change permission
+ HashMap<String, String[]> perm = new HashMap<String, String[]>();
+ perm.put("john", new String[]{PermissionType.READ});
+ nodeToLockSession1.setPermissions(perm);
+ session1.save();
+
+ nodeToLockSession1.lock(true, 100000);
+ assertTrue(nodeToLockSession1.isLocked());
+ nodeToLockSession1.unlock();
+ assertFalse(nodeToLockSession1.isLocked());
+
+ Session session2 = repository.login(new CredentialsImpl("john",
"exo".toCharArray()), "ws");
+ session2.checkPermission(nodeToLockSession1.getPath(), PermissionType.READ);
+ try
+ {
+ session2.checkPermission(nodeToLockSession1.getPath(),
PermissionType.SET_PROPERTY);
+ fail("AccessControlException should have been thrown ");
+ }
+ catch (AccessControlException e)
+ {
+ //ok
+ }
+
+ NodeImpl nodeToLockSession2 =
+
(NodeImpl)session2.getRootNode().getNode("rootLockPermissionsTest").getNode("testLockTimed");
+ assertFalse(nodeToLockSession2.isLocked());
+ try
+ {
+ try
+ {
+ // trying to lock
+ nodeToLockSession2.lock(true, 100000);
+ fail("Node locked. An AccessDeniedException should be thrown on set
property but doesn't");
+ }
+ catch (AccessDeniedException e)
+ {
+ // ok
+ }
+ }
+ finally
+ {
+ if (nodeToLockSession1.isLocked())
+ {
+ nodeToLockSession1.unlock();
+ }
+ session1.logout();
+ session2.logout();
+ }
+ }
+
+ public void testUnlockAccessDeniedException() throws RepositoryException
+ {
+ Session session1 = repository.login(new CredentialsImpl("root",
"exo".toCharArray()), "ws");
+ NodeImpl nodeToLockSession1 =
+
(NodeImpl)session1.getRootNode().getNode("rootLockPermissionsTest").addNode("testUnlock");
+ nodeToLockSession1.addMixin("mix:lockable");
+ nodeToLockSession1.addMixin("exo:owneable");
+ nodeToLockSession1.addMixin("exo:privilegeable");
+
+ // change permission
+ HashMap<String, String[]> perm = new HashMap<String, String[]>();
+ perm.put("john", new String[]{PermissionType.READ});
+ nodeToLockSession1.setPermissions(perm);
+ session1.save();
+
+ Lock lock = nodeToLockSession1.lock(true, 100000);
+ assertTrue(nodeToLockSession1.isLocked());
+
+ Session session2 = repository.login(new CredentialsImpl("john",
"exo".toCharArray()), "ws");
+ session2.checkPermission(nodeToLockSession1.getPath(), PermissionType.READ);
+ try
+ {
+ session2.checkPermission(nodeToLockSession1.getPath(),
PermissionType.SET_PROPERTY);
+ fail("AccessControlException should have been thrown ");
+ }
+ catch (AccessControlException e)
+ {
+ //ok
+ }
+
+ NodeImpl nodeToLockSession2 =
+
(NodeImpl)session2.getRootNode().getNode("rootLockPermissionsTest").getNode("testUnlock");
+ assertTrue(nodeToLockSession2.isLocked());
+ try
+ {
+ try
+ {
+ session2.addLockToken(lock.getLockToken());
+
+ // trying to unlock
+ nodeToLockSession2.unlock();
+ fail("Node locked. An AccessDeniedException should be thrown on set
property but doesn't");
+ }
+ catch (AccessDeniedException e)
+ {
+ // ok
+ }
+ }
+ finally
+ {
+ if (nodeToLockSession1.isLocked())
+ {
+ nodeToLockSession1.unlock();
+ }
+ session1.logout();
+ session2.logout();
+ }
+ }
+
+}