Search in sources :

Example 6 with NoSuchWorkspaceException

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

the class NodeTest method testGetCorrespondingNodePathNoSuchWorkspaceException.

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

Example 7 with NoSuchWorkspaceException

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

the class ConnectionFactoryTest method testExceptionHandling.

/**
     * Tests if a NoSuchWorkspaceException is thrown if a wrong workspace name is given to login
     */
public void testExceptionHandling() throws Exception {
    Object cf = mcf.createConnectionFactory();
    Repository repository = (Repository) cf;
    try {
        repository.login(JCR_SUPERUSER, "xxx");
    } catch (Exception e) {
        assertTrue(e instanceof NoSuchWorkspaceException);
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) Repository(javax.jcr.Repository) NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException)

Example 8 with NoSuchWorkspaceException

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

the class AbstractLoginFilter method doFilter.

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    try {
        Credentials credentials = getCredentials(httpRequest);
        Session session = repository.login(credentials, workspace);
        try {
            request.setAttribute(sessionAttribute, session);
            request.setAttribute(nodeAttribute, session.getRootNode());
            chain.doFilter(request, response);
            if (session.hasPendingChanges()) {
                session.save();
            }
        } finally {
            session.logout();
        }
    } catch (ServletException e) {
        Throwable cause = e.getRootCause();
        if (cause instanceof AccessDeniedException) {
            httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN, cause.getMessage());
        } else {
            throw e;
        }
    } catch (LoginException e) {
        httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
    } catch (NoSuchWorkspaceException e) {
        throw new ServletException("Workspace " + workspace + " not found in the content repository", e);
    } catch (RepositoryException e) {
        throw new ServletException("Unable to access the content repository", e);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) AccessDeniedException(javax.jcr.AccessDeniedException) HttpServletResponse(javax.servlet.http.HttpServletResponse) LoginException(javax.jcr.LoginException) RepositoryException(javax.jcr.RepositoryException) Credentials(javax.jcr.Credentials) Session(javax.jcr.Session)

Example 9 with NoSuchWorkspaceException

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

the class OakServlet method service.

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        Credentials credentials = null;
        String authorization = request.getHeader("Authorization");
        if (authorization != null && authorization.startsWith("Basic ")) {
            String[] basic = Base64.decode(authorization.substring("Basic ".length())).split(":");
            credentials = new SimpleCredentials(basic[0], basic[1].toCharArray());
        } else {
            throw new LoginException();
        }
        ContentSession session = repository.login(credentials, null);
        try {
            Root root = session.getLatestRoot();
            request.setAttribute("root", root);
            // Find the longest part of the given path that matches
            // an existing node. The tail part might be used when
            // creating new nodes or when exposing virtual resources.
            // Note that we need to traverse the path in reverse
            // direction as some parent nodes may be read-protected.
            String head = request.getPathInfo();
            String tail = "";
            Tree tree = root.getTree(head);
            while (!tree.exists()) {
                if (tree.isRoot()) {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                    return;
                }
                tail = "/" + tree.getName() + tail;
                tree = tree.getParent();
            }
            request.setAttribute("tree", tree);
            request.setAttribute("path", tail);
            super.service(request, response);
        } finally {
            session.close();
        }
    } catch (NoSuchWorkspaceException e) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } catch (LoginException e) {
        response.setHeader("WWW-Authenticate", "Basic realm=\"Oak\"");
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) SimpleCredentials(javax.jcr.SimpleCredentials) Root(org.apache.jackrabbit.oak.api.Root) LoginException(javax.security.auth.login.LoginException) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Tree(org.apache.jackrabbit.oak.api.Tree) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials)

Example 10 with NoSuchWorkspaceException

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

the class DavSessionProviderImpl method attachSession.

/**
     * Acquires a DavSession. Upon success, the WebdavRequest will
     * reference that session.
     *
     * A session will not be available if an exception is thrown.
     *
     * @param request
     * @throws org.apache.jackrabbit.webdav.DavException if a problem occurred while obtaining the session
     * @see DavSessionProvider#attachSession(org.apache.jackrabbit.webdav.WebdavRequest)
     */
public boolean attachSession(WebdavRequest request) throws DavException {
    try {
        // retrieve the workspace name
        String workspaceName = request.getRequestLocator().getWorkspaceName();
        // empty workspaceName rather means default -> must be 'null'
        if (workspaceName != null && "".equals(workspaceName)) {
            workspaceName = null;
        }
        // login to repository
        Session repSession = sesProvider.getSession(request, repository, workspaceName);
        if (repSession == null) {
            log.debug("Could not to retrieve a repository session.");
            return false;
        }
        DavSession ds = new DavSessionImpl(repSession);
        log.debug("Attaching session '" + ds + "' to request '" + request + "'");
        request.setDavSession(ds);
        return true;
    } catch (NoSuchWorkspaceException e) {
        // which seems not appropriate here
        throw new JcrDavException(e, DavServletResponse.SC_NOT_FOUND);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    } catch (ServletException e) {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) ServletException(javax.servlet.ServletException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) RepositoryException(javax.jcr.RepositoryException) DavSession(org.apache.jackrabbit.webdav.DavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession)

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