}
private SessionInfo obtain(CredentialsWrapper credentials, String workspaceName)
throws LoginException, NoSuchWorkspaceException, RepositoryException {
// check if the workspace with the given name is accessible
PropFindMethod method = null;
SessionInfoImpl sessionInfo = new SessionInfoImpl(credentials, workspaceName);
try {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
// for backwards compat. -> retrieve DAV:workspace if the newly
// added property (workspaceName) is not supported by the server.
nameSet.add(DeltaVConstants.WORKSPACE);
nameSet.add(JcrRemotingConstants.JCR_WORKSPACE_NAME_LN, ItemResourceConstants.NAMESPACE);
method = new PropFindMethod(uriResolver.getWorkspaceUri(workspaceName), nameSet, DEPTH_0);
getClient(sessionInfo).executeMethod(method);
MultiStatusResponse[] responses = method.getResponseBodyAsMultiStatus().getResponses();
if (responses.length != 1) {
throw new LoginException("Login failed: Unknown workspace '" + workspaceName+ "'.");
}
DavPropertySet props = responses[0].getProperties(DavServletResponse.SC_OK);
DavProperty<?> prop = props.get(JcrRemotingConstants.JCR_WORKSPACE_NAME_LN, ItemResourceConstants.NAMESPACE);
if (prop != null) {
String wspName = prop.getValue().toString();
if (workspaceName == null) {
// login with 'null' workspace name -> retrieve the effective
// workspace name from the property and recreate the SessionInfo.
sessionInfo = new SessionInfoImpl(credentials, wspName);
} else if (!wspName.equals(workspaceName)) {
throw new LoginException("Login failed: Invalid workspace name '" + workspaceName + "'.");
}
} else if (props.contains(DeltaVConstants.WORKSPACE)) {
String wspHref = new HrefProperty(props.get(DeltaVConstants.WORKSPACE)).getHrefs().get(0);
String wspName = Text.unescape(Text.getName(wspHref, true));
if (!wspName.equals(workspaceName)) {
throw new LoginException("Login failed: Invalid workspace name " + workspaceName);
}
} else {
throw new LoginException("Login failed: Unknown workspace '" + workspaceName+ "'.");
}
} catch (IOException e) {
throw new RepositoryException(e.getMessage());
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (method != null) {
method.releaseConnection();
}
}
// make sure the general namespace mappings have been loaded once
// before additional requests are executed that rely on the namespace