Author: angela
Date: Fri Oct 26 17:15:56 2012
New Revision: 1402583
URL: http://svn.apache.org/viewvc?rev=1402583&view=rev
Log:
OAK-250 : Enforce jcr constraints for 'protected' items (WIP)
Modified:
jackrabbit/oak/trunk/oak-jcr/pom.xml
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableTest.java
Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1402583&r1=1402582&r2=1402583&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Fri Oct 26 17:15:56 2012
@@ -45,8 +45,6 @@
org.apache.jackrabbit.test.api.NodeTest#testAddNodeConstraintViolationExceptionUndefinedNodeType<!--OAK-66-->
org.apache.jackrabbit.test.api.NodeTest#testRemoveMandatoryNode<!--OAK-66-->
org.apache.jackrabbit.test.api.NodeTest#testRefreshInvalidItemStateException<!--OAK-141-->
-
org.apache.jackrabbit.test.api.NodeTest#testPrimaryTypeProtected<!--OAK-66-->
-
org.apache.jackrabbit.test.api.NodeTest#testMixinTypesProtected<!--OAK-66-->
org.apache.jackrabbit.test.api.NodeTest#testRemoveNodeLockedItself
org.apache.jackrabbit.test.api.NodeTest#testRemoveNodeParentLocked
org.apache.jackrabbit.test.api.NodeUUIDTest#testSaveReferentialIntegrityException<!--OAK-66-->
@@ -267,13 +265,6 @@
org.apache.jackrabbit.oak.jcr.security.user.GroupTest#testCyclicGroups
<!-- OAK-343 -->
org.apache.jackrabbit.oak.jcr.security.user.AuthorizableTest#testRemoveListedAuthorizable
<!-- OAK-343 -->
org.apache.jackrabbit.oak.jcr.security.user.AuthorizableTest#testSetPropertyInvalidRelativePath
<!-- OAK-369 -->
-
org.apache.jackrabbit.oak.jcr.security.user.AuthorizableTest#testSetSpecialProperties
<!-- OAK-250 -->
-
org.apache.jackrabbit.oak.jcr.security.user.AuthorizableTest#testRemoveSpecialProperties
<!-- OAK-250 -->
-
org.apache.jackrabbit.oak.jcr.security.user.AuthorizableTest#testProtectedUserProperties
<!-- OAK-250 -->
-
org.apache.jackrabbit.oak.jcr.security.user.AuthorizableTest#testProtectedGroupProperties
<!-- OAK-250 -->
-
org.apache.jackrabbit.oak.jcr.security.user.AuthorizableTest#testSetSpecialPropertiesDirectly
<!-- OAK-250 -->
-
org.apache.jackrabbit.oak.jcr.security.user.AuthorizableTest#testRemoveSpecialUserPropertiesDirectly
<!-- OAK-250 -->
-
org.apache.jackrabbit.oak.jcr.security.user.AuthorizableTest#testRemoveSpecialGroupPropertiesDirectly
<!-- OAK-250 -->
org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testGetPrincipals
<!-- principal search missing -->
org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testGetGroupPrincipals
<!-- principal search missing -->
org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testGetAllPrincipals
<!-- principal search missing -->
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java?rev=1402583&r1=1402582&r2=1402583&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
Fri Oct 26 17:15:56 2012
@@ -19,22 +19,27 @@ package org.apache.jackrabbit.oak.jcr;
import java.util.Arrays;
import java.util.Map;
import java.util.Queue;
-
import javax.annotation.Nonnull;
import javax.jcr.InvalidItemStateException;
import javax.jcr.Item;
import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.ValueFactory;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.ItemDefinition;
import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Queues;
import org.apache.jackrabbit.commons.AbstractItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Queues;
+import static javax.jcr.PropertyType.UNDEFINED;
/**
* {@code ItemImpl}...
@@ -185,6 +190,52 @@ abstract class ItemImpl<T extends ItemDe
return types.values();
}
+ // FIXME: move to node type utility (oak-nodetype-plugin)
+ protected static PropertyDefinition getPropertyDefinition(Node parent,
+ String propName,
+ boolean
isMultiple,
+ int type,
+ boolean
exactTypeMatch) throws RepositoryException {
+ // TODO: This may need to be optimized
+ for (NodeType nt : getAllNodeTypes(parent)) {
+ for (PropertyDefinition def : nt.getDeclaredPropertyDefinitions())
{
+ String defName = def.getName();
+ int defType = def.getRequiredType();
+ if (propName.equals(defName)
+ && isMultiple == def.isMultiple()
+ &&(!exactTypeMatch || (type == defType || UNDEFINED ==
type || UNDEFINED == defType))) {
+ return def;
+ }
+ }
+ }
+
+ // try if there is a residual definition
+ for (NodeType nt : getAllNodeTypes(parent)) {
+ for (PropertyDefinition def : nt.getDeclaredPropertyDefinitions())
{
+ String defName = def.getName();
+ int defType = def.getRequiredType();
+ if ("*".equals(defName)
+ && isMultiple == def.isMultiple()
+ && (!exactTypeMatch || (type == defType || UNDEFINED
== type || UNDEFINED == defType))) {
+ return def;
+ }
+ }
+ }
+
+ // FIXME: Shouldn't be needed
+ for (NodeType nt : getAllNodeTypes(parent)) {
+ for (PropertyDefinition def : nt.getDeclaredPropertyDefinitions())
{
+ String defName = def.getName();
+ if ((propName.equals(defName) || "*".equals(defName))
+ && type == PropertyType.STRING
+ && isMultiple == def.isMultiple()) {
+ return def;
+ }
+ }
+ }
+ throw new RepositoryException("No matching property definition found
for " + propName);
+ }
+
/**
* Performs a sanity check on this item and the associated session.
@@ -204,6 +255,17 @@ abstract class ItemImpl<T extends ItemDe
// TODO: validate item state.
}
+ void checkProtected() throws RepositoryException {
+ ItemDefinition definition = (isNode()) ? ((Node) this).getDefinition()
: ((Property) this).getDefinition();
+ checkProtected(definition);
+ }
+
+ void checkProtected(ItemDefinition definition) throws RepositoryException {
+ if (definition.isProtected()) {
+ throw new ConstraintViolationException("Item is protected.");
+ }
+ }
+
/**
* Ensure that the associated session has no pending changes and throw an
* exception otherwise.
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1402583&r1=1402582&r2=1402583&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Fri Oct 26 17:15:56 2012
@@ -45,6 +45,7 @@ import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
import javax.jcr.lock.Lock;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -173,6 +174,7 @@ public class NodeImpl extends ItemImpl<N
@Override
public void remove() throws RepositoryException {
checkStatus();
+ checkProtected();
sessionDelegate.perform(new SessionOperation<Void>() {
@Override
@@ -211,6 +213,7 @@ public class NodeImpl extends ItemImpl<N
@Nonnull
public Node addNode(final String relPath, final String
primaryNodeTypeName) throws RepositoryException {
checkStatus();
+ checkProtected();
return sessionDelegate.perform(new SessionOperation<Node>() {
@Override
@@ -260,7 +263,7 @@ public class NodeImpl extends ItemImpl<N
}
NodeImpl childNode = new NodeImpl(added);
- childNode.setPrimaryType(ntName);
+ childNode.internalSetPrimaryType(ntName);
childNode.autoCreateItems();
return childNode;
}
@@ -270,6 +273,7 @@ public class NodeImpl extends ItemImpl<N
@Override
public void orderBefore(final String srcChildRelPath, final String
destChildRelPath) throws RepositoryException {
checkStatus();
+ checkProtected();
sessionDelegate.perform(new SessionOperation<Void>() {
@Override
@@ -297,7 +301,7 @@ public class NodeImpl extends ItemImpl<N
if (value != null) {
type = value.getType();
}
- return setProperty(name, value, type);
+ return internalSetProperty(name, value, type, false);
}
/**
@@ -305,26 +309,9 @@ public class NodeImpl extends ItemImpl<N
*/
@Override
@Nonnull
- public Property setProperty(final String jcrName, final Value value, final
int type)
+ public Property setProperty(String name, Value value, int type)
throws RepositoryException {
- checkStatus();
-
- return sessionDelegate.perform(new SessionOperation<Property>() {
- @Override
- public Property perform() throws RepositoryException {
- if (value == null) {
- Property property = getProperty(jcrName);
- property.remove();
- return property;
- } else {
- String oakName =
sessionDelegate.getOakPathOrThrow(jcrName);
- int targetType = getTargetType(value, type);
- Value targetValue =
- ValueHelper.convert(value, targetType,
getValueFactory());
- return new PropertyImpl(dlg.setProperty(oakName,
targetValue));
- }
- }
- });
+ return internalSetProperty(name, value, type, type !=
PropertyType.UNDEFINED);
}
/**
@@ -339,33 +326,13 @@ public class NodeImpl extends ItemImpl<N
} else {
type = values[0].getType();
}
- return setProperty(name, values, type);
+ return internalSetProperty(name, values, type, false);
}
@Override
@Nonnull
- public Property setProperty(final String jcrName, final Value[] values,
final int type) throws RepositoryException {
- checkStatus();
-
- return sessionDelegate.perform(new SessionOperation<Property>() {
- @Override
- public Property perform() throws RepositoryException {
- int targetType = getTargetType(values, type);
- Value[] targetValues = ValueHelper.convert(values, targetType,
getValueFactory());
- if (targetValues == null) {
- Property p = getProperty(jcrName);
- p.remove();
- return p;
- } else {
- String oakName =
sessionDelegate.getOakPathOrThrow(jcrName);
- Iterable<Value> nonNullValues = Iterables.filter(
- Arrays.asList(targetValues),
- Predicates.notNull());
-
- return new PropertyImpl(dlg.setProperty(oakName,
nonNullValues));
- }
- }
- });
+ public Property setProperty(String jcrName, Value[] values, int type)
throws RepositoryException {
+ return internalSetProperty(jcrName, values, type, true);
}
/**
@@ -389,7 +356,7 @@ public class NodeImpl extends ItemImpl<N
} else {
vs = ValueHelper.convert(values, type, getValueFactory());
}
- return setProperty(name, vs, type);
+ return internalSetProperty(name, vs, type, (type !=
PropertyType.UNDEFINED));
}
/**
@@ -399,7 +366,7 @@ public class NodeImpl extends ItemImpl<N
@CheckForNull
public Property setProperty(String name, String value) throws
RepositoryException {
Value v = (value == null) ? null :
getValueFactory().createValue(value, PropertyType.STRING);
- return setProperty(name, v, PropertyType.UNDEFINED);
+ return internalSetProperty(name, v, PropertyType.UNDEFINED, false);
}
/**
@@ -409,7 +376,7 @@ public class NodeImpl extends ItemImpl<N
@CheckForNull
public Property setProperty(String name, String value, int type) throws
RepositoryException {
Value v = (value == null) ? null :
getValueFactory().createValue(value, type);
- return setProperty(name, v, type);
+ return internalSetProperty(name, v, type, true);
}
/**
@@ -907,29 +874,15 @@ public class NodeImpl extends ItemImpl<N
@Override
public void setPrimaryType(final String nodeTypeName) throws
RepositoryException {
checkStatus();
+ checkProtected();
- sessionDelegate.perform(new SessionOperation<Void>() {
- @Override
- public Void perform() throws RepositoryException {
- // TODO: figure out the right place for this check
- NodeTypeManager ntm = sessionDelegate.getNodeTypeManager();
- NodeType nt = ntm.getNodeType(nodeTypeName); // throws on not
found
- if (nt.isAbstract() || nt.isMixin()) {
- throw new ConstraintViolationException();
- }
- // TODO: END
-
- String jcrPrimaryType =
sessionDelegate.getOakPathOrThrow(Property.JCR_PRIMARY_TYPE);
- Value value =
sessionDelegate.getValueFactory().createValue(nodeTypeName, PropertyType.NAME);
- dlg.setProperty(jcrPrimaryType, value);
- return null;
- }
- });
+ internalSetPrimaryType(nodeTypeName);
}
@Override
public void addMixin(final String mixinName) throws RepositoryException {
checkStatus();
+ checkProtected();
sessionDelegate.perform(new SessionOperation<Void>() {
@Override
@@ -966,6 +919,7 @@ public class NodeImpl extends ItemImpl<N
@Override
public void removeMixin(final String mixinName) throws RepositoryException
{
checkStatus();
+ checkProtected();
sessionDelegate.perform(new SessionOperation<Void>() {
@Override
@@ -1331,12 +1285,12 @@ public class NodeImpl extends ItemImpl<N
@Override
public void removeSharedSet() throws RepositoryException {
- // TODO
+ throw new UnsupportedRepositoryOperationException("TODO:
Node.removeSharedSet");
}
@Override
public void removeShare() throws RepositoryException {
- // TODO
+ throw new UnsupportedRepositoryOperationException("TODO:
Node.removeShare");
}
/**
@@ -1381,21 +1335,26 @@ public class NodeImpl extends ItemImpl<N
});
}
- private static int getTargetType(Value value, int type) {
- if (value == null) {
- return PropertyType.STRING; // TODO: review again. rather use
- // property definition
- } else {
+ private static int getTargetType(Value value, PropertyDefinition
definition) {
+ if (definition.getRequiredType() == PropertyType.UNDEFINED) {
return value.getType();
+ } else {
+ return definition.getRequiredType();
}
}
- private static int getTargetType(Value[] values, int type) {
- if (values == null || values.length == 0) {
- return PropertyType.STRING; // TODO: review again. rather use
property definition
+ private static int getTargetType(Value[] values, PropertyDefinition
definition) {
+ if (definition.getRequiredType() == PropertyType.UNDEFINED) {
+ if (values.length != 0) {
+ for (Value v : values) {
+ if (v != null) {
+ return v.getType();
+ }
+ }
+ }
+ return PropertyType.STRING;
} else {
- // TODO deal with values array containing a null value in the
first position
- return getTargetType(values[0], type);
+ return definition.getRequiredType();
}
}
@@ -1501,4 +1460,97 @@ public class NodeImpl extends ItemImpl<N
}
throw new NoSuchWorkspaceException(workspaceName + " does not exist.");
}
+
+ private void internalSetPrimaryType(final String nodeTypeName) throws
RepositoryException {
+ sessionDelegate.perform(new SessionOperation<Void>() {
+ @Override
+ public Void perform() throws RepositoryException {
+ // TODO: figure out the right place for this check
+ NodeTypeManager ntm = sessionDelegate.getNodeTypeManager();
+ NodeType nt = ntm.getNodeType(nodeTypeName); // throws on not
found
+ if (nt.isAbstract() || nt.isMixin()) {
+ throw new ConstraintViolationException();
+ }
+ // TODO: END
+
+ String jcrPrimaryType =
sessionDelegate.getOakPathOrThrow(Property.JCR_PRIMARY_TYPE);
+ Value value =
sessionDelegate.getValueFactory().createValue(nodeTypeName, PropertyType.NAME);
+ dlg.setProperty(jcrPrimaryType, value);
+ return null;
+ }
+ });
+ }
+
+ private Property internalSetProperty(final String jcrName, final Value
value,
+ final int type, final boolean
exactTypeMatch) throws RepositoryException {
+ checkStatus();
+ checkProtected();
+
+ return sessionDelegate.perform(new SessionOperation<Property>() {
+ @Override
+ public Property perform() throws RepositoryException {
+ if (value == null) {
+ Property property = getProperty(jcrName);
+ property.remove();
+ return property;
+ } else {
+ String oakName =
sessionDelegate.getOakPathOrThrow(jcrName);
+
+ PropertyDefinition definition;
+ if (hasProperty(jcrName)) {
+ definition = getProperty(jcrName).getDefinition();
+ } else {
+ definition = getPropertyDefinition(NodeImpl.this,
oakName, false, type, exactTypeMatch);
+ }
+ checkProtected(definition);
+ if (definition.isMultiple()) {
+ throw new ValueFormatException("Cannot set single
value to multivalued property");
+ }
+
+ int targetType = getTargetType(value, definition);
+ Value targetValue = ValueHelper.convert(value, targetType,
getValueFactory());
+
+ return new PropertyImpl(dlg.setProperty(oakName,
targetValue));
+ }
+ }
+ });
+ }
+
+ private Property internalSetProperty(final String jcrName, final Value[]
values,
+ final int type, final boolean
exactTypeMatch) throws RepositoryException {
+ checkStatus();
+ checkProtected();
+
+ return sessionDelegate.perform(new SessionOperation<Property>() {
+ @Override
+ public Property perform() throws RepositoryException {
+ if (values == null) {
+ Property p = getProperty(jcrName);
+ p.remove();
+ return p;
+ } else {
+ String oakName =
sessionDelegate.getOakPathOrThrow(jcrName);
+
+ PropertyDefinition definition;
+ if (hasProperty(jcrName)) {
+ definition = getProperty(jcrName).getDefinition();
+ } else {
+ definition = getPropertyDefinition(NodeImpl.this,
oakName, true, type, exactTypeMatch);
+ }
+ checkProtected(definition);
+ if (!definition.isMultiple()) {
+ throw new ValueFormatException("Cannot set value array
to single value property");
+ }
+
+ int targetType = getTargetType(values, definition);
+ Value[] targetValues = ValueHelper.convert(values,
targetType, getValueFactory());
+
+ Iterable<Value> nonNullValues = Iterables.filter(
+ Arrays.asList(targetValues),
+ Predicates.notNull());
+ return new PropertyImpl(dlg.setProperty(oakName,
nonNullValues));
+ }
+ }
+ });
+ }
}
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java?rev=1402583&r1=1402582&r2=1402583&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
Fri Oct 26 17:15:56 2012
@@ -35,7 +35,6 @@ import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
-import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.PropertyDefinition;
import com.google.common.base.Predicates;
@@ -131,6 +130,7 @@ public class PropertyImpl extends ItemIm
@Override
public void remove() throws RepositoryException {
checkStatus();
+ checkProtected();
sessionDelegate.perform(new SessionOperation<Void>() {
@Override
@@ -550,7 +550,6 @@ public class PropertyImpl extends ItemIm
@Override
@Nonnull
public PropertyDefinition getDefinition() throws RepositoryException {
- String name = getName();
int type = UNDEFINED;
if (isMultiple()) {
Value[] values = getValues();
@@ -561,46 +560,7 @@ public class PropertyImpl extends ItemIm
type = getValue().getType();
}
- // TODO: This may need to be optimized
- List<PropertyDefinition> residualDefs = new
ArrayList<PropertyDefinition>();
- for (NodeType nt : getAllNodeTypes(getParent())) {
- for (PropertyDefinition def : nt.getDeclaredPropertyDefinitions())
{
- String defName = def.getName();
- int defType = def.getRequiredType();
- if ((name.equals(defName))
- && (type == defType || UNDEFINED == type || UNDEFINED
== defType)
- && isMultiple() == def.isMultiple()) {
- return def;
- } else if ("*".equals(defName)) {
- residualDefs.add(def);
- }
- }
- }
-
- for (PropertyDefinition def : residualDefs) {
- String defName = def.getName();
- int defType = def.getRequiredType();
- if (("*".equals(defName))
- && (type == defType || UNDEFINED == type || UNDEFINED ==
defType)
- && isMultiple() == def.isMultiple()) {
- return def;
- }
- }
-
- // FIXME: Shouldn't be needed
- for (NodeType nt : getAllNodeTypes(getParent())) {
- for (PropertyDefinition def : nt.getDeclaredPropertyDefinitions())
{
- String defName = def.getName();
- if ((name.equals(defName) || "*".equals(defName))
- && type == PropertyType.STRING
- && isMultiple() == def.isMultiple()) {
- return def;
- }
- }
- }
-
- throw new RepositoryException(
- "No matching property definition found for " + this);
+ return getPropertyDefinition(getParent(), getName(), isMultiple(),
type, true);
}
/**
@@ -680,6 +640,7 @@ public class PropertyImpl extends ItemIm
*/
private void setValue(Value value, int requiredType) throws
RepositoryException {
checkArgument(requiredType != PropertyType.UNDEFINED);
+ checkProtected();
// TODO check again if definition validation should be respected here.
if (isMultiple()) {
@@ -700,6 +661,7 @@ public class PropertyImpl extends ItemIm
*/
private void setValues(Value[] values, int requiredType) throws
RepositoryException {
checkArgument(requiredType != PropertyType.UNDEFINED);
+ checkProtected();
// TODO check again if definition validation should be respected here.
if (!isMultiple()) {
Modified:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableTest.java?rev=1402583&r1=1402582&r2=1402583&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableTest.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableTest.java
Fri Oct 26 17:15:56 2012
@@ -19,9 +19,11 @@ package org.apache.jackrabbit.oak.jcr.se
import java.security.Principal;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.Property;
@@ -47,19 +49,19 @@ import org.junit.Test;
*/
public class AuthorizableTest extends AbstractUserTest {
- private List<String> protectedUserProps = new ArrayList<String>();
- private List<String> protectedGroupProps = new ArrayList<String>();
+ private Map<String, Boolean> protectedUserProps = new HashMap<String,
Boolean>();
+ private Map<String, Boolean> protectedGroupProps = new HashMap<String,
Boolean>();
@Override
protected void setUp() throws Exception {
super.setUp();
- protectedUserProps.add(UserConstants.REP_PASSWORD);
- protectedUserProps.add(UserConstants.REP_IMPERSONATORS);
- protectedUserProps.add(UserConstants.REP_PRINCIPAL_NAME);
+ protectedUserProps.put(UserConstants.REP_PASSWORD, false);
+ protectedUserProps.put(UserConstants.REP_IMPERSONATORS, true);
+ protectedUserProps.put(UserConstants.REP_PRINCIPAL_NAME, false);
- protectedUserProps.add(UserConstants.REP_MEMBERS);
- protectedGroupProps.add(UserConstants.REP_PRINCIPAL_NAME);
+ protectedGroupProps.put(UserConstants.REP_MEMBERS, true);
+ protectedGroupProps.put(UserConstants.REP_PRINCIPAL_NAME, false);
}
private static void checkProtected(Property prop) throws
RepositoryException {
@@ -423,9 +425,14 @@ public class AuthorizableTest extends Ab
public void testSetSpecialProperties() throws NotExecutableException,
RepositoryException {
Value v = superuser.getValueFactory().createValue("any_value");
- for (String pName : protectedUserProps) {
+ for (String pName : protectedUserProps.keySet()) {
try {
- user.setProperty(pName, v);
+ boolean isMultiValued = protectedUserProps.get(pName);
+ if (isMultiValued) {
+ user.setProperty(pName, new Value[] {v});
+ } else {
+ user.setProperty(pName, v);
+ }
superuser.save();
fail("changing the '" + pName + "' property on a User should
fail.");
} catch (RepositoryException e) {
@@ -435,9 +442,14 @@ public class AuthorizableTest extends Ab
}
}
- for (String pName : protectedGroupProps) {
+ for (String pName : protectedGroupProps.keySet()) {
try {
- group.setProperty(pName, v);
+ boolean isMultiValued = protectedGroupProps.get(pName);
+ if (isMultiValued) {
+ group.setProperty(pName, new Value[] {v});
+ } else {
+ group.setProperty(pName, v);
+ }
superuser.save();
fail("changing the '" + pName + "' property on a Group should
fail.");
} catch (RepositoryException e) {
@@ -450,22 +462,24 @@ public class AuthorizableTest extends Ab
@Test
public void testRemoveSpecialProperties() throws NotExecutableException,
RepositoryException {
- for (String pName : protectedUserProps) {
+ for (String pName : protectedUserProps.keySet()) {
try {
- user.removeProperty(pName);
- superuser.save();
- fail("removing the '" + pName + "' property on a User should
fail.");
+ if (user.removeProperty(pName)) {
+ superuser.save();
+ fail("removing the '" + pName + "' property on a User
should fail.");
+ } // else: property not present: fine as well.
} catch (RepositoryException e) {
// success
} finally {
superuser.refresh(false);
}
}
- for (String pName : protectedGroupProps) {
+ for (String pName : protectedGroupProps.keySet()) {
try {
- group.removeProperty(pName);
- superuser.save();
- fail("removing the '" + pName + "' property on a Group should
fail.");
+ if (group.removeProperty(pName)) {
+ superuser.save();
+ fail("removing the '" + pName + "' property on a Group
should fail.");
+ } // else: property not present. fine as well.
} catch (RepositoryException e) {
// success
} finally {