Search in sources :

Example 1 with AccountAudit

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

the class BannerService method findUserBanner.

@GET
@Path("user")
@Produces(MediaType.APPLICATION_JSON)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response findUserBanner(@Context SecurityContext sc) {
    Users user = jWTHelper.getUserPrincipal(sc);
    RESTApiJsonResponse json = new RESTApiJsonResponse();
    json.setSuccessMessage("");
    if (user != null && (user.getSalt() == null || user.getSalt().isEmpty())) {
        json.setSuccessMessage("For security purposes, we highly recommend you change your password.");
    } else if (user != null && UserAccountStatus.TEMP_PASSWORD.equals(user.getStatus())) {
        AccountAudit accountAudit = accountAuditFacade.findByTargetLatestPwdReset(user);
        String fullName = "";
        if (accountAudit != null) {
            fullName = " (" + accountAudit.getInitiator().getFname() + " " + accountAudit.getInitiator().getLname() + ")";
        }
        json.setSuccessMessage("The password you used is autogenerated by an administrator" + fullName + ", it is " + "highly recommend that you change it asap.");
    }
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(json).build();
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users) AccountAudit(io.hops.hopsworks.persistence.entity.user.security.audit.AccountAudit) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired)

Example 2 with AccountAudit

use of io.hops.hopsworks.persistence.entity.user.security.audit.AccountAudit 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 3 with AccountAudit

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

the class AccountAuditFacade method registerAccountChange.

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

Aggregations

AccountAudit (io.hops.hopsworks.persistence.entity.user.security.audit.AccountAudit)3 UserException (io.hops.hopsworks.exceptions.UserException)1 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)1 Users (io.hops.hopsworks.persistence.entity.user.Users)1 RolesAudit (io.hops.hopsworks.persistence.entity.user.security.audit.RolesAudit)1 Date (java.util.Date)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1