jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r641898 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user: IndexNodeResolver.java NodeResolver.java TraversingNodeResolver.java UserManagerImpl.java
Date Thu, 27 Mar 2008 17:07:53 GMT
Author: angela
Date: Thu Mar 27 10:07:41 2008
New Revision: 641898

URL: http://svn.apache.org/viewvc?rev=641898&view=rev
Log:
- resolving TODOs (retrieve group by ID)
- improved NodeResolver (replacing SessionImpl by Session/NamePathResolver pair)

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/NodeResolver.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/TraversingNodeResolver.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java?rev=641898&r1=641897&r2=641898&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java
Thu Mar 27 10:07:41 2008
@@ -18,11 +18,12 @@
 
 import org.apache.jackrabbit.util.ISO9075;
 import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import java.util.Iterator;
@@ -36,9 +37,8 @@
 
     private final QueryManager queryManager;
 
-    IndexNodeResolver(SessionImpl session)
-            throws RepositoryException {
-        super(session);
+    IndexNodeResolver(Session session, NamePathResolver resolver) throws RepositoryException
{
+        super(session, resolver);
         queryManager = session.getWorkspace().getQueryManager();
     }
 
@@ -46,6 +46,18 @@
     /**
      * @inheritDoc
      */
+    public Node findNode(Name nodeName, Name ntName) throws RepositoryException {
+        Query query = buildQuery(nodeName, ntName);
+        NodeIterator res = query.execute().getNodes();
+        if (res.hasNext()) {
+            return res.nextNode();
+        }
+        return null;
+    }
+    
+    /**
+     * @inheritDoc
+     */
     public Node findNode(Name propertyName, String value, Name ntName) throws RepositoryException
{
         Query query = buildQuery(value, Collections.singleton(propertyName), ntName, true,
1);
         NodeIterator res = query.execute().getNodes();
@@ -84,6 +96,28 @@
      * @return
      * @throws RepositoryException
      */
+    private Query buildQuery(Name nodeName, Name ntName)
+            throws RepositoryException {
+        StringBuffer stmt = new StringBuffer("/jcr:root");
+        stmt.append(getSearchRoot(ntName));
+        stmt.append("//element(");
+        stmt.append(getNamePathResolver().getJCRName(nodeName));
+        stmt.append(",");
+        stmt.append(getNamePathResolver().getJCRName(ntName));
+        stmt.append(")");
+        return queryManager.createQuery(stmt.toString(), Query.XPATH);
+    }
+
+    /**
+     *
+     * @param value
+     * @param props
+     * @param ntName
+     * @param exact
+     * @param maxSize Currently ignored!
+     * @return
+     * @throws RepositoryException
+     */
     private Query buildQuery(String value, Set props, Name ntName,
                              boolean exact, long maxSize)
             throws RepositoryException {
@@ -91,14 +125,14 @@
         StringBuffer stmt = new StringBuffer("/jcr:root");
         stmt.append(getSearchRoot(ntName));
         stmt.append("//element(*,");
-        stmt.append(getSession().getJCRName(ntName));
+        stmt.append(getNamePathResolver().getJCRName(ntName));
         stmt.append(")[");
 
         int i = 0;
         Iterator itr = props.iterator();
         while (itr.hasNext()) {
             stmt.append((exact) ? "@" : "jcr:like(@");
-            String pName = getSession().getJCRName((Name) itr.next());
+            String pName = getNamePathResolver().getJCRName((Name) itr.next());
             stmt.append(ISO9075.encode(pName));
             stmt.append((exact) ? "='" : ",'%");
             stmt.append(value);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/NodeResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/NodeResolver.java?rev=641898&r1=641897&r2=641898&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/NodeResolver.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/NodeResolver.java
Thu Mar 27 10:07:41 2008
@@ -18,12 +18,13 @@
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import java.util.Collections;
 import java.util.Set;
 
@@ -36,7 +37,8 @@
 
     private static final Logger log = LoggerFactory.getLogger(NodeResolver.class);
 
-    private final SessionImpl session;
+    private final Session session;
+    private final NamePathResolver resolver;
 
     /**
      * Create a new <code>NodeResolver</code>.
@@ -44,13 +46,23 @@
      * @param session;
      * @throws RepositoryException if instanciation fails
      */
-    NodeResolver(SessionImpl session)
-            throws RepositoryException {
-
+    NodeResolver(Session session, NamePathResolver resolver) throws RepositoryException {
         this.session = session;
+        this.resolver = resolver;
     }
 
     /**
+     * Get the first node that matches <code>ntName</code> and whose name
+     * exactly matches the given <code>nodeName</code>.
+     *
+     * @param nodeName
+     * @param ntName
+     * @return A matching node or <code>null</code>.
+     * @throws RepositoryException
+     */
+    public abstract Node findNode(Name nodeName, Name ntName) throws RepositoryException;
+
+    /**
      * Get the first node that matches <code>ntName</code> and has a
      * property whose value exactly matches the given value. Same as
      * {@link #findNodes(Set,String,Name,boolean,long)} but returning a single node or <code>null</code>.
@@ -101,8 +113,12 @@
     /**
      * @return Session this instance has been constructed with
      */
-    SessionImpl getSession() {
+    Session getSession() {
         return session;
+    }
+
+    NamePathResolver getNamePathResolver() {
+        return resolver;
     }
 
     String getSearchRoot(Name ntName) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/TraversingNodeResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/TraversingNodeResolver.java?rev=641898&r1=641897&r2=641898&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/TraversingNodeResolver.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/TraversingNodeResolver.java
Thu Mar 27 10:07:41 2008
@@ -18,9 +18,9 @@
 package org.apache.jackrabbit.core.security.user;
 
 import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
-import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.NodeImpl;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -28,6 +28,7 @@
 import javax.jcr.NodeIterator;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -48,14 +49,22 @@
      *
      * @param session      to use for repository access
      */
-    TraversingNodeResolver(SessionImpl session) throws RepositoryException {
-        super(session);
+    TraversingNodeResolver(Session session, NamePathResolver resolver) throws RepositoryException
{
+        super(session, resolver);
     }
 
     //-------------------------------------------------------< NodeResolver >---
     /**
      * @inheritDoc
      */
+    public Node findNode(Name nodeName, Name ntName) throws RepositoryException {
+        Node root = (Node) getSession().getItem(getSearchRoot(ntName));
+        return collectNode(nodeName, ntName, root.getNodes());
+    }
+
+    /**
+     * @inheritDoc
+     */
     public Node findNode(Name propertyName, String value, Name ntName) throws RepositoryException
{
         try {
             Node root = (Node) getSession().getItem(getSearchRoot(ntName));
@@ -82,6 +91,25 @@
     }
 
     //--------------------------------------------------------------------------
+
+    private Node collectNode(Name nodeName, Name ntName, NodeIterator nodes) {
+        while (nodes.hasNext()) {
+            NodeImpl node = (NodeImpl) nodes.nextNode();
+            try {
+                if (node.isNodeType(ntName) && nodeName.equals(node.getQName()))
{
+                    return node;
+                }
+                if (node.hasNodes()) {
+                    return collectNode(nodeName, ntName, node.getNodes());
+                }
+            } catch (RepositoryException e) {
+                log.warn("Internal error while accessing node", e);
+            }
+        }
+        log.debug("Could not find a node matching name '" + nodeName + " and nodetype " +
ntName);
+        return null;
+    }
+
     /**
      * searches the given value in the range of the given NodeIterator.
      * recurses unitll all matching values in all configured props are found.
@@ -129,7 +157,7 @@
                             node.getNodes(), matches, exact, maxSize);
                 }
             } catch (RepositoryException e) {
-                log.warn("failed to access Node at " + e);
+                log.warn("Internal error while accessing node", e);
             }
         }
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java?rev=641898&r1=641897&r2=641898&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
Thu Mar 27 10:07:41 2008
@@ -72,11 +72,10 @@
 
         NodeResolver nr;
         try {
-            session.getWorkspace().getQueryManager();
-            nr = new IndexNodeResolver(session);
+            nr = new IndexNodeResolver(session, session);
         } catch (RepositoryException e) {
             log.debug("UserManger: no QueryManager available for workspace '" + session.getWorkspace().getName()
+ "' -> Use traversing node resolver.");
-            nr = new TraversingNodeResolver(session);
+            nr = new TraversingNodeResolver(session, session);
         }
         authResolver = nr;
     }
@@ -94,9 +93,8 @@
         if (n != null) {
             authorz = UserImpl.create(n, this);
         } else {
-            // TODO: TOBEFIXED. should rather search for node with escaped(id) == Node.getName
-            String principalName = getGroupPrincipalName(id);
-            n = (NodeImpl) authResolver.findNode(P_PRINCIPAL_NAME, principalName, NT_REP_GROUP);
+            Name nodeName = session.getQName(id);
+            n = (NodeImpl) authResolver.findNode(nodeName, NT_REP_GROUP);
             if (n != null) {
                 authorz = GroupImpl.create(n, this);
             }
@@ -347,20 +345,10 @@
         String groupID = escHint;
         int i = 0;
         while (getAuthorizable(groupID) != null) {
-            // TODO: replace separator by "_" (see above)
-            groupID = escHint + "_GR_" + i;
+            groupID = escHint + "_" + i;
             i++;
         }
         return session.getQName(groupID);
-    }
-
-    /**
-     * TODO: Remove method as soon as searching group-by-id is fixed (see above).
-     */
-    private static String getGroupPrincipalName(String groupId) {
-        int pos = groupId.lastIndexOf("_GR_");
-        String pName = (pos > -1) ? groupId.substring(0, pos) : groupId;
-        return Text.unescapeIllegalJcrChars(pName);
     }
 
     private Value getValue(String strValue) throws RepositoryException {



Mime
View raw message