Search in sources :

Example 11 with NoSuchWorkspaceException

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

the class RepositoryImpl method getWorkspaceInfo.

/**
     * Returns the {@link WorkspaceInfo} for the named workspace.
     *
     * @param workspaceName The name of the workspace whose {@link WorkspaceInfo}
     *                      is to be returned. This must not be <code>null</code>.
     * @return The {@link WorkspaceInfo} for the named workspace. This will
     *         never be <code>null</code>.
     * @throws NoSuchWorkspaceException If the named workspace does not exist.
     * @throws RepositoryException If this repository has been shut down.
     */
protected WorkspaceInfo getWorkspaceInfo(String workspaceName) throws NoSuchWorkspaceException, RepositoryException {
    // check sanity of this instance
    sanityCheck();
    WorkspaceInfo wspInfo;
    synchronized (wspInfos) {
        wspInfo = wspInfos.get(workspaceName);
        if (wspInfo == null) {
            throw new NoSuchWorkspaceException(workspaceName);
        }
    }
    try {
        wspInfo.initialize();
    } catch (RepositoryException e) {
        log.error("Unable to initialize workspace '" + workspaceName + "'", e);
        throw new NoSuchWorkspaceException(workspaceName);
    }
    return wspInfo;
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) RepositoryException(javax.jcr.RepositoryException)

Example 12 with NoSuchWorkspaceException

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

the class ContentRepositoryImpl method login.

@Nonnull
@Override
public ContentSession login(Credentials credentials, String workspaceName) throws LoginException, NoSuchWorkspaceException {
    if (workspaceName == null) {
        workspaceName = defaultWorkspaceName;
    }
    // TODO: support multiple workspaces. See OAK-118
    if (!defaultWorkspaceName.equals(workspaceName)) {
        throw new NoSuchWorkspaceException(workspaceName);
    }
    LoginContextProvider lcProvider = securityProvider.getConfiguration(AuthenticationConfiguration.class).getLoginContextProvider(this);
    LoginContext loginContext = lcProvider.getLoginContext(credentials, workspaceName);
    loginContext.login();
    return new ContentSessionImpl(loginContext, securityProvider, workspaceName, nodeStore, commitHook, queryEngineSettings, indexProvider);
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) AuthenticationConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.AuthenticationConfiguration) LoginContext(org.apache.jackrabbit.oak.spi.security.authentication.LoginContext) LoginContextProvider(org.apache.jackrabbit.oak.spi.security.authentication.LoginContextProvider) Nonnull(javax.annotation.Nonnull)

Example 13 with NoSuchWorkspaceException

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

the class OakTest method testWithDefaultWorkspaceName.

@Test
public void testWithDefaultWorkspaceName() throws Exception {
    ContentRepository repo = new Oak().with("test").with(new OpenSecurityProvider()).createContentRepository();
    String[] valid = new String[] { null, "test" };
    for (String wspName : valid) {
        ContentSession cs = null;
        try {
            cs = repo.login(null, wspName);
            assertEquals("test", cs.getWorkspaceName());
        } finally {
            if (cs != null) {
                cs.close();
            }
        }
    }
    String[] invalid = new String[] { "", "another", Oak.DEFAULT_WORKSPACE_NAME };
    for (String wspName : invalid) {
        ContentSession cs = null;
        try {
            cs = repo.login(null, wspName);
            fail("invalid workspace nam");
        } catch (NoSuchWorkspaceException e) {
        // success
        } finally {
            if (cs != null) {
                cs.close();
            }
        }
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Test(org.junit.Test)

Example 14 with NoSuchWorkspaceException

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

the class CacheValidatorProviderTest method getCache.

private Tree getCache(@Nonnull Authorizable authorizable) throws Exception {
    ContentSession cs = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {

        @Override
        public ContentSession run() throws LoginException, NoSuchWorkspaceException {
            return login(null);
        }
    });
    try {
        Root r = cs.getLatestRoot();
        NodeUtil n = new NodeUtil(r.getTree(authorizable.getPath()));
        NodeUtil c = n.getOrAddChild(CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE);
        c.setLong(CacheConstants.REP_EXPIRATION, 1);
        r.commit(CacheValidatorProvider.asCommitAttributes());
    } finally {
        cs.close();
    }
    root.refresh();
    return root.getTree(authorizable.getPath()).getChild(CacheConstants.REP_CACHE);
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) Root(org.apache.jackrabbit.oak.api.Root) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) LoginException(javax.security.auth.login.LoginException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil)

Example 15 with NoSuchWorkspaceException

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

the class WorkspaceTest method testDeleteWorkspace.

public void testDeleteWorkspace() throws Exception {
    try {
        Workspace wsp = superuser.getWorkspace();
        String name = getNewWorkspaceName(wsp);
        wsp.createWorkspace(name, wsp.getName());
        List<String> wsps = Arrays.asList(wsp.getAccessibleWorkspaceNames());
        assertTrue(wsps.contains(name));
        wsp.deleteWorkspace(name);
        wsps = Arrays.asList(wsp.getAccessibleWorkspaceNames());
        assertFalse(wsps.contains(name));
        Session s = null;
        try {
            s = getHelper().getSuperuserSession(name);
            fail(name + " has been deleted.");
        } catch (NoSuchWorkspaceException e) {
        // success
        } finally {
            if (s != null) {
                s.logout();
            }
        }
    } catch (UnsupportedRepositoryOperationException e) {
        throw new NotExecutableException();
    } catch (UnsupportedOperationException e) {
        throw new NotExecutableException();
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Workspace(javax.jcr.Workspace) Session(javax.jcr.Session)

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