Search in sources :

Example 91 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class InterruptedQueryTest method testQuery.

@Test
public void testQuery() throws Exception {
    if (Constants.WINDOWS) {
        return;
    }
    for (int i = 0; i < 100; i++) {
        session.getRootNode().addNode("node" + i, "nt:unstructured");
    }
    session.save();
    final QueryManager qm = session.getWorkspace().getQueryManager();
    final AtomicBoolean stop = new AtomicBoolean(false);
    final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            while (!stop.get() && exceptions.isEmpty()) {
                try {
                    // execute query
                    String stmt = "//*[@jcr:primaryType='nt:unstructured']";
                    qm.createQuery(stmt, Query.XPATH).execute();
                } catch (RepositoryException e) {
                    if (Constants.SUN_OS) {
                        // on Solaris it's OK when the root cause
                        // of the exception is an InterruptedIOException
                        // the underlying file is not closed
                        Throwable t = e;
                        while (t.getCause() != null) {
                            t = t.getCause();
                        }
                        if (!(t instanceof InterruptedIOException)) {
                            exceptions.add(e);
                        }
                    } else {
                        exceptions.add(e);
                    }
                }
            }
        }
    });
    t.start();
    for (int i = 0; i < 200 && t.isAlive(); i++) {
        t.interrupt();
        Thread.sleep((long) (100.0 * Math.random()));
    }
    stop.set(true);
    t.join();
    if (!exceptions.isEmpty()) {
        throw exceptions.get(0);
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) RepositoryException(javax.jcr.RepositoryException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QueryManager(javax.jcr.query.QueryManager) Test(org.junit.Test)

Example 92 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class GQLTest method testFilterLimit.

public void testFilterLimit() throws RepositoryException {
    final Node n1 = testRootNode.addNode("node1");
    n1.setProperty("jcr:title", "a");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("jcr:title", "b");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("jcr:title", "c");
    superuser.save();
    String stmt = createStatement("order:jcr:title limit:1");
    RowIterator rows = GQL.execute(stmt, superuser, null, new GQL.Filter() {

        public boolean include(Row row) throws RepositoryException {
            return !n1.getPath().equals(row.getValue("jcr:path").getString());
        }
    });
    checkResultSequence(rows, new Node[] { n2 });
}
Also used : GQL(org.apache.jackrabbit.commons.query.GQL) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator) RepositoryException(javax.jcr.RepositoryException) Row(javax.jcr.query.Row)

Example 93 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class AbstractEntryTest method testHashCode.

public void testHashCode() throws RepositoryException, NotExecutableException {
    Map<AccessControlEntry, AccessControlEntry> equivalent = new HashMap<AccessControlEntry, AccessControlEntry>();
    JackrabbitAccessControlEntry ace = createEntry(new String[] { Privilege.JCR_ALL }, true);
    // create same entry again
    equivalent.put(ace, createEntry(new String[] { Privilege.JCR_ALL }, true));
    // create entry with declared aggregate privileges
    Privilege[] declaredAllPrivs = acMgr.privilegeFromName(Privilege.JCR_ALL).getDeclaredAggregatePrivileges();
    equivalent.put(ace, createEntry(testPrincipal, declaredAllPrivs, true));
    // create entry with aggregate privileges
    Privilege[] aggregateAllPrivs = acMgr.privilegeFromName(Privilege.JCR_ALL).getAggregatePrivileges();
    equivalent.put(ace, createEntry(testPrincipal, aggregateAllPrivs, true));
    // create entry with different privilege order
    List<Privilege> reordered = new ArrayList<Privilege>(Arrays.asList(aggregateAllPrivs));
    reordered.add(reordered.remove(0));
    equivalent.put(createEntry(testPrincipal, reordered.toArray(new Privilege[reordered.size()]), true), createEntry(testPrincipal, aggregateAllPrivs, true));
    // even if entries are build with aggregated or declared aggregate privileges
    equivalent.put(createEntry(testPrincipal, declaredAllPrivs, true), createEntry(testPrincipal, aggregateAllPrivs, true));
    for (AccessControlEntry entry : equivalent.keySet()) {
        assertEquals(entry.hashCode(), equivalent.get(entry).hashCode());
    }
    // and the opposite:
    List<JackrabbitAccessControlEntry> otherAces = new ArrayList<JackrabbitAccessControlEntry>();
    try {
        // ACE template with different principal
        Principal princ = new Principal() {

            public String getName() {
                return "a name";
            }
        };
        Privilege[] privs = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_ALL) };
        otherAces.add(createEntry(princ, privs, true));
    } catch (RepositoryException e) {
    }
    // ACE template with different privileges
    try {
        otherAces.add(createEntry(new String[] { Privilege.JCR_READ }, true));
    } catch (RepositoryException e) {
    }
    // ACE template with different 'allow' flag
    try {
        otherAces.add(createEntry(new String[] { Privilege.JCR_ALL }, false));
    } catch (RepositoryException e) {
    }
    // ACE template with different privileges and 'allows
    try {
        otherAces.add(createEntry(new String[] { PrivilegeRegistry.REP_WRITE }, false));
    } catch (RepositoryException e) {
    }
    // other ace impl
    final Privilege[] privs = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_ALL) };
    JackrabbitAccessControlEntry pe = new JackrabbitAccessControlEntry() {

        public boolean isAllow() {
            return true;
        }

        public String[] getRestrictionNames() {
            return new String[0];
        }

        public Value getRestriction(String restrictionName) {
            return null;
        }

        public Value[] getRestrictions(String restrictionName) throws RepositoryException {
            return null;
        }

        public Principal getPrincipal() {
            return testPrincipal;
        }

        public Privilege[] getPrivileges() {
            return privs;
        }
    };
    otherAces.add(pe);
    for (JackrabbitAccessControlEntry otherAce : otherAces) {
        assertFalse(ace.hashCode() == otherAce.hashCode());
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) RepositoryException(javax.jcr.RepositoryException) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) Value(javax.jcr.Value) Privilege(javax.jcr.security.Privilege) Principal(java.security.Principal)

Example 94 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class TokenBasedLoginTest method testConcurrentLoginOfDifferentUsers.

/**
     * Tests concurrent login of 3 different users on the Repository including
     * token creation.
     * Test copied and slightly adjusted from org.apache.jackrabbit.core.ConcurrentLoginTest
     */
public void testConcurrentLoginOfDifferentUsers() throws RepositoryException, NotExecutableException {
    final Exception[] exception = new Exception[1];
    List<Thread> testRunner = new ArrayList<Thread>();
    for (int i = 0; i < 10; i++) {
        testRunner.add(new Thread(new Runnable() {

            public void run() {
                for (int i = 0; i < 100; i++) {
                    try {
                        SimpleCredentials c;
                        double rand = 3 * Math.random();
                        int index = (int) Math.floor(rand);
                        switch(index) {
                            case 0:
                                c = new SimpleCredentials(testuser.getID(), testuser.getID().toCharArray());
                                break;
                            case 1:
                                c = new SimpleCredentials(getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_SUPERUSER_NAME), getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_SUPERUSER_PWD).toCharArray());
                                break;
                            default:
                                c = new SimpleCredentials(getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_READONLY_NAME), getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_READONLY_PWD).toCharArray());
                                break;
                        }
                        c.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, "");
                        Session s = getHelper().getRepository().login(c);
                        try {
                            Set<TokenCredentials> tcs = ((SessionImpl) s).getSubject().getPublicCredentials(TokenCredentials.class);
                            assertFalse(tcs.isEmpty());
                        } finally {
                            s.logout();
                        }
                    } catch (Exception e) {
                        exception[0] = e;
                        break;
                    }
                }
            }
        }));
    }
    // start threads
    for (Object aTestRunner : testRunner) {
        ((Thread) aTestRunner).start();
    }
    // join threads
    for (Object aTestRunner : testRunner) {
        try {
            ((Thread) aTestRunner).join();
        } catch (InterruptedException e) {
            fail(e.toString());
        }
    }
    if (exception[0] != null) {
        fail(exception[0].toString());
    }
}
Also used : ArrayList(java.util.ArrayList) LoginException(javax.jcr.LoginException) RepositoryException(javax.jcr.RepositoryException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) SimpleCredentials(javax.jcr.SimpleCredentials) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)

Example 95 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class AbstractACLTemplateTest method testRemoveInvalidEntry.

public void testRemoveInvalidEntry() throws RepositoryException {
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    try {
        pt.removeAccessControlEntry(new JackrabbitAccessControlEntry() {

            public boolean isAllow() {
                return false;
            }

            public String[] getRestrictionNames() {
                return new String[0];
            }

            public Value getRestriction(String restrictionName) {
                return null;
            }

            public Value[] getRestrictions(String restrictionName) throws RepositoryException {
                return null;
            }

            public Principal getPrincipal() {
                return testPrincipal;
            }

            public Privilege[] getPrivileges() {
                try {
                    return privilegesFromName(Privilege.JCR_READ);
                } catch (Exception e) {
                    return new Privilege[0];
                }
            }
        });
        fail("Passing an unknown ACE should fail");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) Value(javax.jcr.Value) AccessControlException(javax.jcr.security.AccessControlException) RepositoryException(javax.jcr.RepositoryException) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal) AccessControlException(javax.jcr.security.AccessControlException) RepositoryException(javax.jcr.RepositoryException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1236 Node (javax.jcr.Node)289 Session (javax.jcr.Session)182 IOException (java.io.IOException)156 ArrayList (java.util.ArrayList)106 Name (org.apache.jackrabbit.spi.Name)94 DavException (org.apache.jackrabbit.webdav.DavException)90 Test (org.junit.Test)87 Value (javax.jcr.Value)80 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)76 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)72 Path (org.apache.jackrabbit.spi.Path)67 ItemNotFoundException (javax.jcr.ItemNotFoundException)65 PathNotFoundException (javax.jcr.PathNotFoundException)65 NodeId (org.apache.jackrabbit.core.id.NodeId)64 Property (javax.jcr.Property)61 HashMap (java.util.HashMap)53 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)53 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)52 InvalidItemStateException (javax.jcr.InvalidItemStateException)50