use of edu.harvard.iq.dataverse.actionlogging.ActionLogRecord in project dataverse by IQSS.
the class Mail method sendMail.
@GET
@Path("notifications")
public Response sendMail() {
ActionLogRecord alr = new ActionLogRecord(ActionLogRecord.ActionType.Admin, "sendMail");
// mailService.bulkSendNotifications();
actionLogSvc.log(alr);
return ok("bulk send notification is deprecated");
}
use of edu.harvard.iq.dataverse.actionlogging.ActionLogRecord in project dataverse by IQSS.
the class BuiltinUsers method internalSave.
private Response internalSave(BuiltinUser user, String password, String key) {
String expectedKey = settingsSvc.get(API_KEY_IN_SETTINGS);
if (expectedKey == null) {
return error(Status.SERVICE_UNAVAILABLE, "Dataverse config issue: No API key defined for built in user management");
}
if (!expectedKey.equals(key)) {
return badApiKey(key);
}
ActionLogRecord alr = new ActionLogRecord(ActionLogRecord.ActionType.BuiltinUser, "create");
try {
if (password != null) {
user.updateEncryptedPassword(PasswordEncryption.get().encrypt(password), PasswordEncryption.getLatestVersionNumber());
}
// Make sure the identifier is unique
if ((builtinUserSvc.findByUserName(user.getUserName()) != null) || (authSvc.identifierExists(user.getUserName()))) {
return error(Status.BAD_REQUEST, "username '" + user.getUserName() + "' already exists");
}
user = builtinUserSvc.save(user);
AuthenticatedUser au = authSvc.createAuthenticatedUser(new UserRecordIdentifier(BuiltinAuthenticationProvider.PROVIDER_ID, user.getUserName()), user.getUserName(), user.getDisplayInfo(), false);
/**
* @todo Move this to
* AuthenticationServiceBean.createAuthenticatedUser
*/
boolean rootDataversePresent = false;
try {
Dataverse rootDataverse = dataverseSvc.findRootDataverse();
if (rootDataverse != null) {
rootDataversePresent = true;
}
} catch (Exception e) {
logger.info("The root dataverse is not present. Don't send a notification to dataverseAdmin.");
}
if (rootDataversePresent) {
userNotificationSvc.sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.CREATEACC, null);
}
ApiToken token = new ApiToken();
token.setTokenString(java.util.UUID.randomUUID().toString());
token.setAuthenticatedUser(au);
Calendar c = Calendar.getInstance();
token.setCreateTime(new Timestamp(c.getTimeInMillis()));
c.roll(Calendar.YEAR, 1);
token.setExpireTime(new Timestamp(c.getTimeInMillis()));
authSvc.save(token);
JsonObjectBuilder resp = Json.createObjectBuilder();
resp.add("user", json(user));
resp.add("authenticatedUser", json(au));
resp.add("apiToken", token.getTokenString());
alr.setInfo("builtinUser:" + user.getUserName() + " authenticatedUser:" + au.getIdentifier());
return ok(resp);
} catch (EJBException ejbx) {
alr.setActionResult(ActionLogRecord.Result.InternalError);
alr.setInfo(alr.getInfo() + "// " + ejbx.getMessage());
if (ejbx.getCausedByException() instanceof IllegalArgumentException) {
return error(Status.BAD_REQUEST, "Bad request: can't save user. " + ejbx.getCausedByException().getMessage());
} else {
logger.log(Level.WARNING, "Error saving user: ", ejbx);
return error(Status.INTERNAL_SERVER_ERROR, "Can't save user: " + ejbx.getMessage());
}
} catch (Exception e) {
logger.log(Level.WARNING, "Error saving user", e);
alr.setActionResult(ActionLogRecord.Result.InternalError);
alr.setInfo(alr.getInfo() + "// " + e.getMessage());
return error(Status.INTERNAL_SERVER_ERROR, "Can't save user: " + e.getMessage());
} finally {
actionLogSvc.log(alr);
}
}
use of edu.harvard.iq.dataverse.actionlogging.ActionLogRecord in project dataverse by IQSS.
the class PasswordResetPage method sendPasswordResetLink.
public String sendPasswordResetLink() {
actionLogSvc.log(new ActionLogRecord(ActionLogRecord.ActionType.BuiltinUser, "passwordResetRequest").setInfo("Email Address: " + emailAddress));
try {
PasswordResetInitResponse passwordResetInitResponse = passwordResetService.requestReset(emailAddress);
PasswordResetData passwordResetData = passwordResetInitResponse.getPasswordResetData();
if (passwordResetData != null) {
BuiltinUser foundUser = passwordResetData.getBuiltinUser();
passwordResetUrl = passwordResetInitResponse.getResetUrl();
actionLogSvc.log(new ActionLogRecord(ActionLogRecord.ActionType.BuiltinUser, "passwordResetSent").setInfo("Email Address: " + emailAddress));
} else {
/**
* @todo remove "single" when it's no longer necessary. See
* https://github.com/IQSS/dataverse/issues/844 and
* https://github.com/IQSS/dataverse/issues/1141
*/
logger.log(Level.INFO, "Couldn''t find single account using {0}", emailAddress);
}
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Password Reset Initiated", ""));
} catch (PasswordResetException ex) {
/**
* @todo do we really need a special exception for this??
*/
logger.log(Level.WARNING, "Error While resetting password: " + ex.getMessage(), ex);
}
return "";
}
use of edu.harvard.iq.dataverse.actionlogging.ActionLogRecord in project dataverse by IQSS.
the class LoggingUtil method getActionLogRecord.
public static ActionLogRecord getActionLogRecord(String userId, JobExecution jobExec, String jobInfo, String jobId) {
try {
ActionLogRecord alr = new ActionLogRecord(ActionLogRecord.ActionType.Command, jobExec.getJobName());
alr.setId(jobId);
alr.setInfo(jobInfo);
alr.setUserIdentifier(userId);
alr.setStartTime(jobExec.getStartTime());
alr.setEndTime(jobExec.getEndTime());
if (jobExec.getBatchStatus().name().equalsIgnoreCase("STARTED")) {
alr.setActionResult(ActionLogRecord.Result.OK);
} else {
alr.setActionResult(ActionLogRecord.Result.InternalError);
}
return alr;
} catch (Exception e) {
logger.log(Level.SEVERE, "Error creating action log record: " + e.getMessage());
return null;
}
}
use of edu.harvard.iq.dataverse.actionlogging.ActionLogRecord in project dataverse by IQSS.
the class IpGroupsServiceBean method deleteGroup.
/**
* Deletes the group - if it has no assignments.
* @param grp the group to be deleted
* @throws IllegalArgumentException if the group has assignments
* @see RoleAssigneeServiceBean#getAssignmentsFor(java.lang.String)
*/
public void deleteGroup(IpGroup grp) {
ActionLogRecord alr = new ActionLogRecord(ActionLogRecord.ActionType.GlobalGroups, "ipDelete");
alr.setInfo(grp.getIdentifier());
if (roleAssigneeSvc.getAssignmentsFor(grp.getIdentifier()).isEmpty()) {
em.remove(grp);
actionLogSvc.log(alr);
} else {
String failReason = "Group " + grp.getAlias() + " has assignments and thus can't be deleted.";
alr.setActionResult(ActionLogRecord.Result.BadRequest);
alr.setInfo(alr.getInfo() + "// " + failReason);
actionLogSvc.log(alr);
throw new IllegalArgumentException(failReason);
}
}
Aggregations