Search in sources :

Example 1 with UnauthorizedException

use of org.collectionspace.csp.api.persistence.UnauthorizedException 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 UnauthorizedException

use of org.collectionspace.csp.api.persistence.UnauthorizedException 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)

Example 3 with UnauthorizedException

use of org.collectionspace.csp.api.persistence.UnauthorizedException in project application by collectionspace.

the class WebUI method serviceRequest.

@Override
public void serviceRequest(UIRequest ui) throws UIException, UnauthorizedException {
    CSPRequestCache cache = new RequestCache();
    String[] path = ui.getPrincipalPath();
    Request r = new Request(xxx_storage, cache, ui);
    String test = ui.getRequestedOperation().toString();
    log.debug("ServiceRequest path: " + StringUtils.join(path, "/"));
    log.debug(test);
    try {
        if (tries.get(ui.getRequestedOperation()).call(path, r))
            return;
    } catch (UIException e) {
        throw e;
    } catch (UnauthorizedException ue) {
        throw ue;
    } catch (Exception e) {
        log.error("Error in WebUI.serviceRequest", e);
        log.error(String.format("Request body= %s", ui.getBody()));
        throw new UIException("Error in read", e);
    }
    throw new UIException("path not used");
}
Also used : CSPRequestCache(org.collectionspace.csp.api.core.CSPRequestCache) RequestCache(org.collectionspace.csp.helper.core.RequestCache) UIRequest(org.collectionspace.csp.api.ui.UIRequest) UnauthorizedException(org.collectionspace.csp.api.persistence.UnauthorizedException) UIException(org.collectionspace.csp.api.ui.UIException) CSPRequestCache(org.collectionspace.csp.api.core.CSPRequestCache) UIException(org.collectionspace.csp.api.ui.UIException) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) UnauthorizedException(org.collectionspace.csp.api.persistence.UnauthorizedException)

Aggregations

UnauthorizedException (org.collectionspace.csp.api.persistence.UnauthorizedException)3 ConflictException (org.collectionspace.csp.api.persistence.ConflictException)2 UIException (org.collectionspace.csp.api.ui.UIException)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 CSPDependencyException (org.collectionspace.csp.api.core.CSPDependencyException)1 CSPRequestCache (org.collectionspace.csp.api.core.CSPRequestCache)1 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)1 UIRequest (org.collectionspace.csp.api.ui.UIRequest)1 RequestCache (org.collectionspace.csp.helper.core.RequestCache)1