You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2014/07/04 12:12:46 UTC
svn commit: r1607820 - in /jackrabbit/oak/trunk:
oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/
oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/
oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/
Author: angela
Date: Fri Jul 4 10:12:46 2014
New Revision: 1607820
URL: http://svn.apache.org/r1607820
Log:
OAK-1943
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportPwExpiryTest.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java?rev=1607820&r1=1607819&r2=1607820&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java Fri Jul 4 10:12:46 2014
@@ -29,6 +29,7 @@ import java.util.TreeSet;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.ConstraintViolationException;
@@ -48,6 +49,7 @@ import org.apache.jackrabbit.oak.api.Tre
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
@@ -219,7 +221,9 @@ class UserImporter implements ProtectedP
checkInitialized();
String propName = propInfo.getName();
- Authorizable a = userManager.getAuthorizable(parent);
+ boolean isPwdNode = isPwdNode(parent);
+ Tree authorizableTree = (isPwdNode) ? parent.getParent() : parent;
+ Authorizable a = userManager.getAuthorizable(authorizableTree);
if (a == null) {
log.warn("Cannot handle protected PropInfo " + propInfo + ". Node " + parent + " doesn't represent a valid Authorizable.");
@@ -332,7 +336,22 @@ class UserImporter implements ProtectedP
getMembership(a.getID()).addMembers(propInfo.getTextValues());
return true;
- } // else: cannot handle -> return false
+ } else if (isPwdNode) {
+ // overwrite any properties generated underneath the rep:pwd node
+ // by "UserManagerImpl#setPassword" by the properties defined by
+ // the XML to be imported. see OAK-1943 for the corresponding discussion.
+ int targetType = def.getRequiredType();
+ if (targetType == PropertyType.UNDEFINED) {
+ targetType = (REP_PASSWORD_LAST_MODIFIED.equals(propName)) ? PropertyType.LONG : PropertyType.STRING;
+ }
+ PropertyState property;
+ if (def.isMultiple()) {
+ property = PropertyStates.createProperty(propName, propInfo.getValues(targetType));
+ } else {
+ property = PropertyStates.createProperty(propName, propInfo.getValue(targetType));
+ };
+ parent.setProperty(property);
+ }// else: cannot handle -> return false
return false;
}
@@ -471,6 +490,10 @@ class UserImporter implements ProtectedP
return tree != null && NT_REP_MEMBER_REFERENCES_LIST.equals(TreeUtil.getPrimaryTypeName(tree));
}
+ private static boolean isPwdNode(@Nonnull Tree tree) {
+ return REP_PWD.equals(tree.getName()) && NT_REP_PASSWORD.equals(TreeUtil.getPrimaryTypeName(tree));
+ }
+
/**
* Handling the import behavior
*
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java?rev=1607820&r1=1607819&r2=1607820&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java Fri Jul 4 10:12:46 2014
@@ -281,6 +281,35 @@ public class ImporterImpl implements Imp
return tree;
}
+ private void importProperties(@Nonnull Tree tree,
+ @Nonnull List<PropInfo> propInfos,
+ boolean ignoreRegular) throws RepositoryException {
+ // process properties
+ for (PropInfo pi : propInfos) {
+ // find applicable definition
+ //TODO find better heuristics?
+ PropertyDefinition def = pi.getPropertyDef(effectiveNodeTypeProvider.getEffectiveNodeType(tree));
+ if (def.isProtected()) {
+ // skip protected property
+ log.debug("Protected property " + pi.getName());
+
+ // notify the ProtectedPropertyImporter.
+ for (ProtectedItemImporter ppi : pItemImporters) {
+ if (ppi instanceof ProtectedPropertyImporter
+ && ((ProtectedPropertyImporter) ppi).handlePropInfo(tree, pi, def)) {
+ log.debug("Protected property -> delegated to ProtectedPropertyImporter");
+ break;
+ } /* else: p-i-Importer isn't able to deal with this property.
+ try next pp-importer */
+
+ }
+ } else if (!ignoreRegular) {
+ // regular property -> create the property
+ createProperty(tree, pi, def);
+ }
+ }
+ }
+
//-----------------------------------------------------------< Importer >---
@Override
@@ -362,6 +391,12 @@ public class ImporterImpl implements Imp
*/
log.debug("Skipping protected node: " + existing);
parents.push(existing);
+ /**
+ * let ProtectedPropertyImporters handle the properties
+ * associated with the imported node. this may include overwriting,
+ * merging or just adding missing properties.
+ */
+ importProperties(existing, propInfos, true);
return;
}
if (def.isAutoCreated() && isNodeType(existing, ntName)) {
@@ -429,30 +464,7 @@ public class ImporterImpl implements Imp
}
// process properties
- for (PropInfo pi : propInfos) {
- // find applicable definition
- //TODO find better heuristics?
- PropertyDefinition def = pi.getPropertyDef(effectiveNodeTypeProvider.getEffectiveNodeType(tree));
-
- if (def.isProtected()) {
- // skip protected property
- log.debug("Skipping protected property " + pi.getName());
-
- // notify the ProtectedPropertyImporter.
- for (ProtectedItemImporter ppi : pItemImporters) {
- if (ppi instanceof ProtectedPropertyImporter
- && ((ProtectedPropertyImporter) ppi).handlePropInfo(tree, pi, def)) {
- log.debug("Protected property -> delegated to ProtectedPropertyImporter");
- break;
- } /* else: p-i-Importer isn't able to deal with this property.
- try next pp-importer */
-
- }
- } else {
- // regular property -> create the property
- createProperty(tree, pi, def);
- }
- }
+ importProperties(tree, propInfos, false);
parents.push(tree);
}
Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportPwExpiryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportPwExpiryTest.java?rev=1607820&r1=1607819&r2=1607820&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportPwExpiryTest.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImportPwExpiryTest.java Fri Jul 4 10:12:46 2014
@@ -25,7 +25,6 @@ import org.apache.jackrabbit.api.securit
import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
-import org.junit.Ignore;
import org.junit.Test;
import java.util.HashMap;
@@ -54,7 +53,7 @@ public class UserImportPwExpiryTest exte
@CheckForNull
protected ConfigurationParameters getConfigurationParameters() {
HashMap<String, Object> userParams = new HashMap<String, Object>() {{
- put(UserConstants.PARAM_PASSWORD_MAX_AGE, Long.valueOf(10));
+ put(UserConstants.PARAM_PASSWORD_MAX_AGE, 10);
}};
return ConfigurationParameters.of(ImmutableMap.of(UserConfiguration.NAME, ConfigurationParameters.of(userParams)));
}
@@ -63,8 +62,7 @@ public class UserImportPwExpiryTest exte
* @since Oak 1.1
*/
@Test
- @Ignore("OAK-1943") // FIXME OAK-1943
- public void testImportUser() throws Exception {
+ public void testImportUserCreatesPasswordLastModified() throws Exception {
// import user
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<sv:node sv:name=\"x\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" +
@@ -102,8 +100,7 @@ public class UserImportPwExpiryTest exte
* @since Oak 1.1
*/
@Test
- @Ignore("OAK-1943") // FIXME OAK-1943
- public void testImportUserWithCustomPwdProperties() throws Exception {
+ public void testImportUserWithPwdProperties() throws Exception {
// import user
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<sv:node sv:name=\"y\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" +