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();
}
}
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));
}
}
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);
}
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);
}
Aggregations