jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1432148 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
Date Fri, 11 Jan 2013 16:54:26 GMT
Author: angela
Date: Fri Jan 11 16:54:26 2013
New Revision: 1432148

URL: http://svn.apache.org/viewvc?rev=1432148&view=rev
Log:
OAK-50 : Implement User Management

- keep index when converting jcr user path

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.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=1432148&r1=1432147&r2=1432148&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 Jan 11 16:54:26 2013
@@ -30,7 +30,6 @@ import javax.jcr.ImportUUIDBehavior;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
 
 import org.apache.jackrabbit.api.JackrabbitSession;
@@ -181,7 +180,6 @@ public class UserImporter implements Pro
             return false;
         }
 
-
         initialized = true;
         return initialized;
     }
@@ -217,8 +215,7 @@ public class UserImporter implements Pro
 
     // -----------------------------------------< ProtectedPropertyImporter >---
     @Override
-    public boolean handlePropInfo(Tree parent, PropInfo propInfo,
-                                  PropertyDefinition def) throws RepositoryException {
+    public boolean handlePropInfo(Tree parent, PropInfo propInfo, PropertyDefinition def)
throws RepositoryException {
         checkInitialized();
 
         Authorizable a = userManager.getAuthorizable(parent);
@@ -229,13 +226,12 @@ public class UserImporter implements Pro
 
         String propString = propInfo.getName();
         if (UserConstants.REP_PRINCIPAL_NAME.equals(propString)) {
-            if (isViolatingDefinition(propString, def, UserConstants.NT_REP_AUTHORIZABLE,
false)) {
+            if (!isValid(propString, def, UserConstants.NT_REP_AUTHORIZABLE, false)) {
                 return false;
             }
 
             String principalName = propInfo.getTextValue().getString();
             userManager.setPrincipal(parent, new TreeBasedPrincipal(principalName, parent,
namePathMapper));
-
             /*
             Execute authorizable actions for a NEW group as this is the
             same place in the userManager#createGroup that the actions
@@ -250,10 +246,10 @@ public class UserImporter implements Pro
                     userManager.onCreate((User) a, currentPw.remove(a.getID()));
                 }
             }
-
             return true;
         } else if (UserConstants.REP_PASSWORD.equals(propString)) {
-            if (isWrongType(a, false) || isViolatingDefinition(propString, def, UserConstants.NT_REP_USER,
false)) {
+            if (a.isGroup() || !isValid(propString, def, UserConstants.NT_REP_USER, false))
{
+                log.warn("Unexpected authorizable or definition for property rep:password");
                 return false;
             }
 
@@ -277,7 +273,8 @@ public class UserImporter implements Pro
             return true;
 
         } else if (UserConstants.REP_IMPERSONATORS.equals(propString)) {
-            if (isWrongType(a, false) || isViolatingDefinition(propString, def, UserConstants.MIX_REP_IMPERSONATABLE,
true)) {
+            if (a.isGroup() || !isValid(propString, def, UserConstants.MIX_REP_IMPERSONATABLE,
true)) {
+                log.warn("Unexpected authorizable or definition for property rep:impersonators");
                 return false;
             }
             // since impersonators may be imported later on, postpone processing
@@ -288,8 +285,8 @@ public class UserImporter implements Pro
             return true;
 
         } else if (UserConstants.REP_DISABLED.equals(propString)) {
-            if (isWrongType(a, false) || isViolatingDefinition(propString, def, UserConstants.NT_REP_USER,
false)) {
-                log.warn("Unexpected definition for property rep:disabled");
+            if (a.isGroup() || !isValid(propString, def, UserConstants.NT_REP_USER, false))
{
+                log.warn("Unexpected authorizable or definition for property rep:disabled");
                 return false;
             }
 
@@ -297,7 +294,7 @@ public class UserImporter implements Pro
             return true;
 
         } else if (UserConstants.REP_MEMBERS.equals(propString)) {
-            if (isWrongType(a, true) || isViolatingDefinition(propString, def, UserConstants.NT_REP_GROUP,
true)) {
+            if (!a.isGroup() || !isValid(propString, def, UserConstants.NT_REP_GROUP, true))
{
                 return false;
             }
             // since group-members are references to user/groups that potentially
@@ -403,27 +400,10 @@ public class UserImporter implements Pro
         }
     }
 
-    private boolean isNodeType(String oakName, NodeType nodeType) {
-        return oakName.equals(namePathMapper.getJcrName(nodeType.getName()));
-    }
-
-    private boolean isViolatingDefinition(String propertyName, PropertyDefinition definition,
-                                 String oakNodeTypeName, boolean multipleStatus) {
-        if (multipleStatus == definition.isMultiple() && isNodeType(oakNodeTypeName,
definition.getDeclaringNodeType())) {
-            return false;
-        } else {
-            log.warn("Unexpected definition for property " + propertyName);
-            return true;
-        }
-    }
-
-    private static boolean isWrongType(Authorizable a, boolean isExpectedGroup) {
-        if (a.isGroup() != isExpectedGroup) {
-            log.warn("Expected parent node of to be {}.", (isExpectedGroup) ? "group" : "user");
-            return false;
-        } else {
-            return true;
-        }
+    private boolean isValid(String propertyName, PropertyDefinition definition,
+                            String oakNodeTypeName, boolean multipleStatus) {
+        return multipleStatus == definition.isMultiple() &&
+               definition.getDeclaringNodeType().isNodeType(namePathMapper.getJcrName(oakNodeTypeName));
     }
 
     /**



Mime
View raw message