Search in sources :

Example 1 with AdminData

use of org.collectionspace.chain.csp.schema.AdminData in project application by collectionspace.

the class ServicesStorageGenerator method initializeAuthorities.

private void initializeAuthorities(CSPManager cspManager, Spec spec) {
    AdminData ad = spec.getAdminData();
    String adminUsername = ad.getAuthUser();
    String adminPass = ad.getAuthPass();
    // request.getSession().setValue(UISession.USERID,ad.getAuthUser());
    // request.getSession().setValue(UISession.PASSWORD,ad.getAuthPass());
    CSPRequestCredentials creds = this.createCredentials();
    creds.setCredential(CRED_USERID, spec.getAdminData().getAuthUser());
    creds.setCredential(CRED_PASSWORD, spec.getAdminData().getAuthPass());
    WebReset webReset = new WebReset(false, false);
    webReset.configure((WebUI) cspManager.getUI(""), spec);
    try {
        webReset.run(getStorage(creds, new RequestCache()), null, new String[0], false);
    } catch (UIException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : AdminData(org.collectionspace.chain.csp.schema.AdminData) WebReset(org.collectionspace.chain.csp.webui.misc.WebReset) CSPRequestCache(org.collectionspace.csp.api.core.CSPRequestCache) RequestCache(org.collectionspace.csp.helper.core.RequestCache) UIException(org.collectionspace.csp.api.ui.UIException) CSPRequestCredentials(org.collectionspace.csp.api.core.CSPRequestCredentials)

Example 2 with AdminData

use of org.collectionspace.chain.csp.schema.AdminData in project application by collectionspace.

the class TenantServlet method setCacheAge.

protected void setCacheAge(String tenant, String mimetype, String path, HttpServletResponse servlet_response) {
    ConfigRoot root = tenantCSPM.get(tenant).getConfigRoot();
    Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
    AdminData adminData = spec.getAdminData();
    // The default value
    int cacheAge = 0;
    if (MIME_HTML.equals(mimetype)) {
        cacheAge = adminData.getUiStaticHTMLResourcesCacheAge();
    } else if (MIME_CSS.equals(mimetype)) {
        cacheAge = adminData.getUiStaticCSSResourcesCacheAge();
    } else if (MIME_JSON.equals(mimetype)) {
        cacheAge = adminData.getUiStaticJSResourcesCacheAge();
    } else if (MIME_PLAIN.equals(mimetype) || mimetype == null) {
        // try to refine from extension
        if (path.endsWith(SUFFIX_PROPS)) {
            cacheAge = adminData.getUiStaticPropertiesResourcesCacheAge();
        } else if (path.endsWith(SUFFIX_JSON)) {
            cacheAge = adminData.getUiStaticJSResourcesCacheAge();
        }
    } else if (mimetype != null) {
        if (mimetype.startsWith(MIME_IMAGE) || mimetype.startsWith(MIME_AUDIO) || mimetype.startsWith(MIME_VIDIO)) {
            cacheAge = adminData.getUiStaticMediaResourcesCacheAge();
        }
    }
    if (cacheAge > 0) {
        // Create a cache header per the timeout requested (usu. by the individual request handler)
        servlet_response.addHeader("Cache-Control", "max-age=" + Integer.toString(cacheAge));
    }
}
Also used : AdminData(org.collectionspace.chain.csp.schema.AdminData) ConfigRoot(org.collectionspace.chain.csp.config.ConfigRoot) Spec(org.collectionspace.chain.csp.schema.Spec)

Example 3 with AdminData

use of org.collectionspace.chain.csp.schema.AdminData in project application by collectionspace.

the class UserDetailsReset method send_reset_email.

/* find csid for email, create token, email token to the user */
private void send_reset_email(Storage storage, UIRequest request, Request in) throws UIException {
    JSONObject data = null;
    data = request.getJSONBody();
    // mock login else service layer gets upset = not working
    // XXX ARGH
    AdminData ad = spec.getAdminData();
    request.getSession().setValue(UISession.USERID, ad.getAuthUser());
    request.getSession().setValue(UISession.PASSWORD, ad.getAuthPass());
    in.reset();
    JSONObject outputJSON = new JSONObject();
    if (testSuccess(in.getStorage())) {
        String emailparam = "";
        /* get csid of email address */
        try {
            emailparam = data.getString("email");
            JSONObject userdetails = getcsID(storage, emailparam);
            if (!userdetails.getBoolean("isError")) {
                String csid = userdetails.getString("csid");
                /* for debug purposes */
                if (data.has("debug") && data.getBoolean("debug")) {
                    // only send email if debug is false/null see unit test TestGeneral testPasswordReset
                    outputJSON.put("token", createToken(csid));
                    outputJSON.put("email", emailparam);
                } else {
                    doEmail(csid, emailparam, in, userdetails);
                }
                outputJSON.put("isError", false);
                JSONObject messages = new JSONObject();
                messages.put("message", "Password reset sent to " + emailparam);
                messages.put("severity", "info");
                JSONArray arr = new JSONArray();
                arr.put(messages);
                outputJSON.put("messages", arr);
            } else {
                outputJSON = userdetails;
            }
            request.getSession().setValue(UISession.USERID, "");
            request.getSession().setValue(UISession.PASSWORD, "");
            in.reset();
        } catch (UIException e) {
            // throw new UIException("Failed to send email",e);
            try {
                outputJSON.put("isError", true);
                JSONObject messages = new JSONObject();
                messages.put("message", "Failed to send email: " + e.getMessage());
                messages.put("severity", "error");
                JSONArray arr = new JSONArray();
                arr.put(messages);
                outputJSON.put("messages", arr);
            } catch (JSONException e1) {
                throw new UIException("JSONException during error messaging", e);
            }
        } catch (JSONException e) {
            throw new UIException("JSONException during search on email address", e);
        }
    } else {
        try {
            outputJSON.put("isError", true);
            JSONObject messages = new JSONObject();
            messages.put("message", "The admin details in cspace-config.xml failed");
            messages.put("severity", "error");
            JSONArray arr = new JSONArray();
            arr.put(messages);
            outputJSON.put("messages", arr);
        } catch (JSONException x) {
            throw new UIException("Failed to parse json: ", x);
        }
    }
    request.sendJSONResponse(outputJSON);
    request.setOperationPerformed(Operation.CREATE);
}
Also used : AdminData(org.collectionspace.chain.csp.schema.AdminData) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) UIException(org.collectionspace.csp.api.ui.UIException) JSONException(org.json.JSONException)

Example 4 with AdminData

use of org.collectionspace.chain.csp.schema.AdminData in project application by collectionspace.

the class UserDetailsReset method reset_password.

/* check token and if matches csid then reset password 
	 * */
private void reset_password(Storage storage, UIRequest request, Request in) throws UIException {
    // mock login else service layer gets upset
    // XXX ARGH
    AdminData ad = spec.getAdminData();
    request.getSession().setValue(UISession.USERID, ad.getAuthUser());
    request.getSession().setValue(UISession.PASSWORD, ad.getAuthPass());
    in.reset();
    JSONObject outputJSON = new JSONObject();
    if (testSuccess(in.getStorage())) {
        JSONObject data = null;
        data = request.getJSONBody();
        String token;
        try {
            token = data.getString("token");
            String password = data.getString("password");
            String email = data.getString("email");
            JSONObject userdetails = getcsID(storage, email);
            if (!userdetails.getBoolean("isError")) {
                String csid = userdetails.getString("csid");
                if (testToken(csid, token)) {
                    /* update userdetails */
                    String path = csid;
                    JSONObject fields = userdetails.getJSONObject("fields");
                    try {
                        JSONObject changedata = new JSONObject();
                        JSONObject updatefields = fields;
                        updatefields.put("password", password);
                        changedata.put("fields", updatefields);
                        changedata.put("csid", csid);
                        sendJSON(storage, path, changedata);
                        outputJSON.put("isError", false);
                        JSONObject messages = new JSONObject();
                        messages.put("message", "Your Password has been succesfully changed, Please login");
                        messages.put("severity", "info");
                        JSONArray arr = new JSONArray();
                        arr.put(messages);
                        outputJSON.put("messages", arr);
                    } catch (JSONException x) {
                        throw new UIException("Failed to parse json: ", x);
                    } catch (ExistException x) {
                        throw new UIException("Existence exception: ", x);
                    } catch (UnimplementedException x) {
                        throw new UIException("Unimplemented exception: ", x);
                    } catch (UnderlyingStorageException x) {
                        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
                        outputJSON = uiexception.getJSON();
                    }
                } else {
                    outputJSON.put("isError", false);
                    JSONObject messages = new JSONObject();
                    messages.put("message", "Token was not valid");
                    messages.put("severity", "error");
                    JSONArray arr = new JSONArray();
                    arr.put(messages);
                    outputJSON.put("messages", arr);
                }
            } else {
                outputJSON = userdetails;
            }
            request.getSession().setValue(UISession.USERID, "");
            request.getSession().setValue(UISession.PASSWORD, "");
            in.reset();
        } catch (JSONException x) {
            throw new UIException("Failed to parse json: ", x);
        }
    } else {
        try {
            outputJSON.put("isError", false);
            JSONObject messages = new JSONObject();
            messages.put("message", "The admin details in cspace-config.xml failed");
            messages.put("severity", "error");
            JSONArray arr = new JSONArray();
            arr.put(messages);
            outputJSON.put("messages", arr);
        } catch (JSONException x) {
            throw new UIException("Failed to parse json: ", x);
        }
    }
    /* should we automagically log them in or let them do that?, 
		 * I think we should let them login, it has the advantage 
		 * that they find out straight away if they can't remember the new password  */
    request.sendJSONResponse(outputJSON);
    request.setOperationPerformed(Operation.CREATE);
}
Also used : AdminData(org.collectionspace.chain.csp.schema.AdminData) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) UIException(org.collectionspace.csp.api.ui.UIException) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Aggregations

AdminData (org.collectionspace.chain.csp.schema.AdminData)4 UIException (org.collectionspace.csp.api.ui.UIException)3 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 ConfigRoot (org.collectionspace.chain.csp.config.ConfigRoot)1 Spec (org.collectionspace.chain.csp.schema.Spec)1 WebReset (org.collectionspace.chain.csp.webui.misc.WebReset)1 CSPRequestCache (org.collectionspace.csp.api.core.CSPRequestCache)1 CSPRequestCredentials (org.collectionspace.csp.api.core.CSPRequestCredentials)1 ExistException (org.collectionspace.csp.api.persistence.ExistException)1 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)1 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)1 RequestCache (org.collectionspace.csp.helper.core.RequestCache)1