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