Author: angela
Date: Tue May 16 07:46:44 2017
New Revision: 1795274
URL: http://svn.apache.org/viewvc?rev=1795274&view=rev
Log:
OAK-6093 : Find a new home for NodeUtil and TreeUtil including cleanup
Step 1: extend TreeUtil to cover commonly used functionality from NodeUtil
Step 2: replace usage of NodeUtil by TreeUtil in non-test code
Step 3: move NodeUtil to test-code, where it is mainly used
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/Utils.java
(with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UtilsTest.java
- copied, changed from r1795151,
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/NodeUtilTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/NodeUtil.java
- copied, changed from r1795151,
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
Removed:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
Modified:
jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalIdentityRepositoryInitializer.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/PasswordHistory.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserPrincipalProvider.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexQueryTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProviderTest.java
Modified:
jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalIdentityRepositoryInitializer.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalIdentityRepositoryInitializer.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalIdentityRepositoryInitializer.java
(original)
+++
jackrabbit/oak/trunk/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalIdentityRepositoryInitializer.java
Tue May 16 07:46:44 2017
@@ -22,6 +22,8 @@ import javax.jcr.RepositoryException;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
@@ -36,11 +38,11 @@ import org.apache.jackrabbit.oak.spi.sta
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
-import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.apache.jackrabbit.oak.util.TreeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
/**
* Implementation of the {@code RepositoryInitializer} interface responsible
for
@@ -79,19 +81,20 @@ class ExternalIdentityRepositoryInitiali
null, null, null, null);
// create index definition for "rep:externalId" and
"rep:externalPrincipalNames"
- NodeUtil rootTree = checkNotNull(new NodeUtil(root.getTree("/")));
- NodeUtil index =
rootTree.getOrAddChild(IndexConstants.INDEX_DEFINITIONS_NAME,
JcrConstants.NT_UNSTRUCTURED);
+ Tree rootTree = root.getTree(PathUtils.ROOT_PATH);
+ checkState(rootTree.exists());
+ Tree index = TreeUtil.getOrAddChild(rootTree,
IndexConstants.INDEX_DEFINITIONS_NAME, JcrConstants.NT_UNSTRUCTURED);
if (enforceUniqueIds && !index.hasChild("externalId")) {
- NodeUtil definition = IndexUtils.createIndexDefinition(index,
"externalId", true,
- new
String[]{ExternalIdentityConstants.REP_EXTERNAL_ID}, null);
- definition.setString("info", "Oak index assuring uniqueness of
rep:externalId properties.");
+ Tree definition = IndexUtils.createIndexDefinition(index,
"externalId", true,
+ new
String[]{ExternalIdentityConstants.REP_EXTERNAL_ID});
+ definition.setProperty("info", "Oak index assuring uniqueness
of rep:externalId properties.");
}
if (!index.hasChild("externalPrincipalNames")) {
- NodeUtil definition = IndexUtils.createIndexDefinition(index,
"externalPrincipalNames", false,
- new
String[]{ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES}, null);
- definition.setString("info", "Oak index used by the principal
management provided by the external authentication module.");
+ Tree definition = IndexUtils.createIndexDefinition(index,
"externalPrincipalNames", false,
+ new
String[]{ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES});
+ definition.setProperty("info", "Oak index used by the
principal management provided by the external authentication module.");
}
if (root.hasPendingChanges()) {
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
Tue May 16 07:46:44 2017
@@ -32,24 +32,30 @@ import static org.apache.jackrabbit.oak.
import java.util.Collection;
import java.util.Map;
+import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.jcr.RepositoryException;
+import com.google.common.collect.ImmutableList;
import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import
org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider;
import
org.apache.jackrabbit.oak.plugins.index.reference.NodeReferenceConstants;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.apache.jackrabbit.oak.util.TreeUtil;
/**
* TODO document
*/
public class IndexUtils {
+ private IndexUtils() {
+ }
+
public static NodeBuilder getOrCreateOakIndex(NodeBuilder root) {
NodeBuilder index;
if (!root.hasChildNode(INDEX_DEFINITIONS_NAME)) {
@@ -103,34 +109,52 @@ public class IndexUtils {
* @param propertyNames
* @param declaringNodeTypeNames
*/
- public static NodeUtil createIndexDefinition(@Nonnull NodeUtil indexNode,
+ public static Tree createIndexDefinition(@Nonnull Tree indexNode,
@Nonnull String indexDefName,
boolean unique,
@Nonnull String[] propertyNames,
- @Nullable String[]
declaringNodeTypeNames) throws RepositoryException {
+ @Nonnull String...
declaringNodeTypeNames) throws RepositoryException {
- return createIndexDefinition(indexNode, indexDefName, unique,
propertyNames, declaringNodeTypeNames, PropertyIndexEditorProvider.TYPE);
+ return createIndexDefinition(indexNode, indexDefName, unique,
ImmutableList.copyOf(propertyNames),
ImmutableList.copyOf(declaringNodeTypeNames), PropertyIndexEditorProvider.TYPE,
null);
}
/**
- * Create a new property index definition below the given {@code
indexNode} of the provided {@code propertyIndexType}.
- *
+ * Create a new property index definition below the given {@code
indexNode} of the provided
+ * {@code propertyIndexType}.
+ *
* @param indexNode
* @param indexDefName
* @param unique
* @param propertyNames
* @param declaringNodeTypeNames
* @param propertyIndexType
+ * @param properties any additional property to be added to the index
definition.
* @throws RepositoryException
*/
- public static NodeUtil createIndexDefinition(@Nonnull NodeUtil indexNode,
- @Nonnull String indexDefName,
- boolean unique,
- @Nonnull String[] propertyNames,
- @Nullable String[]
declaringNodeTypeNames,
- @Nonnull String
propertyIndexType) throws RepositoryException {
- return createIndexDefinition(indexNode, indexDefName, unique,
propertyNames,
- declaringNodeTypeNames, propertyIndexType, null);
+ public static Tree createIndexDefinition(@Nonnull Tree indexNode,
+ @Nonnull String indexDefName,
+ boolean unique,
+ @Nonnull Collection<String>
propertyNames,
+ @CheckForNull Collection<String>
declaringNodeTypeNames,
+ @Nonnull String propertyIndexType,
+ @CheckForNull Map<String, String>
properties) throws RepositoryException {
+ Tree entry = TreeUtil.getOrAddChild(indexNode, indexDefName,
INDEX_DEFINITIONS_NODE_TYPE);
+ entry.setProperty(TYPE_PROPERTY_NAME, propertyIndexType);
+ entry.setProperty(REINDEX_PROPERTY_NAME, true);
+ if (unique) {
+ entry.setProperty(UNIQUE_PROPERTY_NAME, true);
+ }
+ if (declaringNodeTypeNames != null && declaringNodeTypeNames.size() >
0) {
+ entry.setProperty(DECLARING_NODE_TYPES, declaringNodeTypeNames,
Type.NAMES);
+ }
+ entry.setProperty(PROPERTY_NAMES, propertyNames, Type.NAMES);
+
+ if (properties != null) {
+ for (String k : properties.keySet()) {
+ entry.setProperty(k, properties.get(k));
+ }
+ }
+ return entry;
}
public static void createReferenceIndex(@Nonnull NodeBuilder index) {
@@ -156,45 +180,6 @@ public class IndexUtils {
}
/**
- * Create a new property index definition below the given {@code
indexNode} of the provided
- * {@code propertyIndexType}.
- *
- * @param indexNode
- * @param indexDefName
- * @param unique
- * @param propertyNames
- * @param declaringNodeTypeNames
- * @param propertyIndexType
- * @param properties any additional property to be added to the index
definition.
- * @throws RepositoryException
- */
- public static NodeUtil createIndexDefinition(@Nonnull NodeUtil indexNode,
- @Nonnull String indexDefName,
- boolean unique,
- @Nonnull String[] propertyNames,
- @Nullable String[]
declaringNodeTypeNames,
- @Nonnull String propertyIndexType,
- Map<String, String> properties)
throws RepositoryException {
- NodeUtil entry = indexNode.getOrAddChild(indexDefName,
INDEX_DEFINITIONS_NODE_TYPE);
- entry.setString(TYPE_PROPERTY_NAME, propertyIndexType);
- entry.setBoolean(REINDEX_PROPERTY_NAME, true);
- if (unique) {
- entry.setBoolean(UNIQUE_PROPERTY_NAME, true);
- }
- if (declaringNodeTypeNames != null && declaringNodeTypeNames.length >
0) {
- entry.setNames(DECLARING_NODE_TYPES, declaringNodeTypeNames);
- }
- entry.setNames(PROPERTY_NAMES, propertyNames);
-
- if (properties != null) {
- for (String k : properties.keySet()) {
- entry.setString(k, properties.get(k));
- }
- }
- return entry;
- }
-
- /**
* Create a new property index definition below the given {@code
indexNode} of the provided
* {@code propertyIndexType}.
*
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java
Tue May 16 07:46:44 2017
@@ -57,13 +57,13 @@ import org.apache.jackrabbit.oak.spi.sec
import
org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider;
import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
import org.apache.jackrabbit.oak.spi.security.user.util.PasswordUtil;
-import org.apache.jackrabbit.oak.util.NodeUtil;
import org.apache.jackrabbit.oak.util.TreeUtil;
import org.apache.jackrabbit.util.ISO8601;
import org.apache.jackrabbit.util.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.jackrabbit.oak.api.Type.DATE;
import static org.apache.jackrabbit.oak.api.Type.STRING;
import static
org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager.getIdentifier;
@@ -199,7 +199,7 @@ class TokenProviderImpl implements Token
public TokenInfo createToken(@Nonnull String userId, @Nonnull Map<String,
?> attributes) {
String error = "Failed to create login token. {}";
User user = getUser(userId);
- NodeUtil tokenParent = (user == null) ? null : getTokenParent(user);
+ Tree tokenParent = (user == null) ? null : getTokenParent(user);
if (tokenParent != null) {
try {
String id = user.getID();
@@ -258,7 +258,7 @@ class TokenProviderImpl implements Token
try {
User user = getUser(tokenTree);
if (user != null) {
- return new TokenInfoImpl(new NodeUtil(tokenTree), token,
user.getID(), user.getPrincipal());
+ return new TokenInfoImpl(tokenTree, token, user.getID(),
user.getPrincipal());
}
} catch (RepositoryException e) {
log.debug("Cannot determine userID/principal from token: {}",
e.getMessage());
@@ -273,8 +273,14 @@ class TokenProviderImpl implements Token
return creationTime + tokenExpiration;
}
- private static long getExpirationTime(NodeUtil tokenNode, long
defaultValue) {
- return tokenNode.getLong(TOKEN_ATTRIBUTE_EXPIRY, defaultValue);
+ private static long getExpirationTime(@Nonnull Tree tokenTree, long
defaultValue) {
+ return TreeUtil.getLong(tokenTree, TOKEN_ATTRIBUTE_EXPIRY,
defaultValue);
+ }
+
+ private static void setExpirationTime(@Nonnull Tree tree, long time) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(time);
+ tree.setProperty(TOKEN_ATTRIBUTE_EXPIRY, ISO8601.format(calendar),
DATE);
}
@CheckForNull
@@ -359,15 +365,15 @@ class TokenProviderImpl implements Token
}
@CheckForNull
- private NodeUtil getTokenParent(@Nonnull User user) {
- NodeUtil tokenParent = null;
+ private Tree getTokenParent(@Nonnull User user) {
+ Tree tokenParent = null;
String parentPath = null;
try {
String userPath = user.getPath();
parentPath = userPath + '/' + TOKENS_NODE_NAME;
- NodeUtil userNode = new NodeUtil(root.getTree(userPath));
- tokenParent = userNode.getOrAddChild(TOKENS_NODE_NAME,
TOKENS_NT_NAME);
+ Tree userNode = root.getTree(userPath);
+ tokenParent = TreeUtil.getOrAddChild(userNode, TOKENS_NODE_NAME,
TOKENS_NT_NAME);
root.commit();
} catch (RepositoryException e) {
@@ -380,7 +386,7 @@ class TokenProviderImpl implements Token
root.refresh();
Tree parentTree = root.getTree(parentPath);
if (parentTree.exists()) {
- tokenParent = new NodeUtil(parentTree);
+ tokenParent = parentTree;
} else {
tokenParent = null;
}
@@ -401,26 +407,26 @@ class TokenProviderImpl implements Token
* new token node.
*
*/
- private TokenInfo createTokenNode(@Nonnull NodeUtil parent, @Nonnull
String tokenName,
+ private TokenInfo createTokenNode(@Nonnull Tree parent, @Nonnull String
tokenName,
long expTime, @Nonnull String uuid,
@Nonnull String id, Map<String, ?>
attributes)
throws AccessDeniedException, UnsupportedEncodingException,
NoSuchAlgorithmException {
- NodeUtil tokenNode = parent.addChild(tokenName, TOKEN_NT_NAME);
- tokenNode.setString(JcrConstants.JCR_UUID, uuid);
+ Tree tokenNode = TreeUtil.addChild(parent, tokenName, TOKEN_NT_NAME);
+ tokenNode.setProperty(JcrConstants.JCR_UUID, uuid);
String key = generateKey(options.getConfigValue(PARAM_TOKEN_LENGTH,
DEFAULT_KEY_SIZE));
- String nodeId = getIdentifier(tokenNode.getTree());
+ String nodeId = getIdentifier(tokenNode);
String token = nodeId + DELIM + key;
String keyHash = PasswordUtil.buildPasswordHash(getKeyValue(key, id),
options);
- tokenNode.setString(TOKEN_ATTRIBUTE_KEY, keyHash);
- tokenNode.setDate(TOKEN_ATTRIBUTE_EXPIRY, expTime);
+ tokenNode.setProperty(TOKEN_ATTRIBUTE_KEY, keyHash);
+ setExpirationTime(tokenNode, expTime);
for (String name : attributes.keySet()) {
if (!RESERVED_ATTRIBUTES.contains(name)) {
String attr = attributes.get(name).toString();
- tokenNode.setString(name, attr);
+ tokenNode.setProperty(name, attr);
}
}
return new TokenInfoImpl(tokenNode, token, id, null);
@@ -444,18 +450,18 @@ class TokenProviderImpl implements Token
private final Map<String, String> mandatoryAttributes;
private final Map<String, String> publicAttributes;
- private TokenInfoImpl(@Nonnull NodeUtil tokenNode, @Nonnull String
token, @Nonnull String userId, @Nullable Principal principal) {
+ private TokenInfoImpl(@Nonnull Tree tokenTree, @Nonnull String token,
@Nonnull String userId, @Nullable Principal principal) {
this.token = token;
- this.tokenPath = tokenNode.getTree().getPath();
+ this.tokenPath = tokenTree.getPath();
this.userId = userId;
this.principal = principal;
- expirationTime = getExpirationTime(tokenNode, Long.MIN_VALUE);
- key = tokenNode.getString(TOKEN_ATTRIBUTE_KEY, null);
+ expirationTime = getExpirationTime(tokenTree, Long.MIN_VALUE);
+ key = TreeUtil.getString(tokenTree, TOKEN_ATTRIBUTE_KEY);
mandatoryAttributes = new HashMap();
publicAttributes = new HashMap();
- for (PropertyState propertyState :
tokenNode.getTree().getProperties()) {
+ for (PropertyState propertyState : tokenTree.getProperties()) {
String name = propertyState.getName();
String value = propertyState.getValue(STRING);
if (RESERVED_ATTRIBUTES.contains(name)) {
@@ -500,7 +506,6 @@ class TokenProviderImpl implements Token
if (options.getConfigValue(PARAM_TOKEN_REFRESH, true)) {
Tree tokenTree = getTokenTree(this);
if (tokenTree.exists()) {
- NodeUtil tokenNode = new NodeUtil(tokenTree);
if (isExpired(loginTime)) {
log.debug("Attempt to reset an expired token.");
return false;
@@ -509,7 +514,7 @@ class TokenProviderImpl implements Token
if (expirationTime - loginTime <= tokenExpiration / 2) {
try {
long expTime = createExpirationTime(loginTime,
tokenExpiration);
- tokenNode.setDate(TOKEN_ATTRIBUTE_EXPIRY, expTime);
+ setExpirationTime(tokenTree, expTime);
root.commit(CommitMarker.asCommitAttributes());
log.debug("Successfully reset token expiration
time.");
return true;
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java
Tue May 16 07:46:44 2017
@@ -48,6 +48,7 @@ import javax.jcr.security.Privilege;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -90,7 +91,6 @@ import org.apache.jackrabbit.oak.spi.sec
import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits;
import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBitsProvider;
import org.apache.jackrabbit.oak.spi.xml.ImportBehavior;
-import org.apache.jackrabbit.oak.util.NodeUtil;
import org.apache.jackrabbit.oak.util.TreeUtil;
import org.apache.jackrabbit.util.ISO9075;
import org.apache.jackrabbit.util.Text;
@@ -307,11 +307,11 @@ public class AccessControlManagerImpl ex
String nodeName = Util.generateAceName(ace, i);
String ntName = (ace.isAllow()) ? NT_REP_GRANT_ACE :
NT_REP_DENY_ACE;
- NodeUtil aceNode = new NodeUtil(aclTree).addChild(nodeName,
ntName);
- aceNode.setString(REP_PRINCIPAL_NAME,
ace.getPrincipal().getName());
- aceNode.setNames(REP_PRIVILEGES,
AccessControlUtils.namesFromPrivileges(ace.getPrivileges()));
+ Tree aceNode = TreeUtil.addChild(aclTree, nodeName, ntName);
+ aceNode.setProperty(REP_PRINCIPAL_NAME,
ace.getPrincipal().getName());
+ aceNode.setProperty(REP_PRIVILEGES,
ImmutableList.copyOf(AccessControlUtils.namesFromPrivileges(ace.getPrivileges())),
Type.NAMES);
Set<Restriction> restrictions = ace.getRestrictions();
- restrictionProvider.writeRestrictions(oakPath, aceNode.getTree(),
restrictions);
+ restrictionProvider.writeRestrictions(oakPath, aceNode,
restrictions);
}
}
@@ -480,7 +480,7 @@ public class AccessControlManagerImpl ex
}
}
String aclName = Util.getAclName(oakPath);
- return new NodeUtil(tree).addChild(aclName, NT_REP_ACL).getTree();
+ return TreeUtil.addChild(tree, aclName, NT_REP_ACL);
}
@CheckForNull
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
Tue May 16 07:46:44 2017
@@ -20,18 +20,20 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Set;
import javax.annotation.Nonnull;
import javax.jcr.RepositoryException;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Type;
import
org.apache.jackrabbit.oak.spi.security.privilege.ImmutablePrivilegeDefinition;
import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits;
import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBitsProvider;
import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition;
-import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.apache.jackrabbit.oak.util.TreeUtil;
import static java.util.Arrays.asList;
@@ -100,12 +102,11 @@ class PrivilegeDefinitionWriter implemen
if (!privilegesTree.exists()) {
throw new RepositoryException("Privilege store does not
exist.");
}
- NodeUtil privilegesNode = new NodeUtil(privilegesTree);
for (PrivilegeDefinition definition : definitions) {
- if (privilegesNode.hasChild(definition.getName())) {
+ if (privilegesTree.hasChild(definition.getName())) {
throw new RepositoryException("Privilege definition with
name '" + definition.getName() + "' already exists.");
}
- writePrivilegeNode(privilegesNode, definition);
+ writePrivilegeNode(privilegesTree, definition);
}
/*
update the property storing the next privilege bits with the
@@ -122,16 +123,16 @@ class PrivilegeDefinitionWriter implemen
}
}
- private void writePrivilegeNode(NodeUtil privilegesNode,
PrivilegeDefinition definition) throws RepositoryException {
+ private void writePrivilegeNode(Tree privilegesTree, PrivilegeDefinition
definition) throws RepositoryException {
String name = definition.getName();
- NodeUtil privNode = privilegesNode.addChild(name, NT_REP_PRIVILEGE);
+ Tree privNode = TreeUtil.addChild(privilegesTree, name,
NT_REP_PRIVILEGE);
if (definition.isAbstract()) {
- privNode.setBoolean(REP_IS_ABSTRACT, true);
+ privNode.setProperty(REP_IS_ABSTRACT, true);
}
- String[] declAggrNames =
definition.getDeclaredAggregateNames().toArray(new
String[definition.getDeclaredAggregateNames().size()]);
- boolean isAggregate = declAggrNames.length > 0;
+ Set<String> declAggrNames = definition.getDeclaredAggregateNames();
+ boolean isAggregate = declAggrNames.size() > 0;
if (isAggregate) {
- privNode.setNames(REP_AGGREGATES, declAggrNames);
+ privNode.setProperty(REP_AGGREGATES, declAggrNames, Type.NAMES);
}
PrivilegeBits bits;
@@ -142,7 +143,7 @@ class PrivilegeDefinitionWriter implemen
} else {
bits = next();
}
- bits.writeTo(privNode.getTree());
+ bits.writeTo(privNode);
}
private static Collection<PrivilegeDefinition> getBuiltInDefinitions() {
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImpl.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImpl.java
Tue May 16 07:46:44 2017
@@ -32,14 +32,13 @@ import javax.jcr.nodetype.PropertyDefini
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.plugins.tree.TreeLocation;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
+import org.apache.jackrabbit.oak.plugins.tree.TreeLocation;
import org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl;
import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
-import org.apache.jackrabbit.oak.util.NodeUtil;
import org.apache.jackrabbit.util.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -273,7 +272,7 @@ class AuthorizablePropertiesImpl impleme
if (targetTree != null) {
checkScope(userPath, targetTree.getPath(), relPath);
} else {
- targetTree = new NodeUtil(userTree).getOrAddTree(relPath,
JcrConstants.NT_UNSTRUCTURED).getTree();
+ targetTree = Utils.getOrAddTree(userTree, relPath,
JcrConstants.NT_UNSTRUCTURED);
checkScope(userPath, targetTree.getPath(), relPath);
}
} else {
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/PasswordHistory.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/PasswordHistory.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/PasswordHistory.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/PasswordHistory.java
Tue May 16 07:46:44 2017
@@ -30,7 +30,6 @@ import org.apache.jackrabbit.oak.api.Typ
import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
import org.apache.jackrabbit.oak.spi.security.user.util.PasswordUtil;
-import org.apache.jackrabbit.oak.util.NodeUtil;
import org.apache.jackrabbit.oak.util.TreeUtil;
/**
@@ -129,7 +128,7 @@ final class PasswordHistory implements U
@Nonnull
private static Tree getPasswordTree(@Nonnull Tree userTree, boolean
doCreate) throws AccessDeniedException {
if (doCreate) {
- return new NodeUtil(userTree).getOrAddChild(UserConstants.REP_PWD,
UserConstants.NT_REP_PASSWORD).getTree();
+ return TreeUtil.getOrAddChild(userTree, UserConstants.REP_PWD,
UserConstants.NT_REP_PASSWORD);
} else {
return userTree.getChild(UserConstants.REP_PWD);
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
Tue May 16 07:46:44 2017
@@ -24,6 +24,8 @@ import org.apache.jackrabbit.JcrConstant
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
@@ -42,11 +44,11 @@ import org.apache.jackrabbit.oak.spi.sec
import org.apache.jackrabbit.oak.spi.state.ApplyDiff;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.apache.jackrabbit.oak.util.TreeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
import static
org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState.squeeze;
/**
@@ -104,31 +106,32 @@ class UserInitializer implements Workspa
String errorMsg = "Failed to initialize user content.";
try {
- NodeUtil rootTree = checkNotNull(new NodeUtil(root.getTree("/")));
- NodeUtil index =
rootTree.getOrAddChild(IndexConstants.INDEX_DEFINITIONS_NAME,
JcrConstants.NT_UNSTRUCTURED);
+ Tree rootTree = root.getTree(PathUtils.ROOT_PATH);
+ checkState(rootTree.exists());
+ Tree index = TreeUtil.getOrAddChild(rootTree,
IndexConstants.INDEX_DEFINITIONS_NAME, JcrConstants.NT_UNSTRUCTURED);
if (!index.hasChild("authorizableId")) {
- NodeUtil authorizableId =
IndexUtils.createIndexDefinition(index, "authorizableId", true,
- new String[]{REP_AUTHORIZABLE_ID},
+ Tree authorizableId = IndexUtils.createIndexDefinition(index,
"authorizableId", true,
+ new String[]{REP_AUTHORIZABLE_ID},
new String[]{NT_REP_AUTHORIZABLE});
- authorizableId.setString("info",
+ authorizableId.setProperty("info",
"Oak index used by the user management " +
"to enforce uniqueness of rep:authorizableId property
values.");
}
if (!index.hasChild("principalName")) {
- NodeUtil principalName =
IndexUtils.createIndexDefinition(index, "principalName", true,
+ Tree principalName = IndexUtils.createIndexDefinition(index,
"principalName", true,
new String[]{REP_PRINCIPAL_NAME},
new String[]{NT_REP_AUTHORIZABLE});
- principalName.setString("info",
+ principalName.setProperty("info",
"Oak index used by the user management " +
"to enforce uniqueness of rep:principalName property
values, " +
"and to quickly search a principal by name if it was
constructed manually.");
}
if (!index.hasChild("repMembers")) {
- NodeUtil members = IndexUtils.createIndexDefinition(index,
"repMembers", false,
+ Tree members = IndexUtils.createIndexDefinition(index,
"repMembers", false,
new String[]{REP_MEMBERS},
new String[]{NT_REP_MEMBER_REFERENCES});
- members.setString("info",
+ members.setProperty("info",
"Oak index used by the user management to lookup group
membership.");
}
@@ -145,10 +148,7 @@ class UserInitializer implements Workspa
if (root.hasPendingChanges()) {
root.commit();
}
- } catch (RepositoryException e) {
- log.error(errorMsg, e);
- throw new RuntimeException(e);
- } catch (CommitFailedException e) {
+ } catch (RepositoryException | CommitFailedException e) {
log.error(errorMsg, e);
throw new RuntimeException(e);
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java
Tue May 16 07:46:44 2017
@@ -22,7 +22,6 @@ import java.security.Principal;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -58,7 +57,7 @@ import org.apache.jackrabbit.oak.spi.sec
import org.apache.jackrabbit.oak.spi.security.user.action.GroupAction;
import org.apache.jackrabbit.oak.spi.security.user.util.PasswordUtil;
import org.apache.jackrabbit.oak.spi.security.user.util.UserUtil;
-import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.apache.jackrabbit.oak.util.TreeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -471,7 +470,7 @@ public class UserManagerImpl implements
// irrespective of password expiry being enabled or not
|| (forceInitialPwChange && !isNewUser))) {
- Tree pwdTree = new
NodeUtil(userTree).getOrAddChild(UserConstants.REP_PWD,
UserConstants.NT_REP_PASSWORD).getTree();
+ Tree pwdTree = TreeUtil.getOrAddChild(userTree,
UserConstants.REP_PWD, UserConstants.NT_REP_PASSWORD);
// System.currentTimeMillis() may be inaccurate on windows. This
is accepted for this feature.
pwdTree.setProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED,
System.currentTimeMillis(), Type.LONG);
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserPrincipalProvider.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserPrincipalProvider.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserPrincipalProvider.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserPrincipalProvider.java
Tue May 16 07:46:44 2017
@@ -56,7 +56,7 @@ import org.apache.jackrabbit.oak.spi.sec
import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
import org.apache.jackrabbit.oak.spi.security.user.util.UserUtil;
-import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.apache.jackrabbit.oak.util.TreeUtil;
import org.apache.jackrabbit.util.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -240,10 +240,9 @@ class UserPrincipalProvider implements P
@Nonnull
private Set<Group> getGroupMembership(@Nonnull Tree authorizableTree) {
Set<Group> groupPrincipals = null;
- NodeUtil authorizableNode = new NodeUtil(authorizableTree);
boolean doCache = cacheEnabled && UserUtil.isType(authorizableTree,
AuthorizableType.USER);
if (doCache) {
- groupPrincipals = readGroupsFromCache(authorizableNode);
+ groupPrincipals = readGroupsFromCache(authorizableTree);
}
// caching not configured or cache expired: use the membershipProvider
to calculate
@@ -262,7 +261,7 @@ class UserPrincipalProvider implements P
// remember the regular groups in case caching is enabled
if (doCache) {
- cacheGroups(authorizableNode, groupPrincipals);
+ cacheGroups(authorizableTree, groupPrincipals);
}
}
@@ -272,31 +271,31 @@ class UserPrincipalProvider implements P
return groupPrincipals;
}
- private void cacheGroups(@Nonnull NodeUtil authorizableNode, @Nonnull
Set<Group> groupPrincipals) {
+ private void cacheGroups(@Nonnull Tree authorizableNode, @Nonnull
Set<Group> groupPrincipals) {
try {
root.refresh();
- NodeUtil cache =
authorizableNode.getChild(CacheConstants.REP_CACHE);
- if (cache == null) {
+ Tree cache = authorizableNode.getChild(CacheConstants.REP_CACHE);
+ if (!cache.exists()) {
if (groupPrincipals.size() <= MEMBERSHIP_THRESHOLD) {
- log.debug("Omit cache creation for user without group
membership at " + authorizableNode.getTree().getPath());
+ log.debug("Omit cache creation for user without group
membership at " + authorizableNode.getPath());
return;
} else {
- log.debug("Create new group membership cache at " +
authorizableNode.getTree().getPath());
- cache =
authorizableNode.addChild(CacheConstants.REP_CACHE,
CacheConstants.NT_REP_CACHE);
+ log.debug("Create new group membership cache at " +
authorizableNode.getPath());
+ cache = TreeUtil.addChild(authorizableNode,
CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE);
}
}
- cache.setLong(CacheConstants.REP_EXPIRATION,
LongUtils.calculateExpirationTime(expiration));
+ cache.setProperty(CacheConstants.REP_EXPIRATION,
LongUtils.calculateExpirationTime(expiration));
String value = (groupPrincipals.isEmpty()) ? "" :
Joiner.on(",").join(Iterables.transform(groupPrincipals, new Function<Group,
String>() {
@Override
public String apply(Group input) {
return Text.escape(input.getName());
}
}));
- cache.setString(CacheConstants.REP_GROUP_PRINCIPAL_NAMES, value);
+ cache.setProperty(CacheConstants.REP_GROUP_PRINCIPAL_NAMES, value);
root.commit(CacheValidatorProvider.asCommitAttributes());
- log.debug("Cached group membership at " +
authorizableNode.getTree().getPath());
+ log.debug("Cached group membership at " +
authorizableNode.getPath());
} catch (AccessDeniedException e) {
log.debug("Failed to cache group membership", e.getMessage());
@@ -308,17 +307,17 @@ class UserPrincipalProvider implements P
}
@CheckForNull
- private Set<Group> readGroupsFromCache(@Nonnull NodeUtil authorizableNode)
{
- NodeUtil principalCache =
authorizableNode.getChild(CacheConstants.REP_CACHE);
- if (principalCache == null) {
- log.debug("No group cache at " +
authorizableNode.getTree().getPath());
+ private Set<Group> readGroupsFromCache(@Nonnull Tree authorizableNode) {
+ Tree principalCache =
authorizableNode.getChild(CacheConstants.REP_CACHE);
+ if (!principalCache.exists()) {
+ log.debug("No group cache at " + authorizableNode.getPath());
return null;
}
if (isValidCache(principalCache)) {
- log.debug("Reading group membership at " +
authorizableNode.getTree().getPath());
+ log.debug("Reading group membership at " +
authorizableNode.getPath());
- String str =
principalCache.getString(CacheConstants.REP_GROUP_PRINCIPAL_NAMES, null);
+ String str = TreeUtil.getString(principalCache,
CacheConstants.REP_GROUP_PRINCIPAL_NAMES);
if (str == null || str.isEmpty()) {
return new HashSet<Group>(1);
}
@@ -330,13 +329,13 @@ class UserPrincipalProvider implements P
}
return groups;
} else {
- log.debug("Expired group cache for " +
authorizableNode.getTree().getPath());
+ log.debug("Expired group cache for " + authorizableNode.getPath());
return null;
}
}
- private static boolean isValidCache(NodeUtil principalCache) {
- long expirationTime =
principalCache.getLong(CacheConstants.REP_EXPIRATION, EXPIRATION_NO_CACHE);
+ private static boolean isValidCache(Tree principalCache) {
+ long expirationTime = TreeUtil.getLong(principalCache,
CacheConstants.REP_EXPIRATION, EXPIRATION_NO_CACHE);
long now = new Date().getTime();
return expirationTime > EXPIRATION_NO_CACHE && now < expirationTime;
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
Tue May 16 07:46:44 2017
@@ -20,7 +20,6 @@ import java.security.Principal;
import java.text.ParseException;
import java.util.Collections;
import java.util.Iterator;
-
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -42,7 +41,6 @@ import org.apache.jackrabbit.oak.spi.sec
import org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName;
import org.apache.jackrabbit.oak.spi.security.user.AuthorizableType;
import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
-import org.apache.jackrabbit.oak.util.NodeUtil;
import org.apache.jackrabbit.oak.util.TreeUtil;
import org.apache.jackrabbit.util.Text;
import org.slf4j.Logger;
@@ -294,16 +292,16 @@ class UserProvider extends AuthorizableB
String folderPath = new StringBuilder()
.append(authRoot)
.append(getFolderPath(nodeName, intermediatePath,
authRoot)).toString();
- NodeUtil folder;
+ Tree folder;
Tree tree = root.getTree(folderPath);
while (!tree.isRoot() && !tree.exists()) {
tree = tree.getParent();
}
if (tree.exists()) {
- folder = new NodeUtil(tree);
+ folder = tree;
String relativePath = PathUtils.relativize(tree.getPath(),
folderPath);
if (!relativePath.isEmpty()) {
- folder = folder.getOrAddTree(relativePath,
NT_REP_AUTHORIZABLE_FOLDER);
+ folder = Utils.getOrAddTree(folder, relativePath,
NT_REP_AUTHORIZABLE_FOLDER);
}
} else {
throw new AccessDeniedException("Missing permission to create
intermediate authorizable folders.");
@@ -311,8 +309,8 @@ class UserProvider extends AuthorizableB
// test for colliding folder child node.
while (folder.hasChild(nodeName)) {
- NodeUtil colliding = folder.getChild(nodeName);
- String primaryType =
TreeUtil.getPrimaryTypeName(colliding.getTree());
+ Tree colliding = folder.getChild(nodeName);
+ String primaryType = TreeUtil.getPrimaryTypeName(colliding);
if (NT_REP_AUTHORIZABLE_FOLDER.equals(primaryType)) {
log.debug("Existing folder node collides with user/group to be
created. Expanding path by: " + colliding.getName());
folder = colliding;
@@ -320,7 +318,7 @@ class UserProvider extends AuthorizableB
break;
}
}
- return folder.getTree();
+ return folder;
}
@Nonnull
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/Utils.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/Utils.java?rev=1795274&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/Utils.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/Utils.java
Tue May 16 07:46:44 2017
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.security.user;
+
+import javax.annotation.Nonnull;
+import javax.jcr.AccessDeniedException;
+
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.util.TreeUtil;
+import org.apache.jackrabbit.util.Text;
+
+class Utils {
+
+ private Utils() {}
+
+ /**
+ * TODO: clean up. workaround for OAK-426
+ * <p>
+ * Create the tree at the specified relative path including all missing
+ * intermediate trees using the specified {@code primaryTypeName}. This
+ * method treats ".." parent element and "." as current element and
+ * resolves them accordingly; in case of a relative path containing parent
+ * elements this may lead to tree creating outside the tree structure
+ * defined by this {@code NodeUtil}.
+ *
+ * @param relativePath A relative OAK path that may contain parent and
+ * current elements.
+ * @param primaryTypeName A oak name of a primary node type that is used
+ * to create the missing trees.
+ * @return The node util of the tree at the specified {@code relativePath}.
+ * @throws AccessDeniedException If the any intermediate tree does not
exist
+ * and cannot be created.
+ */
+ @Nonnull
+ static Tree getOrAddTree(@Nonnull Tree tree, @Nonnull String relativePath,
@Nonnull String primaryTypeName) throws AccessDeniedException {
+ if (PathUtils.denotesCurrent(relativePath)) {
+ return tree;
+ } else if (PathUtils.denotesParent(relativePath)) {
+ return tree.getParent();
+ } else if (relativePath.indexOf('/') == -1) {
+ return TreeUtil.getOrAddChild(tree, relativePath, primaryTypeName);
+ } else {
+ Tree t = TreeUtil.getTree(tree, relativePath);
+ if (t == null || !t.exists()) {
+ Tree target = tree;
+ for (String segment : Text.explode(relativePath, '/')) {
+ if (PathUtils.denotesParent(segment)) {
+ target = target.getParent();
+ } else if (target.hasChild(segment)) {
+ target = target.getChild(segment);
+ } else if (!PathUtils.denotesCurrent(segment)) {
+ target = TreeUtil.addChild(target, segment,
primaryTypeName);
+ }
+ }
+ if (!target.exists()) {
+ throw new AccessDeniedException();
+ }
+ return target;
+ } else {
+ return t;
+ }
+ }
+ }
+}
\ No newline at end of file
Propchange:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/Utils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java
Tue May 16 07:46:44 2017
@@ -38,7 +38,7 @@ import org.apache.jackrabbit.oak.api.Tre
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
import
org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants;
-import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.apache.jackrabbit.oak.util.TreeUtil;
import org.apache.jackrabbit.util.Text;
public abstract class AbstractRestrictionProvider implements
RestrictionProvider, AccessControlConstants {
@@ -126,10 +126,9 @@ public abstract class AbstractRestrictio
// validation of the restrictions is delegated to the commit hook
// see #validateRestrictions below
if (!restrictions.isEmpty()) {
- NodeUtil aceNode = new NodeUtil(aceTree);
- NodeUtil rNode = aceNode.getOrAddChild(REP_RESTRICTIONS,
NT_REP_RESTRICTIONS);
+ Tree rTree = TreeUtil.getOrAddChild(aceTree, REP_RESTRICTIONS,
NT_REP_RESTRICTIONS);
for (Restriction restriction : restrictions) {
- rNode.getTree().setProperty(restriction.getProperty());
+ rTree.setProperty(restriction.getProperty());
}
}
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
Tue May 16 07:46:44 2017
@@ -22,6 +22,8 @@ import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import javax.jcr.AccessDeniedException;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -59,6 +61,7 @@ import static org.apache.jackrabbit.JcrC
import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
import static org.apache.jackrabbit.oak.api.Type.DATE;
+import static org.apache.jackrabbit.oak.api.Type.LONG;
import static org.apache.jackrabbit.oak.api.Type.NAME;
import static org.apache.jackrabbit.oak.api.Type.NAMES;
import static org.apache.jackrabbit.oak.api.Type.STRING;
@@ -102,6 +105,12 @@ public final class TreeUtil {
}
@CheckForNull
+ public String getString(@Nonnull Tree tree, @Nonnull String name,
@Nullable String defaultValue) {
+ String str = getString(tree, name);
+ return (str != null) ? str : defaultValue;
+ }
+
+ @CheckForNull
private static String getStringInternal(@Nonnull Tree tree,
@Nonnull String propertyName,
@Nonnull Type<String> type) {
@@ -150,6 +159,15 @@ public final class TreeUtil {
}
}
+ public static long getLong(@Nonnull Tree tree, @Nonnull String name, long
defaultValue) {
+ PropertyState property = tree.getProperty(name);
+ if (property != null && !property.isArray()) {
+ return property.getValue(LONG);
+ } else {
+ return defaultValue;
+ }
+ }
+
/**
* Return the possibly non existing tree located at the passed {@code
path} from
* the location of the start {@code tree} or {@code null} if {@code path}
results
@@ -211,6 +229,46 @@ public final class TreeUtil {
return child;
}
+ /**
+ * Adds a new child tree with the given name and primary type name.
+ * This method is a shortcut for calling {@link Tree#addChild(String)} and
+ * {@link Tree#setProperty(String, Object,
org.apache.jackrabbit.oak.api.Type)}
+ * where the property name is {@link JcrConstants#JCR_PRIMARYTYPE}.
+ * Note, that this method in addition verifies if the created tree exists
+ * and is accessible in order to avoid {@link IllegalStateException} upon
+ * subsequent modification of the new child.
+ *
+ * @param name The Oak name of the child item.
+ * @param primaryTypeName The Oak name of the primary node type.
+ * @return The new child tree with the specified name and primary type.
+ * @throws AccessDeniedException If the child does not exist after
creation.
+ */
+ @Nonnull
+ public static Tree addChild(@Nonnull Tree tree, @Nonnull String childName,
@Nonnull String primaryTypeName) throws AccessDeniedException {
+ Tree child = tree.addChild(childName);
+ if (!child.exists()) {
+ throw new AccessDeniedException();
+ }
+ child.setProperty(JcrConstants.JCR_PRIMARYTYPE, primaryTypeName, NAME);
+ return child;
+ }
+
+ /**
+ * Combination of {@link Tree#getChild(String)} and adding a child
including
+ * its jcr:primaryType property (i.e. {@link Tree#addChild(String)} and
+ * {@link Tree#setProperty(PropertyState)}) in case no tree exists with
the specified name.
+ *
+ * @param name The Oak name of the child item.
+ * @param primaryTypeName The Oak name of the primary node type.
+ * @return The new child node with the specified name and primary type.
+ * @throws AccessDeniedException If the child does not exist after
creation.
+ */
+ @Nonnull
+ public static Tree getOrAddChild(@Nonnull Tree tree, @Nonnull String
childName, @Nonnull String primaryTypeName) throws AccessDeniedException {
+ Tree child = tree.getChild(childName);
+ return (child.exists()) ? child : addChild(tree, childName,
primaryTypeName);
+ }
+
public static void addMixin(@Nonnull Tree tree, @Nonnull String mixinName,
@Nonnull Tree typeRoot, @CheckForNull String userID) throws RepositoryException
{
Tree type = typeRoot.getChild(mixinName);
if (!type.exists()) {
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexQueryTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexQueryTest.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexQueryTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexQueryTest.java
Tue May 16 07:46:44 2017
@@ -78,7 +78,7 @@ public class NodeTypeIndexQueryTest exte
mixLanguage(t, "e");
mixLanguage(t, "f");
- NodeUtil n = new NodeUtil(root.getTree("/oak:index"));
+ Tree n = root.getTree("/oak:index");
createIndexDefinition(n, "nodetype", false, new String[] {
JCR_PRIMARYTYPE, JCR_MIXINTYPES }, new String[] { "nt:folder",
"mix:language" });
@@ -98,7 +98,7 @@ public class NodeTypeIndexQueryTest exte
setTraversalEnabled(false);
Tree t, t1;
- NodeUtil n = new NodeUtil(root.getTree("/oak:index"));
+ Tree n = root.getTree("/oak:index");
createIndexDefinition(n, "nodeType", false, new String[] {
JCR_PRIMARYTYPE }, new String[] { NT_UNSTRUCTURED });
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProviderTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProviderTest.java?rev=1795274&r1=1795273&r2=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProviderTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProviderTest.java
Tue May 16 07:46:44 2017
@@ -29,6 +29,7 @@ import java.util.List;
import javax.jcr.RepositoryException;
+import com.google.common.collect.ImmutableList;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.commons.junit.LogCustomizer;
import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
@@ -41,7 +42,6 @@ import org.apache.jackrabbit.oak.spi.com
import org.apache.jackrabbit.oak.spi.commit.EditorHook;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.util.NodeUtil;
import org.junit.Test;
import ch.qos.logback.classic.Level;
@@ -58,9 +58,9 @@ public class OrderedPropertyIndexEditorP
private void createIndexDef(NodeBuilder root) throws RepositoryException {
IndexUtils
.createIndexDefinition(
- new NodeUtil(TreeFactory.createTree(root
- .child(IndexConstants.INDEX_DEFINITIONS_NAME))), indexName,
false,
- new String[] { indexedProperty }, null, OrderedIndex.TYPE);
+ TreeFactory.createTree(root
+ .child(IndexConstants.INDEX_DEFINITIONS_NAME)), indexName,
false,
+ ImmutableList.of(indexedProperty), null, OrderedIndex.TYPE, null);
}
@Test
Copied:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UtilsTest.java
(from r1795151,
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/NodeUtilTest.java)
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UtilsTest.java?p2=jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UtilsTest.java&p1=jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/NodeUtilTest.java&r1=1795151&r2=1795274&rev=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/NodeUtilTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UtilsTest.java
Tue May 16 07:46:44 2017
@@ -14,28 +14,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.jackrabbit.oak.util;
+package org.apache.jackrabbit.oak.security.user;
import java.util.Map;
import javax.annotation.Nonnull;
import com.google.common.collect.ImmutableMap;
import org.apache.jackrabbit.oak.AbstractSecurityTest;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
-public class NodeUtilTest extends AbstractSecurityTest {
+public class UtilsTest extends AbstractSecurityTest {
- private NodeUtil node;
+ private Tree tree;
@Override
public void before() throws Exception {
super.before();
- node = new NodeUtil(root.getTree("/"));
+ tree = root.getTree(PathUtils.ROOT_PATH);
}
@Override
@@ -47,20 +49,20 @@ public class NodeUtilTest extends Abstra
}
}
- private void assertEqualNodeUtil(@Nonnull NodeUtil expected, @Nonnull
NodeUtil result) {
- assertEquals(expected.getTree().getPath(), result.getTree().getPath());
+ private void assertEqualPath(@Nonnull Tree expected, @Nonnull Tree result)
{
+ assertEquals(expected.getPath(), result.getPath());
}
@Test
public void testGetOrAddTree() throws Exception {
- NodeUtil result = node.getOrAddTree(".",
NodeTypeConstants.NT_OAK_UNSTRUCTURED);
- assertSame(node, result);
+ Tree result = Utils.getOrAddTree(tree, ".",
NodeTypeConstants.NT_OAK_UNSTRUCTURED);
+ assertSame(tree, result);
- NodeUtil child = node.getOrAddTree("child",
NodeTypeConstants.NT_OAK_UNSTRUCTURED);
- assertEqualNodeUtil(new NodeUtil(root.getTree("/child")), child);
+ Tree child = Utils.getOrAddTree(tree, "child",
NodeTypeConstants.NT_OAK_UNSTRUCTURED);
+ assertEqualPath(root.getTree("/child"), child);
- NodeUtil parent = child.getOrAddTree("..",
NodeTypeConstants.NT_OAK_UNSTRUCTURED);
- assertEqualNodeUtil(node, parent);
+ Tree parent = Utils.getOrAddTree(child, "..",
NodeTypeConstants.NT_OAK_UNSTRUCTURED);
+ assertEqualPath(tree, parent);
Map<String, String> map = ImmutableMap.of(
"a/b/c", "/a/b/c",
@@ -69,8 +71,8 @@ public class NodeUtilTest extends Abstra
"a/././././b/c", "/a/b/c"
);
for (String relPath : map.keySet()) {
- NodeUtil n = node.getOrAddTree(relPath,
NodeTypeConstants.NT_OAK_UNSTRUCTURED);
- assertEqualNodeUtil(new NodeUtil(root.getTree(map.get(relPath))),
n);
+ Tree t = Utils.getOrAddTree(tree, relPath,
NodeTypeConstants.NT_OAK_UNSTRUCTURED);
+ assertEqualPath(root.getTree(map.get(relPath)), t);
}
}
}
\ No newline at end of file
Copied:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/NodeUtil.java
(from r1795151,
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java)
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/NodeUtil.java?p2=jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/NodeUtil.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java&r1=1795151&r2=1795274&rev=1795274&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/util/NodeUtil.java
Tue May 16 07:46:44 2017
@@ -49,6 +49,8 @@ import static org.apache.jackrabbit.oak.
/**
* Utility class for accessing and writing typed content of a tree.
+ *
+ * @deprecated See OAK-6093
*/
public class NodeUtil {