Search in sources :

Example 1 with NoSuchWorkspaceException

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

the class SessionImpl method impersonate.

/**
     * {@inheritDoc}
     */
@Override
public Session impersonate(Credentials otherCredentials) throws LoginException, RepositoryException {
    // check sanity of this session
    sanityCheck();
    if (!(otherCredentials instanceof SimpleCredentials)) {
        String msg = "impersonate failed: incompatible credentials, SimpleCredentials expected";
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    // set IMPERSONATOR_ATTRIBUTE attribute of given credentials
    // with subject of current session
    SimpleCredentials creds = (SimpleCredentials) otherCredentials;
    creds.setAttribute(SecurityConstants.IMPERSONATOR_ATTRIBUTE, subject);
    try {
        return getRepository().login(otherCredentials, getWorkspace().getName());
    } catch (NoSuchWorkspaceException nswe) {
        // should never get here...
        String msg = "impersonate failed";
        log.error(msg, nswe);
        throw new RepositoryException(msg, nswe);
    } finally {
        // make sure IMPERSONATOR_ATTRIBUTE is removed
        creds.removeAttribute(SecurityConstants.IMPERSONATOR_ATTRIBUTE);
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) SimpleCredentials(javax.jcr.SimpleCredentials) RepositoryException(javax.jcr.RepositoryException)

Example 2 with NoSuchWorkspaceException

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

the class RepositoryLoginTest method testNoSuchWorkspaceException.

/**
     * Tests if {@link javax.jcr.Repository#login(Credentials credentials, String workspaceName)}
     * throws a {@link javax.jcr.NoSuchWorkspaceException}
     * if no workspace of the requested name is existing.
     */
public void testNoSuchWorkspaceException() throws RepositoryException {
    Session session = getHelper().getReadOnlySession();
    String name;
    try {
        name = getNonExistingWorkspaceName(session);
    } finally {
        session.logout();
        session = null;
    }
    try {
        session = getHelper().getRepository().login(credentials, name);
        fail("login with a not available workspace name must throw a " + "NoSuchWorkspaceException");
    } catch (NoSuchWorkspaceException e) {
    // success
    } finally {
        if (session != null) {
            session.logout();
        }
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) Session(javax.jcr.Session)

Example 3 with NoSuchWorkspaceException

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

the class WorkspaceImpl method getQueryManager.

/**
     * {@inheritDoc}
     */
public synchronized QueryManager getQueryManager() throws RepositoryException {
    // check state of this instance
    sanityCheck();
    if (queryManager == null) {
        SearchManager searchManager;
        try {
            searchManager = context.getRepository().getSearchManager(wspConfig.getName());
            if (searchManager == null) {
                String msg = "no search manager configured for this workspace";
                log.debug(msg);
                throw new RepositoryException(msg);
            }
        } catch (NoSuchWorkspaceException nswe) {
            // should never get here
            String msg = "internal error: failed to instantiate query manager";
            log.debug(msg);
            throw new RepositoryException(msg, nswe);
        }
        queryManager = new QueryManagerImpl(context, searchManager);
    }
    return queryManager;
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) RepositoryException(javax.jcr.RepositoryException) QueryManagerImpl(org.apache.jackrabbit.core.query.QueryManagerImpl)

Example 4 with NoSuchWorkspaceException

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

the class AccessManagerTest method testCanAccessNotExistingWorkspace.

public void testCanAccessNotExistingWorkspace() throws RepositoryException, NotExecutableException {
    Session s = getHelper().getReadOnlySession();
    try {
        List<String> all = Arrays.asList(s.getWorkspace().getAccessibleWorkspaceNames());
        String testName = "anyWorkspace";
        int i = 0;
        while (all.contains(testName)) {
            testName = "anyWorkspace" + i;
            i++;
        }
        assertFalse(getAccessManager(s).canAccess(testName));
    } catch (NoSuchWorkspaceException e) {
    // fine as well.
    } finally {
        s.logout();
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) Session(javax.jcr.Session)

Example 5 with NoSuchWorkspaceException

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

the class NodeTest method testUpdateNoSuchWorkspaceException.

/**
     * Tries to use {@link javax.jcr.Node#update(String)} with an invalid
     * workspace.
     * <p>
     * This should throw an {@link javax.jcr.NoSuchWorkspaceException}.
     */
public void testUpdateNoSuchWorkspaceException() throws RepositoryException {
    // get default workspace test root node using superuser session
    Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
    // create a test node in default workspace
    Node testNode = defaultRootNode.addNode(nodeName1, testNodeType);
    // save changes
    superuser.save();
    try {
        testNode.update(getNonExistingWorkspaceName(superuser));
        fail("Calling Node.update() on a non existing workspace should throw NoSuchWorkspaceException");
    } catch (NoSuchWorkspaceException e) {
    // ok, works as expected
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) Node(javax.jcr.Node)

Aggregations

NoSuchWorkspaceException (javax.jcr.NoSuchWorkspaceException)15 RepositoryException (javax.jcr.RepositoryException)5 Session (javax.jcr.Session)5 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)3 Credentials (javax.jcr.Credentials)2 Node (javax.jcr.Node)2 SimpleCredentials (javax.jcr.SimpleCredentials)2 LoginException (javax.security.auth.login.LoginException)2 ServletException (javax.servlet.ServletException)2 Root (org.apache.jackrabbit.oak.api.Root)2 Nonnull (javax.annotation.Nonnull)1 AccessDeniedException (javax.jcr.AccessDeniedException)1 LoginException (javax.jcr.LoginException)1 Repository (javax.jcr.Repository)1 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 Workspace (javax.jcr.Workspace)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 QueryManagerImpl (org.apache.jackrabbit.core.query.QueryManagerImpl)1 ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)1