Search in sources :

Example 1 with RolesAudit

use of io.hops.hopsworks.persistence.entity.user.security.audit.RolesAudit in project hopsworks by logicalclocks.

the class UsersController method deleteUser.

/**
 * Delete users. Will fail if the user is an initiator of an audit log.
 * @param u
 * @throws UserException
 */
public void deleteUser(Users u) throws UserException {
    if (u != null) {
        // Should not delete user that is an Initiator in a RolesAudit
        List<RolesAudit> results = rolesAuditFacade.findByTarget(u);
        for (Iterator<RolesAudit> iterator = results.iterator(); iterator.hasNext(); ) {
            RolesAudit next = iterator.next();
            rolesAuditFacade.remove(next);
        }
        // Should not delete user that is an Initiator in an AccountAudit
        List<AccountAudit> resultsAA = accountAuditFacade.findByTarget(u);
        for (Iterator<AccountAudit> iterator = resultsAA.iterator(); iterator.hasNext(); ) {
            AccountAudit next = iterator.next();
            accountAuditFacade.remove(next);
        }
        // run delete handlers
        UserAccountHandler.runUserAccountDeleteHandlers(userAccountHandlers, u);
        try {
            userFacade.removeByEmail(u.getEmail());
        } catch (ConstraintViolationException cve) {
            throw new UserException(RESTCodes.UserErrorCode.ACCOUNT_DELETION_ERROR, Level.FINE, "User that initiated " + "audit log on another account can not be deleted.", cve.getMessage());
        }
    }
}
Also used : RolesAudit(io.hops.hopsworks.persistence.entity.user.security.audit.RolesAudit) ConstraintViolationException(javax.validation.ConstraintViolationException) UserException(io.hops.hopsworks.exceptions.UserException) AccountAudit(io.hops.hopsworks.persistence.entity.user.security.audit.AccountAudit)

Example 2 with RolesAudit

use of io.hops.hopsworks.persistence.entity.user.security.audit.RolesAudit in project hopsworks by logicalclocks.

the class AccountAuditFacade method registerRoleChange.

/**
 * @param user
 * @param action
 * @param outcome
 * @param message
 * @param targetUser
 * @param remoteHost
 * @param userAgent
 */
public void registerRoleChange(Users user, String action, String outcome, String message, Users targetUser, String remoteHost, String userAgent) {
    RolesAudit rolesAudit = new RolesAudit(action, new Date(), message, userAgent, remoteHost, outcome, targetUser, user);
    em.persist(rolesAudit);
}
Also used : RolesAudit(io.hops.hopsworks.persistence.entity.user.security.audit.RolesAudit) Date(java.util.Date)

Aggregations

RolesAudit (io.hops.hopsworks.persistence.entity.user.security.audit.RolesAudit)2 UserException (io.hops.hopsworks.exceptions.UserException)1 AccountAudit (io.hops.hopsworks.persistence.entity.user.security.audit.AccountAudit)1 Date (java.util.Date)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1