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