jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r689499 [11/11] - in /jackrabbit/trunk: jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jsr283/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jsr283/retention/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/jsr283/se...
Date Wed, 27 Aug 2008 15:12:07 GMT
Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java?rev=689499&r1=689498&r2=689499&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java
Wed Aug 27 08:12:04 2008
@@ -20,11 +20,12 @@
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.Group;
 import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.core.NodeImpl;
+import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.security.TestPrincipal;
 import org.apache.jackrabbit.test.NotExecutableException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
 
 import javax.jcr.Credentials;
 import javax.jcr.RepositoryException;
@@ -41,13 +42,17 @@
  */
 public class UserManagerImplTest extends AbstractUserTest {
 
-    private static Logger log = LoggerFactory.getLogger(UserManagerImplTest.class);
+    private String pPrincipalName;
+    private String pUserID;
 
     protected void setUp() throws Exception {
         super.setUp();
         if (!(userMgr instanceof UserManagerImpl)) {
             throw new NotExecutableException("UserManagerImpl expected -> cannot perform
test.");
         }
+        NameResolver resolver = (SessionImpl) superuser;
+        pPrincipalName = resolver.getJCRName(UserConstants.P_PRINCIPAL_NAME);
+        pUserID = resolver.getJCRName(UserConstants.P_USERID);
     }
 
     private String getTestUserId(Principal p) throws RepositoryException {
@@ -211,7 +216,7 @@
             if (auth != null) {
                 if (!auth.isGroup() && auth.hasProperty("rep:userId")) {
                     String val = auth.getProperty("rep:userId")[0].getString();
-                    Iterator users = userMgr.findAuthorizable("rep:userId", val);
+                    Iterator users = userMgr.findAuthorizables("rep:userId", val);
 
                     // the result must contain 1 authorizable
                     assertTrue(users.hasNext());
@@ -235,7 +240,7 @@
             auth.setProperty("E-Mail", new Value[] { superuser.getValueFactory().createValue("anyVal")});
 
             boolean found = false;
-            Iterator result = userMgr.findAuthorizable("E-Mail", "anyVal");
+            Iterator result = userMgr.findAuthorizables("E-Mail", "anyVal");
             while (result.hasNext()) {
                 Authorizable a = (Authorizable) result.next();
                 if (a.getID().equals(auth.getID())) {
@@ -260,14 +265,14 @@
             u = userMgr.createUser(uid, buildPassword(uid, false), p, null);
 
             boolean found = false;
-            Iterator it = ((UserManagerImpl)userMgr).findUsers("");
+            Iterator it = userMgr.findAuthorizables(pPrincipalName, null, UserManager.SEARCH_TYPE_USER);
             while (it.hasNext() && !found) {
                 User nu = (User) it.next();
                 found = nu.getID().equals(uid);
             }
-            assertTrue("Searching for \"\" must find the created user.", found);
+            assertTrue("Searching for 'null' must find the created user.", found);
 
-            it = ((UserManagerImpl)userMgr).findUsers(p.getName());
+            it = userMgr.findAuthorizables(pPrincipalName, p.getName(), UserManager.SEARCH_TYPE_USER);
             found = false;
             while (it.hasNext() && !found) {
                 User nu = (User) it.next();
@@ -275,7 +280,7 @@
             }
             assertTrue("Searching for principal-name must find the created user.", found);
 
-            it = ((UserManagerImpl)userMgr).findUsers(uid);
+            it = userMgr.findAuthorizables(pUserID, uid, UserManager.SEARCH_TYPE_USER);
             found = false;
             while (it.hasNext() && !found) {
                 User nu = (User) it.next();
@@ -284,10 +289,10 @@
             assertTrue("Searching for user id must find the created user.", found);
 
             // but search groups should not find anything
-            it = ((UserManagerImpl)userMgr).findGroups(uid);
+            it = userMgr.findAuthorizables(pPrincipalName, p.getName(), UserManager.SEARCH_TYPE_GROUP);
             assertFalse(it.hasNext());
 
-            it = ((UserManagerImpl)userMgr).findGroups("");
+            it = userMgr.findAuthorizables(pPrincipalName, null, UserManager.SEARCH_TYPE_GROUP);
             while (it.hasNext()) {
                 if (((Authorizable) it.next()).getPrincipal().getName().equals(p.getName()))
{
                     fail("Searching for Groups should never find a user");
@@ -307,26 +312,24 @@
             gr = userMgr.createGroup(p);
 
             boolean found = false;
-            Iterator it = ((UserManagerImpl)userMgr).findGroups("");
+            Iterator it = userMgr.findAuthorizables(pPrincipalName, null, UserManager.SEARCH_TYPE_GROUP);
             while (it.hasNext() && !found) {
                 Group ng = (Group) it.next();
                 found = ng.getPrincipal().getName().equals(p.getName());
             }
             assertTrue("Searching for \"\" must find the created group.", found);
 
-            it = ((UserManagerImpl)userMgr).findGroups(p.getName());
-            found = false;
-            while (it.hasNext() && !found) {
-                Group ng = (Group) it.next();
-                found = ng.getPrincipal().getName().equals(p.getName());
-            }
-            assertTrue("Searching for principal-name must find the created group.", found);
+            it = userMgr.findAuthorizables(pPrincipalName, p.getName(), UserManager.SEARCH_TYPE_GROUP);
+            assertTrue(it.hasNext());
+            Group ng = (Group) it.next();
+            assertEquals("Searching for principal-name must find the created group.", p.getName(),
ng.getPrincipal().getName());
+            assertFalse("Only a single group must be found for a given principal name.",
it.hasNext());
 
             // but search users should not find anything
-            it = ((UserManagerImpl)userMgr).findUsers(p.getName());
+            it = userMgr.findAuthorizables(pPrincipalName, p.getName(), UserManager.SEARCH_TYPE_USER);
             assertFalse(it.hasNext());
 
-            it = ((UserManagerImpl)userMgr).findUsers("");
+            it = userMgr.findAuthorizables(pPrincipalName, null, UserManager.SEARCH_TYPE_USER);
             while (it.hasNext()) {
                 if (((Authorizable) it.next()).getPrincipal().getName().equals(p.getName()))
{
                     fail("Searching for Users should never find a group");
@@ -340,14 +343,14 @@
     }
 
     public void testFindAllUsers() throws RepositoryException {
-        Iterator it = ((UserManagerImpl)userMgr).findUsers("");
+        Iterator it = userMgr.findAuthorizables(pPrincipalName, null, UserManager.SEARCH_TYPE_USER);
         while (it.hasNext()) {
             assertFalse(((Authorizable) it.next()).isGroup());
         }
     }
 
     public void testFindAllGroups() throws RepositoryException {
-        Iterator it = ((UserManagerImpl)userMgr).findGroups("");
+        Iterator it = userMgr.findAuthorizables(pPrincipalName, null, UserManager.SEARCH_TYPE_GROUP);
         while (it.hasNext()) {
             assertTrue(((Authorizable) it.next()).isGroup());
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/repository/repository.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/repository/repository.xml?rev=689499&r1=689498&r2=689499&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/repository/repository.xml (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/repository/repository.xml Wed Aug 27 08:12:04
2008
@@ -48,14 +48,14 @@
         </AccessManager>
 
         <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
-           <!-- anonymous user name ('anonymous' is the default value) -->
+           <!-- 
+              anonymous user name ('anonymous' is the default value)
+            -->
            <param name="anonymousId" value="anonymous"/>
-           <param name="adminId" value="admin"/>
            <!--
-              default user name to be used instead of the anonymous user
-              when no login credentials are provided (unset by default)
-           -->
-           <!-- <param name="defaultUserId" value="superuser"/> -->
+              administrator user id (default value if param is missing is 'admin')
+            -->
+           <param name="adminId" value="admin"/>
         </LoginModule>
     </Security>
 

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/NameParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/NameParser.java?rev=689499&r1=689498&r2=689499&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/NameParser.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/NameParser.java
Wed Aug 27 08:12:04 2008
@@ -34,11 +34,15 @@
     private static final int STATE_PREFIX = 1;
     private static final int STATE_NAME_START = 2;
     private static final int STATE_NAME = 3;
+    private static final int STATE_URI_START = 4;
+    private static final int STATE_URI = 5;
 
     /**
-     * Parses the <code>jcrName</code> and returns a new <code>Name</code>.
+     * Parses the <code>jcrName</code> (either qualified or expanded) and
+     * returns a new <code>Name</code>.
      *
-     * @param jcrName the name to be parsed
+     * @param jcrName the name to be parsed. The jcrName may either in the
+     * qualified or in the expanded form.
      * @param resolver <code>NamespaceResolver</code> use to retrieve the
      * namespace URI from the prefix contained in the given JCR name.
      * @return qName the new <code>Name</code>
@@ -59,6 +63,7 @@
 
         // parse the name
         String prefix = "";
+        String uri = null;
         int nameStart = 0;
         int state = STATE_PREFIX_START;
         boolean trailingSpaces = false;
@@ -77,6 +82,8 @@
                         throw new IllegalNameException("Invalid name prefix: "+ prefix);
                     }
                     state = STATE_NAME_START;
+                } else if (state == STATE_URI) {
+                    // ignore -> validation of uri later on.
                 } else {
                     throw new IllegalNameException("'" + c + "' not allowed in name");
                 }
@@ -86,19 +93,74 @@
                     throw new IllegalNameException("'" + c + "' not valid name start");
                 }
                 trailingSpaces = true;
-            } else if (Character.isWhitespace(c) || c == '/' || c == '[' || c == ']' || c
== '*' || c == '\'' || c == '\"') {
+            } else if (Character.isWhitespace(c) || c == '[' || c == ']' || c == '*' || c
== '\'' || c == '\"') {
                 throw new IllegalNameException("'" + c + "' not allowed in name");
+            } else if (c == '/') {
+                if (state == STATE_URI_START) {
+                    state = STATE_URI;
+                } else if (state != STATE_URI) {
+                    throw new IllegalNameException("'" + c + "' not allowed in name");
+                }
+                trailingSpaces = false;
+            } else if (c == '{') {
+                if (state == STATE_PREFIX_START) {
+                    state = STATE_URI_START;
+                } else if (state == STATE_URI_START || state == STATE_URI) {
+                    // second '{' in the uri-part -> no valid expanded jcr-name.
+                    // therefore reset the nameStart and change state.
+                    state = STATE_NAME;
+                    nameStart = 0;
+                } else if (state == STATE_NAME_START) {
+                    state = STATE_NAME;
+                    nameStart = i;
+                }
+                trailingSpaces = false;
+            } else if (c == '}') {
+                if (state == STATE_URI_START || state == STATE_URI) {
+                    String tmp = jcrName.substring(1, i);
+                    try {
+                        // make sure the uri is a known namespace uri
+                        // TODO: since namespace registration does not validate
+                        //       the URI format validation is omitted here
+                        resolver.getPrefix(tmp);
+                        uri = tmp;
+                        state = STATE_NAME_START;
+                    } catch (NamespaceException e) {
+                        // unknown uri -> apparently a localname starting with {
+                        // -> make sure there are no invalid characters
+                        if (tmp.indexOf(':') == -1 && tmp.indexOf('/') == -1) {
+                            state = STATE_NAME;
+                            nameStart = 0;
+                        } else {
+                            throw new IllegalNameException("Unknown uri " + tmp + ". But
':' and '/' are not allowed in a local name.");
+                        }
+                    }
+                } else if (state == STATE_PREFIX_START) {
+                    state = STATE_PREFIX; // prefix start -> validation later on will
fail.
+                } else if (state == STATE_NAME_START) {
+                    state = STATE_NAME;
+                    nameStart = i;
+                }
+                trailingSpaces = false;
             } else {
                 if (state == STATE_PREFIX_START) {
                     state = STATE_PREFIX; // prefix start
                 } else if (state == STATE_NAME_START) {
                     state = STATE_NAME;
                     nameStart = i;
+                } else if (state == STATE_URI_START) {
+                    state = STATE_URI;
                 }
                 trailingSpaces = false;
             }
         }
 
+        // take care of qualified jcrNames starting with '{' that are not having
+        // a terminating '}' -> make sure there are no illegal characters present.
+        if (state == STATE_URI && (jcrName.indexOf(':') > -1 || jcrName.indexOf('/')
> -1)) {
+            throw new IllegalNameException("Local name may not contain ':' nor '/'");
+        }
+
         if (nameStart == len || state == STATE_NAME_START) {
             throw new IllegalNameException("Local name must not be empty");
         }
@@ -113,8 +175,12 @@
         }
 
         // resolve prefix to uri
-        String uri = resolver.getURI(prefix);
-        return factory.create(uri, nameStart == 0 ? jcrName : jcrName.substring(nameStart,
len));
+        if (uri == null) {
+            uri = resolver.getURI(prefix);
+        }
+
+        String localName = (nameStart == 0 ? jcrName : jcrName.substring(nameStart, len));
+        return factory.create(uri, localName);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java?rev=689499&r1=689498&r2=689499&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java
Wed Aug 27 08:12:04 2008
@@ -24,6 +24,9 @@
 import junit.framework.TestCase;
 
 import javax.jcr.NamespaceException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
 
 /**
  * <code>NameParserTest</code>...
@@ -87,4 +90,114 @@
             }
         }
     }
+
+    public void testExpandedJcrNames() throws NamespaceException, IllegalNameException {
+        NamespaceResolver resolver = new TestNamespaceResolver();
+
+        List valid = new ArrayList();
+        // valid qualified jcr-names:
+        // String-array consisting of { jcrName , uri , localName }
+        valid.add(new String[] {"abc:{c}", "abc", "{c}"});
+        valid.add(new String[] {"abc:}c", "abc", "}c"});
+        valid.add(new String[] {"abc:c}", "abc", "c}"});
+        valid.add(new String[] {"{ab", "", "{ab"});
+        valid.add(new String[] {"ab}", "", "ab}"});
+        valid.add(new String[] {"a}bc", "", "a}bc"});
+        valid.add(new String[] {"{", "", "{"});
+        valid.add(new String[] {"}", "", "}"});
+        valid.add(new String[] {"abc", "", "abc"});
+        valid.add(new String[] {"abc{abc}", "", "abc{abc}"});
+        valid.add(new String[] {"{{abc}", "", "{{abc}"});
+        valid.add(new String[] {"{abc{abc}", "", "{abc{abc}"});
+        valid.add(new String[] {"abc {", "", "abc {"});
+        valid.add(new String[] {"abc { }", "", "abc { }"});
+        valid.add(new String[] {"{ ab }", "", "{ ab }"});
+        valid.add(new String[] {"{ }abc", "", "{ }abc"});
+        // unknown uri -> but valid non-prefixed jcr-name
+        valid.add(new String[] {"{test}abc", "", "{test}abc"});
+        valid.add(new String[] {"{ab}", "", "{ab}"});
+
+        // valid expanded jcr-names:
+        // String-array consisting of { jcrName , uri , localName }
+        valid.add(new String[] {"{http://jackrabbit.apache.org}abc", "http://jackrabbit.apache.org",
"abc"});
+        valid.add(new String[] {"{http://jackrabbit.apache.org:80}abc", "http://jackrabbit.apache.org:80",
"abc"});
+        valid.add(new String[] {"{http://jackrabbit.apache.org/info}abc", "http://jackrabbit.apache.org/info",
"abc"});
+        valid.add(new String[] {"{jcr:jackrabbit}abc", "jcr:jackrabbit", "abc"});
+        valid.add(new String[] {"{/jackrabbit/a/b/c}abc", "/jackrabbit/a/b/c", "abc"});
+        valid.add(new String[] {"{abc}def", "abc", "def"});
+        valid.add(new String[] {"{}abc", "", "abc"});
+
+        for (Iterator it = valid.iterator(); it.hasNext();) {
+            String[] strs = (String[]) it.next();
+            try {
+                Name n = NameParser.parse(strs[0], resolver, factory);
+                assertEquals("URI mismatch", strs[1], n.getNamespaceURI());
+                assertEquals("Local name mismatch", strs[2], n.getLocalName());
+            } catch (Exception e) {
+                fail(e.getMessage() + " -> " + strs[0]);
+            }
+        }
+
+        // invalid jcr-names (neither expanded nor qualified form)
+        List invalid = new ArrayList();
+        // invalid prefix
+        invalid.add("{a:b");
+        invalid.add("}a:b");
+        invalid.add("a{b:c");
+        invalid.add("a}b:c");
+        // unknown uri -> but invalid local name with ':' and or '/'
+        invalid.add("{http//:test.apache.org}abc");
+        invalid.add("{test/test/test}abc");
+        // invalid local name containing '/'
+        invalid.add("{http://jackrabbit.apache.org}abc/dfg");
+        // invalid local name containing ':'
+        invalid.add("{http://jackrabbit.apache.org}abc:dfg");
+        // invalid local name containing ':' and '/'
+        invalid.add("{{http://jackrabbit.apache.org}abc:dfg}");
+        // invalid local name containing '/'
+        invalid.add("/a/b/c");
+        // known uri but local name missing -> must fail.
+        invalid.add("{abc}");
+        invalid.add("{http://jackrabbit.apache.org}");
+        invalid.add("{}");
+
+        for (Iterator it = invalid.iterator(); it.hasNext();) {
+            String jcrName = (String) it.next();
+            try {
+                NameParser.parse(jcrName, resolver, factory);
+                fail("Parsing '" + jcrName + "' should fail. Not a valid jcr name.");
+            } catch (IllegalNameException e) {
+                //ok
+            }
+        }
+    }
+
+    /**
+     * Dummy NamespaceResolver that only knows the empty namespace and
+     * namespaces containing either 'jackrabbit' or 'abc'. Used to test
+     * the parsing of the expanded jcr names, which should treat a jcr name with
+     * unknown namespace uri qualified jcr names.
+     */
+    private class TestNamespaceResolver implements NamespaceResolver {
+
+        public String getURI(String prefix) throws NamespaceException {
+            if (prefix.length() == 0 ||
+                prefix.indexOf("jackrabbit") > -1 ||
+                prefix.indexOf("abc") > -1 ){
+                return prefix;
+            } else {
+                throw new NamespaceException("Unknown namespace prefix " + prefix);
+            }
+        }
+
+        public String getPrefix(String uri) throws NamespaceException {
+            if (uri.length() == 0 ||
+                uri.indexOf("jackrabbit") > -1 ||
+                uri.indexOf("abc") > -1 ){
+                return uri;
+            } else {
+                throw new NamespaceException("Unknown namespace prefix " + uri);
+            }
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/repository.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/repository.xml?rev=689499&r1=689498&r2=689499&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/repository.xml (original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/repository.xml Wed Aug 27 08:12:04
2008
@@ -51,11 +51,6 @@
            <!-- anonymous user name ('anonymous' is the default value) -->
            <param name="anonymousId" value="anonymous"/>
            <param name="adminId" value="admin"/>
-           <!--
-              default user name to be used instead of the anonymous user
-              when no login credentials are provided (unset by default)
-           -->
-           <!-- <param name="defaultUserId" value="superuser"/> -->
         </LoginModule>
     </Security>
 



Mime
View raw message