use of org.collectionspace.csp.api.persistence.ConflictException in project application by collectionspace.
the class WebLogin method loginAttempt.
/**
* If successful, returns null; otherwise, returns an error message.
* @param storage
* @param tenant
* @return
*/
private String loginAttempt(Storage storage, String tenant) {
// null equals success
String result = LOGIN_FAIL_ERR;
try {
String base = spec.getRecordByWebUrl("userperm").getID();
JSONObject activePermissions = storage.retrieveJSON(base + "/0/", new JSONObject());
// check tenant
if (activePermissions.has("account")) {
JSONObject acc = activePermissions.getJSONObject("account");
if (acc.has("tenantId")) {
if (acc.getString("tenantId").equals(tenant)) {
result = null;
}
}
}
} catch (UnauthorizedException ue) {
result = LOGIN_FAIL_ERR;
} catch (ConflictException e) {
result = LOGIN_CONFLICT_ERR;
} catch (Exception e) {
result = LOGIN_CONNECTION_ERR;
}
return result;
}
use of org.collectionspace.csp.api.persistence.ConflictException in project application by collectionspace.
the class AuthorizationStorage method simpleRetrieveJSONFullPath.
public JSONObject simpleRetrieveJSONFullPath(CSPRequestCredentials creds, CSPRequestCache cache, String filePath, Record thisr) throws ExistException, UnimplementedException, UnderlyingStorageException {
try {
JSONObject out = new JSONObject();
if (thisr.isMultipart()) {
ReturnedMultipartDocument doc = conn.getMultipartXMLDocument(RequestMethod.GET, filePath, null, creds, cache);
if ((doc.getStatus() < 200 || doc.getStatus() >= 300))
throw new UnderlyingStorageException("Does not exist ", doc.getStatus(), filePath);
for (String section : thisr.getServicesRecordPathKeys()) {
String path = thisr.getServicesRecordPath(section);
String[] parts = path.split(":", 2);
convertToJson(out, doc.getDocument(parts[0]), thisr, "GET", section, "", "");
}
} else {
ReturnedDocument doc = conn.getXMLDocument(RequestMethod.GET, filePath, null, creds, cache);
if ((doc.getStatus() < 200 || doc.getStatus() >= 300)) {
if (doc.getStatus() == 401) {
throw new UnauthorizedException("Username and/or password are invalid.", doc.getStatus(), filePath);
} else if (doc.getStatus() == 409) {
throw new ConflictException("Conflict with request. The user's tenant may be disabled. Contact your CollectionSpace administrator.", doc.getStatus(), filePath);
} else {
String status = Integer.toString(doc.getStatus());
throw new UnderlyingStorageException("Does not exist ", doc.getStatus(), filePath);
}
}
convertToJson(out, doc.getDocument(), thisr, "GET", "common", "");
}
return out;
} catch (ConnectionException e) {
throw new UnderlyingStorageException("Service layer exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
} catch (JSONException e) {
throw new UnderlyingStorageException("Service layer exception" + e.getLocalizedMessage(), e);
}
}
Aggregations