Search in sources :

Example 1 with ConflictException

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;
}
Also used : JSONObject(org.json.JSONObject) ConflictException(org.collectionspace.csp.api.persistence.ConflictException) UnauthorizedException(org.collectionspace.csp.api.persistence.UnauthorizedException) UnauthorizedException(org.collectionspace.csp.api.persistence.UnauthorizedException) JSONException(org.json.JSONException) ConflictException(org.collectionspace.csp.api.persistence.ConflictException) UIException(org.collectionspace.csp.api.ui.UIException) ConfigException(org.collectionspace.chain.csp.config.ConfigException)

Example 2 with ConflictException

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);
    }
}
Also used : ReturnedMultipartDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument) JSONObject(org.json.JSONObject) ConflictException(org.collectionspace.csp.api.persistence.ConflictException) UnauthorizedException(org.collectionspace.csp.api.persistence.UnauthorizedException) JSONException(org.json.JSONException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)

Aggregations

ConflictException (org.collectionspace.csp.api.persistence.ConflictException)2 UnauthorizedException (org.collectionspace.csp.api.persistence.UnauthorizedException)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 ConfigException (org.collectionspace.chain.csp.config.ConfigException)1 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)1 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)1 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)1 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)1 UIException (org.collectionspace.csp.api.ui.UIException)1