Search in sources :

Example 11 with ActionLogRecord

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");
}
Also used : ActionLogRecord(edu.harvard.iq.dataverse.actionlogging.ActionLogRecord) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 12 with ActionLogRecord

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);
    }
}
Also used : UserRecordIdentifier(edu.harvard.iq.dataverse.authorization.UserRecordIdentifier) Calendar(java.util.Calendar) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Dataverse(edu.harvard.iq.dataverse.Dataverse) Timestamp(java.sql.Timestamp) EJBException(javax.ejb.EJBException) Date(java.util.Date) ActionLogRecord(edu.harvard.iq.dataverse.actionlogging.ActionLogRecord) ApiToken(edu.harvard.iq.dataverse.authorization.users.ApiToken) JsonObjectBuilder(javax.json.JsonObjectBuilder) EJBException(javax.ejb.EJBException)

Example 13 with ActionLogRecord

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 "";
}
Also used : ActionLogRecord(edu.harvard.iq.dataverse.actionlogging.ActionLogRecord) BuiltinUser(edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser) FacesMessage(javax.faces.application.FacesMessage)

Example 14 with ActionLogRecord

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;
    }
}
Also used : ActionLogRecord(edu.harvard.iq.dataverse.actionlogging.ActionLogRecord) IOException(java.io.IOException)

Example 15 with ActionLogRecord

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);
    }
}
Also used : ActionLogRecord(edu.harvard.iq.dataverse.actionlogging.ActionLogRecord)

Aggregations

ActionLogRecord (edu.harvard.iq.dataverse.actionlogging.ActionLogRecord)16 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)4 ApiToken (edu.harvard.iq.dataverse.authorization.users.ApiToken)3 Timestamp (java.sql.Timestamp)3 EJBException (javax.ejb.EJBException)3 NoResultException (javax.persistence.NoResultException)3 ConstraintViolationException (javax.validation.ConstraintViolationException)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 IOException (java.io.IOException)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 NonUniqueResultException (javax.persistence.NonUniqueResultException)2 Dataverse (edu.harvard.iq.dataverse.Dataverse)1 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)1 Permission (edu.harvard.iq.dataverse.authorization.Permission)1 UserRecordIdentifier (edu.harvard.iq.dataverse.authorization.UserRecordIdentifier)1 AuthenticationProviderFactoryNotFoundException (edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationProviderFactoryNotFoundException)1 AuthorizationSetupException (edu.harvard.iq.dataverse.authorization.exceptions.AuthorizationSetupException)1 BuiltinAuthenticationProvider (edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinAuthenticationProvider)1