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);
}
}
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();
}
}
}
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;
}
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();
}
}
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
}
}
Aggregations