completed update of account, splitted login from account
This commit is contained in:
@ -1,314 +1,376 @@
|
||||
package de.muehlencord.shared.account.business.account.boundary;
|
||||
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountException;
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountStatus;
|
||||
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
|
||||
import de.muehlencord.shared.account.business.mail.entity.MailException;
|
||||
import de.muehlencord.shared.account.business.mail.boundary.MailService;
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||
import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
||||
import de.muehlencord.shared.account.util.SecurityUtil;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
@Stateless
|
||||
public class AccountControl implements Serializable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AccountControl.class.getName());
|
||||
private static final long serialVersionUID = 3424816272598108101L;
|
||||
|
||||
@EJB
|
||||
private ConfigService configService;
|
||||
|
||||
@EJB
|
||||
private MailService mailService;
|
||||
|
||||
@Inject
|
||||
EntityManager em;
|
||||
|
||||
/**
|
||||
* returns a list of active accounts
|
||||
*
|
||||
* @return a list of active accounts
|
||||
*/
|
||||
public List<AccountEntity> getActiveAccounts() {
|
||||
Query query = em.createQuery("SELECT a FROM AccountEntity a WHERE a.status <> :status", AccountEntity.class);
|
||||
query.setParameter("status", AccountStatus.DISABLED.name());
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of active accounts
|
||||
*
|
||||
* @return a list of active accounts
|
||||
*/
|
||||
public List<AccountEntity> getAllAccounts() {
|
||||
Query query = em.createNamedQuery("AccountEntity.findAll");
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<AccountEntity> getAccounts(boolean includeDisabled) {
|
||||
if (includeDisabled) {
|
||||
return getAllAccounts();
|
||||
} else {
|
||||
return getActiveAccounts();
|
||||
}
|
||||
}
|
||||
|
||||
public AccountEntity getAccountEntity(String userName, boolean loadRoles) {
|
||||
StringBuilder queryBuilder = new StringBuilder();
|
||||
queryBuilder.append("SELECT a FROM AccountEntity a ");
|
||||
if (loadRoles) {
|
||||
queryBuilder.append("LEFT JOIN FETCH a.applicationRoleList ");
|
||||
}
|
||||
queryBuilder.append("WHERE a.username = :username");
|
||||
Query query = em.createQuery(queryBuilder.toString());
|
||||
query.setParameter("username", userName);
|
||||
try {
|
||||
return (AccountEntity) query.getSingleResult();
|
||||
} catch (NoResultException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public AccountEntity saveAccount(ApplicationEntity application, AccountEntity account, List<ApplicationRoleEntity> applicationRoles) {
|
||||
Date now = new Date(); // Todo now in UTC
|
||||
Subject currentUser = SecurityUtils.getSubject();
|
||||
String currentLoggedInUser = currentUser.getPrincipal().toString();
|
||||
|
||||
account.setLastUpdatedBy(currentLoggedInUser);
|
||||
account.setLastUpdatedOn(now);
|
||||
|
||||
boolean newAccount = (account.getCreatedOn() == null);
|
||||
|
||||
// new account
|
||||
if (newAccount) {
|
||||
account.setCreatedOn(now);
|
||||
account.setCreatedBy(currentLoggedInUser);
|
||||
|
||||
// set default random password, user has to get password via lost passwort option afterwards
|
||||
String randomPassword = RandomStringUtils.random(20, true, true);
|
||||
String hashedPassword = SecurityUtil.createPassword(randomPassword);
|
||||
account.setAccountPassword(hashedPassword);
|
||||
em.persist(account);
|
||||
} else {
|
||||
em.merge(account);
|
||||
|
||||
// reload account from db and join roles
|
||||
account = getAccountEntity(account.getUsername(), true);
|
||||
}
|
||||
|
||||
// assign roles to account
|
||||
if (account.getApplicationRoleList() == null) {
|
||||
account.setApplicationRoleList(new ArrayList<>());
|
||||
}
|
||||
|
||||
boolean roleSetupChanged = false;
|
||||
// remove roles which are no longer listed
|
||||
// ensure this is only done for the given application - keep the other applications untouched
|
||||
List<ApplicationRoleEntity> assignedRoles = new ArrayList<>();
|
||||
assignedRoles.addAll(account.getApplicationRoleList());
|
||||
for (ApplicationRoleEntity currentlyAssignedRole : assignedRoles) {
|
||||
if ((currentlyAssignedRole.getApplication().equals(application) && (!applicationRoles.contains(currentlyAssignedRole)))) {
|
||||
account.getApplicationRoleList().remove(currentlyAssignedRole);
|
||||
roleSetupChanged = true;
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Removed role {} ({}) from user {}", currentlyAssignedRole.getRoleName(), application.getApplicationName(), account.getUsername());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add newly added roles to role list
|
||||
for (ApplicationRoleEntity applicationRole : applicationRoles) {
|
||||
if (!account.getApplicationRoleList().contains(applicationRole)) {
|
||||
account.addApplicationRole(applicationRole);
|
||||
roleSetupChanged = true;
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Added role {} ({}) to account {}", applicationRole.getRoleName(), application.getApplicationName(), account.getUsername());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update account in database if roles changed
|
||||
if (roleSetupChanged) {
|
||||
em.merge(account);
|
||||
}
|
||||
return account;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAccount(AccountEntity account) throws AccountException {
|
||||
Date now = new Date(); // Todo now in UTC
|
||||
Subject currentUser = SecurityUtils.getSubject();
|
||||
String currentUserName = currentUser.getPrincipal().toString();
|
||||
|
||||
if (account.getUsername().equals(currentUserName)) {
|
||||
throw new AccountException("Cannot delete own account");
|
||||
} else {
|
||||
account.setStatus(AccountStatus.DISABLED.name());
|
||||
account.setLastUpdatedBy(currentUserName);
|
||||
account.setLastUpdatedOn(now);
|
||||
em.merge(account);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean initPasswordReset(String userName) {
|
||||
try {
|
||||
AccountEntity account = getAccountEntity(userName, false);
|
||||
if (account == null) {
|
||||
LOGGER.warn("Account with name " + userName + " not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (account.getStatus().equals(AccountStatus.BLOCKED.name())) {
|
||||
LOGGER.warn("Account " + userName + " is locked, cannot initialize password reset");
|
||||
return false;
|
||||
}
|
||||
|
||||
String randomString = RandomStringUtils.random(40, true, true);
|
||||
|
||||
Date validTo = new Date(); // TODO now in UTC
|
||||
validTo = new Date(validTo.getTime() + 1000 * 600); // 10 minutes to react
|
||||
|
||||
account.setPasswordResetHash(randomString);
|
||||
account.setPasswordResetOngoing(true);
|
||||
account.setPasswordResetValidTo(validTo);
|
||||
|
||||
mailService.sendPasswortResetStartEmail(account, randomString);
|
||||
|
||||
em.merge(account);
|
||||
return true;
|
||||
} catch (MailException ex) {
|
||||
LOGGER.error("Error while sending password reset mail. " + ex.toString());
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Error while sending password reset mail.", ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean resetPassword(String userName, String newPassword, String resetPasswordToken) {
|
||||
AccountEntity account = getAccountEntity(userName, false);
|
||||
|
||||
if (account == null) {
|
||||
LOGGER.warn("Error while resetting password, no account with username " + userName + " found");
|
||||
// TODO add extra logging for intrusion protection system like fail2ban
|
||||
return false;
|
||||
}
|
||||
|
||||
if (account.getPasswordResetOngoing() && (account.getPasswordResetHash() != null) && (account.getPasswordResetValidTo() != null)) {
|
||||
Date now = new Date(); // TODO now in UTC
|
||||
String storedHash = account.getPasswordResetHash().trim();
|
||||
if (account.getPasswordResetValidTo().after(now)) {
|
||||
if (storedHash.equals(resetPasswordToken)) {
|
||||
// everything ok, reset password
|
||||
executePasswordReset(account, newPassword);
|
||||
LOGGER.info("Updated password for user " + userName);
|
||||
return true;
|
||||
} else {
|
||||
// token is not valid, refuse to change password
|
||||
LOGGER.warn("Trying to reset password for user " + userName + " but wrong token " + resetPasswordToken + " provided");
|
||||
addLoginError(account);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// password reset token no longer valid
|
||||
LOGGER.warn("Trying to reset password for user " + userName + " but token is no longer valid");
|
||||
addLoginError(account);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// user is not is password reset mode
|
||||
LOGGER.warn("Trying to reset password for user " + userName + " but password reset was not requested");
|
||||
addLoginError(account);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void executePasswordReset(AccountEntity account, String newPassword) {
|
||||
Date now = new Date(); // TODO now in UTC
|
||||
|
||||
String hashedPassword = SecurityUtil.createPassword(newPassword);
|
||||
account.setAccountPassword(hashedPassword);
|
||||
|
||||
account.setPasswordResetOngoing(false);
|
||||
account.setPasswordResetHash(null);
|
||||
account.setPasswordResetValidTo(null);
|
||||
|
||||
account.setLastUpdatedBy(account.getUsername());
|
||||
account.setLastUpdatedOn(now);
|
||||
em.merge(account);
|
||||
|
||||
}
|
||||
|
||||
public void updateLogin(AccountEntity account) {
|
||||
Date now = new Date(); // TODO now in UTC
|
||||
// a scucessful login ends a password reset procedure
|
||||
if (account.getPasswordResetOngoing()) {
|
||||
account.setPasswordResetOngoing(false);
|
||||
account.setPasswordResetHash(null);
|
||||
account.setPasswordResetValidTo(null);
|
||||
account.setLastUpdatedOn(now);
|
||||
account.setLastUpdatedBy(account.getUsername());
|
||||
}
|
||||
|
||||
account.setLastLogin(now);
|
||||
account.setFailureCount(0);
|
||||
account.setStatus(AccountStatus.NORMAL.name());
|
||||
|
||||
em.merge(account);
|
||||
}
|
||||
|
||||
public void addLoginError(ApplicationEntity application, AccountEntity account) {
|
||||
try {
|
||||
Date now = new Date(); // TODO now in UTC
|
||||
account.setLastFailedLogin(now);
|
||||
account.setFailureCount(account.getFailureCount() + 1);
|
||||
|
||||
int maxFailedLogins = Integer.parseInt(configService.getConfigValue("account.maxFailedLogins"));
|
||||
if ((account.getFailureCount() >= maxFailedLogins) && (!account.getStatus().equals("LOCKED"))) { // TOD add status enum
|
||||
// max failed logins reached, disabling user
|
||||
LOGGER.info("Locking account " + account.getUsername() + " due to " + account.getFailureCount() + " failed logins");
|
||||
account.setStatus(AccountStatus.BLOCKED.name());
|
||||
}
|
||||
|
||||
// on a failed login request, disable password reset
|
||||
account.setPasswordResetOngoing(false);
|
||||
account.setPasswordResetHash(null);
|
||||
account.setPasswordResetValidTo(null);
|
||||
|
||||
account.setLastUpdatedBy("system");
|
||||
account.setLastUpdatedOn(now);
|
||||
em.merge(account);
|
||||
} catch (ConfigException ex) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(ex.toString(), ex);
|
||||
} else {
|
||||
LOGGER.error(ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package de.muehlencord.shared.account.business.account.boundary;
|
||||
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountException;
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountStatus;
|
||||
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
|
||||
import de.muehlencord.shared.account.business.mail.entity.MailException;
|
||||
import de.muehlencord.shared.account.business.mail.boundary.MailService;
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountLoginEntity;
|
||||
import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import de.muehlencord.shared.account.util.SecurityUtil;
|
||||
import de.muehlencord.shared.util.DateUtil;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
@Stateless
|
||||
public class AccountControl implements Serializable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AccountControl.class.getName());
|
||||
private static final long serialVersionUID = 3424816272598108101L;
|
||||
|
||||
@EJB
|
||||
private ConfigService configService;
|
||||
|
||||
@EJB
|
||||
private MailService mailService;
|
||||
|
||||
@Inject
|
||||
private ApplicationEntity application;
|
||||
|
||||
@Inject
|
||||
EntityManager em;
|
||||
|
||||
/**
|
||||
* returns a list of active accounts
|
||||
*
|
||||
* @return a list of active accounts
|
||||
*/
|
||||
public List<AccountEntity> getActiveAccounts() {
|
||||
Query query = em.createQuery("SELECT a FROM AccountEntity a WHERE a.status <> :status", AccountEntity.class);
|
||||
query.setParameter("status", AccountStatus.DISABLED.name());
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of active accounts
|
||||
*
|
||||
* @return a list of active accounts
|
||||
*/
|
||||
public List<AccountEntity> getAllAccounts() {
|
||||
Query query = em.createNamedQuery("AccountEntity.findAll");
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<AccountEntity> getAccounts(boolean includeDisabled) {
|
||||
if (includeDisabled) {
|
||||
return getAllAccounts();
|
||||
} else {
|
||||
return getActiveAccounts();
|
||||
}
|
||||
}
|
||||
|
||||
public AccountEntity getAccountEntity(String userName, boolean loadRoles) {
|
||||
StringBuilder queryBuilder = new StringBuilder();
|
||||
queryBuilder.append("SELECT a FROM AccountEntity a ");
|
||||
if (loadRoles) {
|
||||
queryBuilder.append("LEFT JOIN FETCH a.applicationRoleList ");
|
||||
}
|
||||
queryBuilder.append("WHERE a.username = :username");
|
||||
Query query = em.createQuery(queryBuilder.toString());
|
||||
query.setParameter("username", userName);
|
||||
try {
|
||||
return (AccountEntity) query.getSingleResult();
|
||||
} catch (NoResultException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public AccountEntity saveAccount(AccountEntity account, List<ApplicationRoleEntity> applicationRoles) {
|
||||
Date now = DateUtil.getCurrentTimeInUTC();
|
||||
Subject currentUser = SecurityUtils.getSubject();
|
||||
String currentLoggedInUser = currentUser.getPrincipal().toString();
|
||||
|
||||
account.setLastUpdatedBy(currentLoggedInUser);
|
||||
account.setLastUpdatedOn(now);
|
||||
|
||||
boolean newAccount = (account.getCreatedOn() == null);
|
||||
|
||||
// new account
|
||||
if (newAccount) {
|
||||
account.setCreatedOn(now);
|
||||
account.setCreatedBy(currentLoggedInUser);
|
||||
em.persist(account);
|
||||
} else {
|
||||
em.merge(account);
|
||||
|
||||
// reload account from db and join roles
|
||||
account = getAccountEntity(account.getUsername(), true);
|
||||
}
|
||||
|
||||
// assign roles to account
|
||||
if (account.getApplicationRoleList() == null) {
|
||||
account.setApplicationRoleList(new ArrayList<>());
|
||||
}
|
||||
|
||||
boolean roleSetupChanged = false;
|
||||
// remove roles which are no longer listed
|
||||
// ensure this is only done for the given application - keep the other applications untouched
|
||||
List<ApplicationRoleEntity> assignedRoles = new ArrayList<>();
|
||||
assignedRoles.addAll(account.getApplicationRoleList());
|
||||
for (ApplicationRoleEntity currentlyAssignedRole : assignedRoles) {
|
||||
if ((currentlyAssignedRole.getApplication().equals(application) && (!applicationRoles.contains(currentlyAssignedRole)))) {
|
||||
account.getApplicationRoleList().remove(currentlyAssignedRole);
|
||||
roleSetupChanged = true;
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Removed role {} ({}) from user {}", currentlyAssignedRole.getRoleName(), application.getApplicationName(), account.getUsername());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add newly added roles to role list
|
||||
for (ApplicationRoleEntity applicationRole : applicationRoles) {
|
||||
if (!account.getApplicationRoleList().contains(applicationRole)) {
|
||||
account.addApplicationRole(applicationRole);
|
||||
roleSetupChanged = true;
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Added role {} ({}) to account {}", applicationRole.getRoleName(), application.getApplicationName(), account.getUsername());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update account in database if roles changed
|
||||
if (roleSetupChanged) {
|
||||
em.merge(account);
|
||||
}
|
||||
return account;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAccount(AccountEntity account) throws AccountException {
|
||||
Date now = new Date(); // Todo now in UTC
|
||||
Subject currentUser = SecurityUtils.getSubject();
|
||||
String currentUserName = currentUser.getPrincipal().toString();
|
||||
|
||||
if (account.getUsername().equals(currentUserName)) {
|
||||
throw new AccountException("Cannot delete own account");
|
||||
} else {
|
||||
account.setStatus(AccountStatus.DISABLED.name());
|
||||
account.setLastUpdatedBy(currentUserName);
|
||||
account.setLastUpdatedOn(now);
|
||||
em.merge(account);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean initPasswordReset(String userName) {
|
||||
try {
|
||||
AccountEntity account = getAccountEntity(userName, false);
|
||||
if (account == null) {
|
||||
LOGGER.warn("Account with name " + userName + " not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (account.getStatus().equals(AccountStatus.BLOCKED.name())) {
|
||||
LOGGER.warn("Account " + userName + " is locked, cannot initialize password reset");
|
||||
return false;
|
||||
}
|
||||
|
||||
String randomString = RandomStringUtils.random(40, true, true);
|
||||
|
||||
Date validTo = new Date(); // TODO now in UTC
|
||||
validTo = new Date(validTo.getTime() + 1000 * 600); // 10 minutes to react
|
||||
|
||||
// TODO rework password reset
|
||||
// account.setPasswordResetHash(randomString);
|
||||
// account.setPasswordResetOngoing(true);
|
||||
// account.setPasswordResetValidTo(validTo);
|
||||
mailService.sendPasswortResetStartEmail(account, randomString);
|
||||
|
||||
em.merge(account);
|
||||
return true;
|
||||
} catch (MailException ex) {
|
||||
LOGGER.error("Error while sending password reset mail. " + ex.toString());
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Error while sending password reset mail.", ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean resetPassword(String userName, String newPassword, String resetPasswordToken) {
|
||||
AccountEntity account = getAccountEntity(userName, false);
|
||||
|
||||
if (account == null) {
|
||||
LOGGER.warn("Error while resetting password, no account with username " + userName + " found");
|
||||
// TODO add extra logging for intrusion protection system like fail2ban
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
if (account.getPasswordResetOngoing() && (account.getPasswordResetHash() != null) && (account.getPasswordResetValidTo() != null)) {
|
||||
Date now = new Date(); // TODO now in UTC
|
||||
String storedHash = account.getPasswordResetHash().trim();
|
||||
if (account.getPasswordResetValidTo().after(now)) {
|
||||
if (storedHash.equals(resetPasswordToken)) {
|
||||
// everything ok, reset password
|
||||
executePasswordReset(account, newPassword);
|
||||
LOGGER.info("Updated password for user " + userName);
|
||||
return true;
|
||||
} else {
|
||||
// token is not valid, refuse to change password
|
||||
LOGGER.warn("Trying to reset password for user " + userName + " but wrong token " + resetPasswordToken + " provided");
|
||||
addLoginError(account);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// password reset token no longer valid
|
||||
LOGGER.warn("Trying to reset password for user " + userName + " but token is no longer valid");
|
||||
addLoginError(account);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// user is not is password reset mode
|
||||
LOGGER.warn("Trying to reset password for user " + userName + " but password reset was not requested");
|
||||
addLoginError(account);
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
return false; // FIMXE re-implement password reset
|
||||
}
|
||||
|
||||
private void executePasswordReset(AccountEntity account, String newPassword) {
|
||||
Date now = new Date(); // TODO now in UTC
|
||||
|
||||
String hashedPassword = SecurityUtil.createPassword(newPassword);
|
||||
// account.setAccountPassword(hashedPassword);
|
||||
//
|
||||
// account.setPasswordResetOngoing(false);
|
||||
// account.setPasswordResetHash(null);
|
||||
// account.setPasswordResetValidTo(null);
|
||||
|
||||
account.setLastUpdatedBy(account.getUsername());
|
||||
account.setLastUpdatedOn(now);
|
||||
em.merge(account);
|
||||
|
||||
}
|
||||
|
||||
public AccountLoginEntity updateSuccessFullLogin(AccountLoginEntity login, String byUser) {
|
||||
Date now = DateUtil.getCurrentTimeInUTC();
|
||||
// a scucessful login ends a password reset procedure
|
||||
if (login.getPasswordResetOngoing()) {
|
||||
login.setPasswordResetOngoing(false);
|
||||
login.setPasswordResetHash(null);
|
||||
login.setPasswordResetValidTo(null);
|
||||
login.setLastUpdatedOn(now);
|
||||
login.setLastUpdatedBy(byUser);
|
||||
}
|
||||
|
||||
login.setLastLogin(now);
|
||||
login.setFailureCount(0);
|
||||
return updateLogin(login);
|
||||
}
|
||||
|
||||
|
||||
public AccountLoginEntity updateLogin(AccountLoginEntity login) {
|
||||
return em.merge (login);
|
||||
}
|
||||
|
||||
public void updateLogin (AccountEntity account) {
|
||||
if (account.getAccountLogin() == null) {
|
||||
// TODO connect to IPRS - how can an account ask for an updated login if the user cannot login
|
||||
} else {
|
||||
updateSuccessFullLogin (account.getAccountLogin(), account.getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void addLoginError(AccountEntity account) {
|
||||
// TODO reimplement
|
||||
// try {
|
||||
// Date now = new Date(); // TODO now in UTC
|
||||
// account.setLastFailedLogin(now);
|
||||
// account.setFailureCount(account.getFailureCount() + 1);
|
||||
//
|
||||
// int maxFailedLogins = Integer.parseInt(configService.getConfigValue( "account.maxFailedLogins"));
|
||||
// if ((account.getFailureCount() >= maxFailedLogins) && (!account.getStatus().equals("LOCKED"))) { // TOD add status enum
|
||||
// // max failed logins reached, disabling user
|
||||
// LOGGER.info("Locking account " + account.getUsername() + " due to " + account.getFailureCount() + " failed logins");
|
||||
// account.setStatus(AccountStatus.BLOCKED.name());
|
||||
// }
|
||||
//
|
||||
// // on a failed login request, disable password reset
|
||||
// account.setPasswordResetOngoing(false);
|
||||
// account.setPasswordResetHash(null);
|
||||
// account.setPasswordResetValidTo(null);
|
||||
//
|
||||
// account.setLastUpdatedBy("system");
|
||||
// account.setLastUpdatedOn(now);
|
||||
// em.merge(account);
|
||||
// } catch (ConfigException ex) {
|
||||
// if (LOGGER.isDebugEnabled()) {
|
||||
// LOGGER.debug(ex.toString(), ex);
|
||||
// } else {
|
||||
// LOGGER.error(ex.toString());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public AccountLoginEntity createLoginWithRandomPassword() {
|
||||
AccountLoginEntity login = new AccountLoginEntity();
|
||||
String randomPassword = RandomStringUtils.random(20, true, true);
|
||||
String hashedPassword = SecurityUtil.createPassword(randomPassword);
|
||||
login.setAccountPassword(hashedPassword);
|
||||
login.setLastLogin(null);
|
||||
login.setLastFailedLogin(null);
|
||||
login.setFailureCount(0);
|
||||
|
||||
return login;
|
||||
}
|
||||
|
||||
public String getHashedPassword (String password) {
|
||||
String hashedPassword = SecurityUtil.createPassword(password);
|
||||
return hashedPassword;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addLogin(AccountEntity accountToAdd, AccountLoginEntity accountLogin) {
|
||||
Date now = DateUtil.getCurrentTimeInUTC();
|
||||
Subject currentUser = SecurityUtils.getSubject();
|
||||
String currentLoggedInUser = currentUser.getPrincipal().toString();
|
||||
|
||||
AccountEntity account = em.merge(accountToAdd);
|
||||
accountLogin.setAccount(account);
|
||||
accountLogin.setCreatedBy(currentLoggedInUser);
|
||||
accountLogin.setCreatedOn(now);
|
||||
accountLogin.setLastUpdatedBy(currentLoggedInUser);
|
||||
accountLogin.setLastUpdatedOn(now);
|
||||
em.persist(accountLogin);
|
||||
|
||||
account.setAccountLogin(accountLogin);
|
||||
em.merge(account);
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteLogin(AccountEntity accountToDelete) {
|
||||
AccountEntity account = em.merge(accountToDelete);
|
||||
AccountLoginEntity login = account.getAccountLogin();
|
||||
login.setAccount(null);
|
||||
account.setAccountLogin(null);
|
||||
em.remove(login);
|
||||
em.merge(account);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,105 +1,99 @@
|
||||
package de.muehlencord.shared.account.business.account.boundary;
|
||||
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountException;
|
||||
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
|
||||
import de.muehlencord.shared.account.business.application.boundary.ApplicationService;
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import java.io.Serializable;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import javax.ejb.EJB;
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@Stateless
|
||||
public class ApplicationPermissionControl implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3761100587901739481L;
|
||||
|
||||
@EJB
|
||||
ApplicationService applicationService;
|
||||
|
||||
@PersistenceContext
|
||||
EntityManager em;
|
||||
|
||||
public List<ApplicationPermissionEntity> getApplicationPermissions(ApplicationEntity application) {
|
||||
Query query = em.createNamedQuery("ApplicationPermissionEntity.findAll");
|
||||
query.setParameter("application", application);
|
||||
List<ApplicationPermissionEntity> permissionList = query.getResultList();
|
||||
if (permissionList == null) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
return permissionList;
|
||||
}
|
||||
}
|
||||
|
||||
public ApplicationPermissionEntity findPermissionByName(ApplicationEntity application, String permissionName) {
|
||||
Query query = em.createNamedQuery("ApplicationPermissionEntity.findByPermissionName");
|
||||
query.setParameter("application", application);
|
||||
query.setParameter("permissionName", permissionName);
|
||||
List<ApplicationPermissionEntity> resultList = query.getResultList();
|
||||
if ((resultList == null) || (resultList.isEmpty())) {
|
||||
return null;
|
||||
} else {
|
||||
return resultList.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void create(String applicationName, String name, String description) {
|
||||
ApplicationEntity application = applicationService.findByApplicationName(applicationName);
|
||||
// TODO add error handling if not found
|
||||
ApplicationPermissionEntity permission = new ApplicationPermissionEntity(application, name, description);
|
||||
em.persist(permission);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void update(ApplicationPermissionEntity permission) throws AccountException {
|
||||
ApplicationPermissionEntity existing = attach(permission);
|
||||
em.merge(existing);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void createOrUpdate(String name, String description) {
|
||||
ApplicationPermissionEntity permission = findByName(name);
|
||||
if (permission == null) {
|
||||
permission = new ApplicationPermissionEntity(name, description);
|
||||
em.persist(permission);
|
||||
} else {
|
||||
permission.setPermissionDescription(description);
|
||||
em.merge(permission);
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(ApplicationPermissionEntity permission) throws AccountException {
|
||||
ApplicationPermissionEntity existingPermission = attach(permission);
|
||||
em.remove(existingPermission);
|
||||
}
|
||||
|
||||
public ApplicationPermissionEntity attach(ApplicationPermissionEntity permission) throws AccountException {
|
||||
try {
|
||||
return em.merge(permission);
|
||||
} catch (OptimisticLockException ex) {
|
||||
throw new AccountException("Entity updated / deleted, please reload", true);
|
||||
}
|
||||
}
|
||||
|
||||
private ApplicationPermissionEntity findByName(String name) {
|
||||
Query query = em.createNamedQuery("ApplicationPermissionEntity.findByPermissionName");
|
||||
query.setParameter("permissionName", name);
|
||||
List<ApplicationPermissionEntity> permissions = query.getResultList();
|
||||
if ((permissions == null) || (permissions.isEmpty())) {
|
||||
return null;
|
||||
} else {
|
||||
return permissions.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.muehlencord.shared.account.business.account.boundary;
|
||||
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountException;
|
||||
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import java.io.Serializable;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@Stateless
|
||||
public class ApplicationPermissionControl implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3761100587901739481L;
|
||||
|
||||
@PersistenceContext
|
||||
EntityManager em;
|
||||
|
||||
public List<ApplicationPermissionEntity> getApplicationPermissions(ApplicationEntity app) {
|
||||
Query query = em.createNamedQuery("ApplicationPermissionEntity.findAll");
|
||||
query.setParameter("application", app);
|
||||
List<ApplicationPermissionEntity> permissionList = query.getResultList();
|
||||
if (permissionList == null) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
return permissionList;
|
||||
}
|
||||
}
|
||||
|
||||
public ApplicationPermissionEntity findPermissionByName(ApplicationEntity application, String permissionName) {
|
||||
Query query = em.createNamedQuery("ApplicationPermissionEntity.findByPermissionName");
|
||||
query.setParameter("application", application);
|
||||
query.setParameter("permissionName", permissionName);
|
||||
List<ApplicationPermissionEntity> resultList = query.getResultList();
|
||||
if ((resultList == null) || (resultList.isEmpty())) {
|
||||
return null;
|
||||
} else {
|
||||
return resultList.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void create(ApplicationEntity application,String name, String description) {
|
||||
ApplicationPermissionEntity permission = new ApplicationPermissionEntity(application, name, description);
|
||||
em.persist(permission);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void update(ApplicationPermissionEntity permission) throws AccountException {
|
||||
ApplicationPermissionEntity existing = attach(permission);
|
||||
em.merge(existing);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void createOrUpdate(ApplicationEntity application, String name, String description) {
|
||||
ApplicationPermissionEntity permission = findByName(application, name);
|
||||
if (permission == null) {
|
||||
permission = new ApplicationPermissionEntity(name, description);
|
||||
em.persist(permission);
|
||||
} else {
|
||||
permission.setPermissionDescription(description);
|
||||
em.merge(permission);
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(ApplicationPermissionEntity permission) throws AccountException {
|
||||
ApplicationPermissionEntity existingPermission = attach(permission);
|
||||
em.remove(existingPermission);
|
||||
}
|
||||
|
||||
public ApplicationPermissionEntity attach(ApplicationPermissionEntity permission) throws AccountException {
|
||||
try {
|
||||
return em.merge(permission);
|
||||
} catch (OptimisticLockException ex) {
|
||||
throw new AccountException("Entity updated / deleted, please reload", true);
|
||||
}
|
||||
}
|
||||
|
||||
private ApplicationPermissionEntity findByName(ApplicationEntity application, String name) {
|
||||
Query query = em.createNamedQuery("ApplicationPermissionEntity.findByPermissionName");
|
||||
query.setParameter("application", application);
|
||||
query.setParameter("permissionName", name);
|
||||
List<ApplicationPermissionEntity> permissions = query.getResultList();
|
||||
if ((permissions == null) || (permissions.isEmpty())) {
|
||||
return null;
|
||||
} else {
|
||||
return permissions.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,149 +1,147 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.account.business.account.boundary;
|
||||
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountException;
|
||||
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
|
||||
import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@Stateless
|
||||
public class ApplicationRoleControl implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5962478269550134748L;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationRoleControl.class);
|
||||
|
||||
@EJB
|
||||
ApplicationPermissionControl applicationPermissionControl;
|
||||
|
||||
@PersistenceContext
|
||||
EntityManager em;
|
||||
|
||||
public List<ApplicationRoleEntity> getAllRoles(ApplicationEntity application) {
|
||||
Query query = em.createNamedQuery("ApplicationRoleEntity.findAll");
|
||||
query.setParameter ("application", application);
|
||||
|
||||
List<ApplicationRoleEntity> roles = query.getResultList();
|
||||
if (roles == null) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
return roles;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void createOrUpdate(ApplicationEntity application, String name, String description) {
|
||||
ApplicationRoleEntity role = findByName(application, name);
|
||||
if (role == null) {
|
||||
role = new ApplicationRoleEntity(application, name, description);
|
||||
em.persist(role);
|
||||
} else {
|
||||
role.setRoleDescription(description);
|
||||
em.merge(role);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void create(ApplicationRoleEntity role) {
|
||||
em.persist(role);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void update (ApplicationRoleEntity role) {
|
||||
em.merge(role);
|
||||
}
|
||||
|
||||
public void delete(ApplicationRoleEntity role) throws AccountException {
|
||||
ApplicationRoleEntity existingRole = attach(role);
|
||||
em.remove(existingRole);
|
||||
}
|
||||
|
||||
public ApplicationRoleEntity attach(ApplicationRoleEntity role) throws AccountException {
|
||||
try {
|
||||
return em.merge(role);
|
||||
} catch (OptimisticLockException ex) {
|
||||
throw new AccountException("Entity updated / deleted, please reload", true);
|
||||
}
|
||||
}
|
||||
|
||||
public ApplicationRoleEntity findByName(ApplicationEntity application, String name) {
|
||||
Query query = em.createNamedQuery("ApplicationRoleEntity.findByRoleName");
|
||||
query.setParameter("application", application);
|
||||
query.setParameter("roleName", name);
|
||||
List<ApplicationRoleEntity> permissions = query.getResultList();
|
||||
if ((permissions == null) || (permissions.isEmpty())) {
|
||||
return null;
|
||||
} else {
|
||||
return permissions.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ApplicationPermissionEntity> getRolePermissions(ApplicationRoleEntity role) throws AccountException {
|
||||
ApplicationRoleEntity existingRole = em.find(ApplicationRoleEntity.class, role.getId());
|
||||
List<ApplicationPermissionEntity> permissions = existingRole.getApplicationPermissionList();
|
||||
permissions.size(); // force list to load
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public List<ApplicationPermissionEntity> getNotAssignedApplicationPermissions(ApplicationRoleEntity role) {
|
||||
try {
|
||||
List<ApplicationPermissionEntity> rolePermissions = getRolePermissions(role);
|
||||
List<ApplicationPermissionEntity> allPermssions = applicationPermissionControl.getApplicationPermissions(role.getApplication());
|
||||
|
||||
List<ApplicationPermissionEntity> missingPermissions = new ArrayList<>();
|
||||
allPermssions.stream().filter((perm) -> (!rolePermissions.contains(perm))).forEachOrdered((perm) -> {
|
||||
missingPermissions.add(perm);
|
||||
});
|
||||
return missingPermissions;
|
||||
} catch (AccountException ex) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(ex.toString(), ex);
|
||||
} else {
|
||||
LOGGER.debug(ex.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addPermission(ApplicationRoleEntity role, ApplicationPermissionEntity permission) throws AccountException {
|
||||
ApplicationRoleEntity existingRole = attach(role);
|
||||
if (existingRole.getApplicationPermissionList() == null) {
|
||||
existingRole.setApplicationPermissionList(new ArrayList<>());
|
||||
}
|
||||
existingRole.getApplicationPermissionList().add(permission);
|
||||
em.merge(role);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void removePermission(ApplicationRoleEntity role, ApplicationPermissionEntity permission) throws AccountException {
|
||||
ApplicationRoleEntity existingRole = attach(role);
|
||||
if ((existingRole.getApplicationPermissionList() != null) && (existingRole.getApplicationPermissionList().contains(permission))) {
|
||||
existingRole.getApplicationPermissionList().remove(permission);
|
||||
}
|
||||
em.merge(role);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.account.business.account.boundary;
|
||||
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountException;
|
||||
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
|
||||
import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@Stateless
|
||||
public class ApplicationRoleControl implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5962478269550134748L;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationRoleControl.class);
|
||||
|
||||
@EJB
|
||||
ApplicationPermissionControl applicationPermissionControl;
|
||||
|
||||
@PersistenceContext
|
||||
EntityManager em;
|
||||
|
||||
public List<ApplicationRoleEntity> getAllRoles(ApplicationEntity app) {
|
||||
Query query = em.createNamedQuery("ApplicationRoleEntity.findAll");
|
||||
query.setParameter("application", app);
|
||||
|
||||
List<ApplicationRoleEntity> roles = query.getResultList();
|
||||
if (roles == null) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
return roles;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void createOrUpdate(ApplicationEntity application, String name, String description) {
|
||||
ApplicationRoleEntity role = findByName(application, name);
|
||||
if (role == null) {
|
||||
role = new ApplicationRoleEntity(application, name, description);
|
||||
em.persist(role);
|
||||
} else {
|
||||
role.setRoleDescription(description);
|
||||
em.merge(role);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void create(ApplicationRoleEntity role) {
|
||||
em.persist(role);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void update(ApplicationRoleEntity role) {
|
||||
em.merge(role);
|
||||
}
|
||||
|
||||
public void delete(ApplicationRoleEntity role) throws AccountException {
|
||||
ApplicationRoleEntity existingRole = attach(role);
|
||||
em.remove(existingRole);
|
||||
}
|
||||
|
||||
public ApplicationRoleEntity attach(ApplicationRoleEntity role) throws AccountException {
|
||||
try {
|
||||
return em.merge(role);
|
||||
} catch (OptimisticLockException ex) {
|
||||
throw new AccountException("Entity updated / deleted, please reload", true);
|
||||
}
|
||||
}
|
||||
|
||||
public ApplicationRoleEntity findByName(ApplicationEntity application, String name) {
|
||||
Query query = em.createNamedQuery("ApplicationRoleEntity.findByRoleName");
|
||||
query.setParameter("application", application);
|
||||
query.setParameter("roleName", name);
|
||||
List<ApplicationRoleEntity> permissions = query.getResultList();
|
||||
if ((permissions == null) || (permissions.isEmpty())) {
|
||||
return null;
|
||||
} else {
|
||||
return permissions.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ApplicationPermissionEntity> getRolePermissions(ApplicationRoleEntity role) throws AccountException {
|
||||
ApplicationRoleEntity existingRole = em.find(ApplicationRoleEntity.class, role.getId());
|
||||
List<ApplicationPermissionEntity> permissions = existingRole.getApplicationPermissionList();
|
||||
permissions.size(); // force list to load
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public List<ApplicationPermissionEntity> getNotAssignedApplicationPermissions(ApplicationRoleEntity role) {
|
||||
try {
|
||||
List<ApplicationPermissionEntity> rolePermissions = getRolePermissions(role);
|
||||
List<ApplicationPermissionEntity> allPermssions = applicationPermissionControl.getApplicationPermissions(role.getApplication());
|
||||
|
||||
List<ApplicationPermissionEntity> missingPermissions = new ArrayList<>();
|
||||
allPermssions.stream().filter((perm) -> (!rolePermissions.contains(perm))).forEachOrdered((perm) -> {
|
||||
missingPermissions.add(perm);
|
||||
});
|
||||
return missingPermissions;
|
||||
} catch (AccountException ex) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(ex.toString(), ex);
|
||||
} else {
|
||||
LOGGER.debug(ex.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addPermission(ApplicationRoleEntity role, ApplicationPermissionEntity permission) throws AccountException {
|
||||
ApplicationRoleEntity existingRole = attach(role);
|
||||
if (existingRole.getApplicationPermissionList() == null) {
|
||||
existingRole.setApplicationPermissionList(new ArrayList<>());
|
||||
}
|
||||
existingRole.getApplicationPermissionList().add(permission);
|
||||
em.merge(role);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void removePermission(ApplicationRoleEntity role, ApplicationPermissionEntity permission) throws AccountException {
|
||||
ApplicationRoleEntity existingRole = attach(role);
|
||||
if ((existingRole.getApplicationPermissionList() != null) && (existingRole.getApplicationPermissionList().contains(permission))) {
|
||||
existingRole.getApplicationPermissionList().remove(permission);
|
||||
}
|
||||
em.merge(role);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,345 +1,263 @@
|
||||
package de.muehlencord.shared.account.business.account.entity;
|
||||
|
||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "account")
|
||||
@XmlRootElement
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "AccountEntity.findAll", query = "SELECT a FROM AccountEntity a ORDER by a.username"),
|
||||
@NamedQuery(name = "AccountEntity.findByUsername", query = "SELECT a FROM AccountEntity a WHERE a.username = :username"),
|
||||
@NamedQuery(name = "AccountEntity.findByFirstname", query = "SELECT a FROM AccountEntity a WHERE a.firstname = :firstname ORDER BY a.username"),
|
||||
@NamedQuery(name = "AccountEntity.findByLastname", query = "SELECT a FROM AccountEntity a WHERE a.lastname = :lastname ORDER BY a.username"),
|
||||
@NamedQuery(name = "AccountEntity.findByAccountPassword", query = "SELECT a FROM AccountEntity a WHERE a.accountPassword = :accountPassword"),
|
||||
@NamedQuery(name = "AccountEntity.findByLastLogin", query = "SELECT a FROM AccountEntity a WHERE a.lastLogin = :lastLogin"),
|
||||
@NamedQuery(name = "AccountEntity.findByLastFailedLogin", query = "SELECT a FROM AccountEntity a WHERE a.lastFailedLogin = :lastFailedLogin"),
|
||||
@NamedQuery(name = "AccountEntity.findByFailureCount", query = "SELECT a FROM AccountEntity a WHERE a.failureCount = :failureCount"),
|
||||
@NamedQuery(name = "AccountEntity.findByStatus", query = "SELECT a FROM AccountEntity a WHERE a.status = :status"),
|
||||
@NamedQuery(name = "AccountEntity.findByPasswordResetOngoing", query = "SELECT a FROM AccountEntity a WHERE a.passwordResetOngoing = :passwordResetOngoing"),
|
||||
@NamedQuery(name = "AccountEntity.findByPasswordResetValidTo", query = "SELECT a FROM AccountEntity a WHERE a.passwordResetValidTo = :passwordResetValidTo"),
|
||||
@NamedQuery(name = "AccountEntity.findByPasswordResetHash", query = "SELECT a FROM AccountEntity a WHERE a.passwordResetHash = :passwordResetHash"),
|
||||
@NamedQuery(name = "AccountEntity.findByCreatedOn", query = "SELECT a FROM AccountEntity a WHERE a.createdOn = :createdOn"),
|
||||
@NamedQuery(name = "AccountEntity.findByCreatedBy", query = "SELECT a FROM AccountEntity a WHERE a.createdBy = :createdBy"),
|
||||
@NamedQuery(name = "AccountEntity.findByLastUpdatedOn", query = "SELECT a FROM AccountEntity a WHERE a.lastUpdatedOn = :lastUpdatedOn"),
|
||||
@NamedQuery(name = "AccountEntity.findByLastUpdatedBy", query = "SELECT a FROM AccountEntity a WHERE a.lastUpdatedBy = :lastUpdatedBy")})
|
||||
public class AccountEntity implements Serializable, Account {
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "account")
|
||||
private List<ConfigEntity> configEntityList;
|
||||
|
||||
private static final long serialVersionUID = 6216991757526150935L;
|
||||
|
||||
@Id
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(generator = "uuid2")
|
||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
@Type(type = "pg-uuid")
|
||||
private UUID id;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 100)
|
||||
@Column(name = "firstname")
|
||||
private String firstname;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 100)
|
||||
@Column(name = "lastname")
|
||||
private String lastname;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 200)
|
||||
@Column(name = "account_password", columnDefinition = "bpchar(200)")
|
||||
private String accountPassword;
|
||||
@Column(name = "last_login")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastLogin;
|
||||
@Column(name = "last_failed_login")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastFailedLogin;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "failure_count")
|
||||
private int failureCount;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 10)
|
||||
@Column(name = "status")
|
||||
private String status;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "password_reset_ongoing")
|
||||
private boolean passwordResetOngoing;
|
||||
@Column(name = "password_reset_valid_to")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date passwordResetValidTo;
|
||||
@Size(max = 200)
|
||||
@Column(name = "password_reset_hash", columnDefinition = "bpchar(200)")
|
||||
private String passwordResetHash;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "created_on")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createdOn;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 32)
|
||||
@Column(name = "created_by")
|
||||
private String createdBy;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "last_updated_on")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastUpdatedOn;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 32)
|
||||
@Column(name = "last_updated_by")
|
||||
private String lastUpdatedBy;
|
||||
@JoinTable(name = "account_role", joinColumns = {
|
||||
@JoinColumn(name = "account", referencedColumnName = "id")}, inverseJoinColumns = {
|
||||
@JoinColumn(name = "account_role", referencedColumnName = "id")})
|
||||
@ManyToMany(fetch = FetchType.LAZY)
|
||||
private List<ApplicationRoleEntity> applicationRoleList;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "accountId", fetch = FetchType.LAZY)
|
||||
private List<AccountHistoryEntity> accountHistoryList;
|
||||
@OneToOne(cascade = CascadeType.ALL, mappedBy = "account")
|
||||
private AccountLoginEntity accountLogin;
|
||||
|
||||
public AccountEntity() {
|
||||
// empty constructor required for JPA
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
if (accountLogin == null) {
|
||||
return null;
|
||||
} else {
|
||||
return accountLogin.getUsername();
|
||||
}
|
||||
}
|
||||
|
||||
public void addApplicationRole(ApplicationRoleEntity applicationRole) {
|
||||
if (applicationRoleList == null) {
|
||||
applicationRoleList = new ArrayList<>();
|
||||
}
|
||||
applicationRoleList.add(applicationRole);
|
||||
}
|
||||
|
||||
/* **** getter / setter **** */
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public String getAccountPassword() {
|
||||
return accountPassword;
|
||||
}
|
||||
|
||||
public void setAccountPassword(String accountPassword) {
|
||||
this.accountPassword = accountPassword;
|
||||
}
|
||||
|
||||
public Date getLastLogin() {
|
||||
return lastLogin;
|
||||
}
|
||||
|
||||
public void setLastLogin(Date lastLogin) {
|
||||
this.lastLogin = lastLogin;
|
||||
}
|
||||
|
||||
public Date getLastFailedLogin() {
|
||||
return lastFailedLogin;
|
||||
}
|
||||
|
||||
public void setLastFailedLogin(Date lastFailedLogin) {
|
||||
this.lastFailedLogin = lastFailedLogin;
|
||||
}
|
||||
|
||||
public int getFailureCount() {
|
||||
return failureCount;
|
||||
}
|
||||
|
||||
public void setFailureCount(int failureCount) {
|
||||
this.failureCount = failureCount;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public boolean getPasswordResetOngoing() {
|
||||
return passwordResetOngoing;
|
||||
}
|
||||
|
||||
public void setPasswordResetOngoing(boolean passwordResetOngoing) {
|
||||
this.passwordResetOngoing = passwordResetOngoing;
|
||||
}
|
||||
|
||||
public Date getPasswordResetValidTo() {
|
||||
return passwordResetValidTo;
|
||||
}
|
||||
|
||||
public void setPasswordResetValidTo(Date passwordResetValidTo) {
|
||||
this.passwordResetValidTo = passwordResetValidTo;
|
||||
}
|
||||
|
||||
public String getPasswordResetHash() {
|
||||
return passwordResetHash;
|
||||
}
|
||||
|
||||
public void setPasswordResetHash(String passwordResetHash) {
|
||||
this.passwordResetHash = passwordResetHash;
|
||||
}
|
||||
|
||||
public Date getCreatedOn() {
|
||||
return createdOn;
|
||||
}
|
||||
|
||||
public void setCreatedOn(Date createdOn) {
|
||||
this.createdOn = createdOn;
|
||||
}
|
||||
|
||||
public String getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
|
||||
public void setCreatedBy(String createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
public Date getLastUpdatedOn() {
|
||||
return lastUpdatedOn;
|
||||
}
|
||||
|
||||
public void setLastUpdatedOn(Date lastUpdatedOn) {
|
||||
this.lastUpdatedOn = lastUpdatedOn;
|
||||
}
|
||||
|
||||
public String getLastUpdatedBy() {
|
||||
return lastUpdatedBy;
|
||||
}
|
||||
|
||||
public void setLastUpdatedBy(String lastUpdatedBy) {
|
||||
this.lastUpdatedBy = lastUpdatedBy;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public List<ApplicationRoleEntity> getApplicationRoleList() {
|
||||
return applicationRoleList;
|
||||
}
|
||||
|
||||
public void setApplicationRoleList(List<ApplicationRoleEntity> applicationRoleList) {
|
||||
this.applicationRoleList = applicationRoleList;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public List<AccountHistoryEntity> getAccountHistoryList() {
|
||||
return accountHistoryList;
|
||||
}
|
||||
|
||||
public void setAccountHistoryList(List<AccountHistoryEntity> accountHistoryList) {
|
||||
this.accountHistoryList = accountHistoryList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (id != null ? id.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||
if (!(object instanceof AccountEntity)) {
|
||||
return false;
|
||||
}
|
||||
AccountEntity other = (AccountEntity) object;
|
||||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "de.muehlencord.shared.account.entity.Account[ id=" + id + " ]";
|
||||
}
|
||||
|
||||
public AccountLoginEntity getAccountLogin() {
|
||||
return accountLogin;
|
||||
}
|
||||
|
||||
public void setAccountLogin(AccountLoginEntity accountLogin) {
|
||||
this.accountLogin = accountLogin;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public List<ConfigEntity> getConfigEntityList() {
|
||||
return configEntityList;
|
||||
}
|
||||
|
||||
public void setConfigEntityList(List<ConfigEntity> configEntityList) {
|
||||
this.configEntityList = configEntityList;
|
||||
}
|
||||
|
||||
}
|
||||
package de.muehlencord.shared.account.business.account.entity;
|
||||
|
||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "account")
|
||||
@XmlRootElement
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "AccountEntity.findAll", query = "SELECT a FROM AccountEntity a ORDER by a.lastname, a.firstname"),
|
||||
@NamedQuery(name = "AccountEntity.findByStatus", query = "SELECT a FROM AccountEntity a WHERE a.status = :status"),
|
||||
@NamedQuery(name = "AccountEntity.findByCreatedOn", query = "SELECT a FROM AccountEntity a WHERE a.createdOn = :createdOn"),
|
||||
@NamedQuery(name = "AccountEntity.findByCreatedBy", query = "SELECT a FROM AccountEntity a WHERE a.createdBy = :createdBy"),
|
||||
@NamedQuery(name = "AccountEntity.findByLastUpdatedOn", query = "SELECT a FROM AccountEntity a WHERE a.lastUpdatedOn = :lastUpdatedOn"),
|
||||
@NamedQuery(name = "AccountEntity.findByLastUpdatedBy", query = "SELECT a FROM AccountEntity a WHERE a.lastUpdatedBy = :lastUpdatedBy")})
|
||||
public class AccountEntity implements Serializable, Account {
|
||||
|
||||
private static final long serialVersionUID = 6216991757526150935L;
|
||||
|
||||
@Id
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(generator = "uuid2")
|
||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
@Type(type = "pg-uuid")
|
||||
private UUID id;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 32)
|
||||
@Column(name = "username")
|
||||
private String username;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 200)
|
||||
@Column(name = "emailaddress")
|
||||
private String emailaddress;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 100)
|
||||
@Column(name = "firstname")
|
||||
private String firstname;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 100)
|
||||
@Column(name = "lastname")
|
||||
private String lastname;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 10)
|
||||
@Column(name = "status")
|
||||
private String status;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "created_on")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createdOn;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 32)
|
||||
@Column(name = "created_by")
|
||||
private String createdBy;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "last_updated_on")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastUpdatedOn;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 32)
|
||||
@Column(name = "last_updated_by")
|
||||
private String lastUpdatedBy;
|
||||
@JoinTable(name = "account_role", joinColumns = {
|
||||
@JoinColumn(name = "account", referencedColumnName = "id")}, inverseJoinColumns = {
|
||||
@JoinColumn(name = "account_role", referencedColumnName = "id")})
|
||||
@ManyToMany(fetch = FetchType.LAZY)
|
||||
private List<ApplicationRoleEntity> applicationRoleList;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "accountId", fetch = FetchType.LAZY)
|
||||
private List<AccountHistoryEntity> accountHistoryList;
|
||||
@OneToOne(cascade = CascadeType.ALL, mappedBy = "account")
|
||||
private AccountLoginEntity accountLogin;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "account")
|
||||
private List<ConfigEntity> configItems;
|
||||
|
||||
public AccountEntity() {
|
||||
// empty constructor required for JPA
|
||||
}
|
||||
|
||||
public void addApplicationRole(ApplicationRoleEntity applicationRole) {
|
||||
if (applicationRoleList == null) {
|
||||
applicationRoleList = new ArrayList<>();
|
||||
}
|
||||
applicationRoleList.add(applicationRole);
|
||||
}
|
||||
|
||||
/* **** getter / setter **** */
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getEmailaddress() {
|
||||
return emailaddress;
|
||||
}
|
||||
|
||||
public void setEmailaddress(String emailaddress) {
|
||||
this.emailaddress = emailaddress;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Date getCreatedOn() {
|
||||
return createdOn;
|
||||
}
|
||||
|
||||
public void setCreatedOn(Date createdOn) {
|
||||
this.createdOn = createdOn;
|
||||
}
|
||||
|
||||
public String getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
|
||||
public void setCreatedBy(String createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
public Date getLastUpdatedOn() {
|
||||
return lastUpdatedOn;
|
||||
}
|
||||
|
||||
public void setLastUpdatedOn(Date lastUpdatedOn) {
|
||||
this.lastUpdatedOn = lastUpdatedOn;
|
||||
}
|
||||
|
||||
public String getLastUpdatedBy() {
|
||||
return lastUpdatedBy;
|
||||
}
|
||||
|
||||
public void setLastUpdatedBy(String lastUpdatedBy) {
|
||||
this.lastUpdatedBy = lastUpdatedBy;
|
||||
}
|
||||
|
||||
public List<ApplicationRoleEntity> getApplicationRoleList() {
|
||||
return applicationRoleList;
|
||||
}
|
||||
|
||||
public void setApplicationRoleList(List<ApplicationRoleEntity> applicationRoleList) {
|
||||
this.applicationRoleList = applicationRoleList;
|
||||
}
|
||||
|
||||
public List<AccountHistoryEntity> getAccountHistoryList() {
|
||||
return accountHistoryList;
|
||||
}
|
||||
|
||||
public void setAccountHistoryList(List<AccountHistoryEntity> accountHistoryList) {
|
||||
this.accountHistoryList = accountHistoryList;
|
||||
}
|
||||
|
||||
public AccountLoginEntity getAccountLogin() {
|
||||
return accountLogin;
|
||||
}
|
||||
|
||||
public void setAccountLogin(AccountLoginEntity accountLogin) {
|
||||
this.accountLogin = accountLogin;
|
||||
}
|
||||
|
||||
public List<ConfigEntity> getConfigItems() {
|
||||
return configItems;
|
||||
}
|
||||
|
||||
public void setConfigItems(List<ConfigEntity> configItems) {
|
||||
this.configItems = configItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (id != null ? id.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||
if (!(object instanceof AccountEntity)) {
|
||||
return false;
|
||||
}
|
||||
AccountEntity other = (AccountEntity) object;
|
||||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "de.muehlencord.shared.account.entity.Account[ id=" + id + " ]";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,270 +1,243 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.account.business.account.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "account_login")
|
||||
@XmlRootElement
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "AccountLoginEntity.findAll", query = "SELECT a FROM AccountLoginEntity a"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByAccountPassword", query = "SELECT a FROM AccountLoginEntity a WHERE a.accountPassword = :accountPassword"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByLastLogin", query = "SELECT a FROM AccountLoginEntity a WHERE a.lastLogin = :lastLogin"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByLastFailedLogin", query = "SELECT a FROM AccountLoginEntity a WHERE a.lastFailedLogin = :lastFailedLogin"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByFailureCount", query = "SELECT a FROM AccountLoginEntity a WHERE a.failureCount = :failureCount"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByPasswordResetOngoing", query = "SELECT a FROM AccountLoginEntity a WHERE a.passwordResetOngoing = :passwordResetOngoing"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByPasswordResetValidTo", query = "SELECT a FROM AccountLoginEntity a WHERE a.passwordResetValidTo = :passwordResetValidTo"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByPasswordResetHash", query = "SELECT a FROM AccountLoginEntity a WHERE a.passwordResetHash = :passwordResetHash"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByCreatedOn", query = "SELECT a FROM AccountLoginEntity a WHERE a.createdOn = :createdOn"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByCreatedBy", query = "SELECT a FROM AccountLoginEntity a WHERE a.createdBy = :createdBy"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByLastUpdatedOn", query = "SELECT a FROM AccountLoginEntity a WHERE a.lastUpdatedOn = :lastUpdatedOn"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByLastUpdatedBy", query = "SELECT a FROM AccountLoginEntity a WHERE a.lastUpdatedBy = :lastUpdatedBy")})
|
||||
public class AccountLoginEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -799045989045040077L;
|
||||
|
||||
@Id
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(generator = "uuid2")
|
||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
@Type(type = "pg-uuid")
|
||||
private UUID id;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 32)
|
||||
@Column(name = "username")
|
||||
private String username;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 200)
|
||||
@Column(name = "emailaddress")
|
||||
private String emailaddress;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 200)
|
||||
@Column(name = "account_password")
|
||||
private String accountPassword;
|
||||
@Column(name = "last_login")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastLogin;
|
||||
@Column(name = "last_failed_login")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastFailedLogin;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "failure_count")
|
||||
private int failureCount;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "password_reset_ongoing")
|
||||
private boolean passwordResetOngoing;
|
||||
@Column(name = "password_reset_valid_to")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date passwordResetValidTo;
|
||||
@Size(max = 200)
|
||||
@Column(name = "password_reset_hash")
|
||||
private String passwordResetHash;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "created_on")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createdOn;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 32)
|
||||
@Column(name = "created_by")
|
||||
private String createdBy;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "last_updated_on")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastUpdatedOn;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 32)
|
||||
@Column(name = "last_updated_by")
|
||||
private String lastUpdatedBy;
|
||||
@JoinColumn(name = "account", referencedColumnName = "id")
|
||||
@OneToOne(optional = false)
|
||||
private AccountEntity account;
|
||||
|
||||
public AccountLoginEntity() {
|
||||
}
|
||||
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAccountPassword() {
|
||||
return accountPassword;
|
||||
}
|
||||
|
||||
public void setAccountPassword(String accountPassword) {
|
||||
this.accountPassword = accountPassword;
|
||||
}
|
||||
|
||||
public Date getLastLogin() {
|
||||
return lastLogin;
|
||||
}
|
||||
|
||||
public void setLastLogin(Date lastLogin) {
|
||||
this.lastLogin = lastLogin;
|
||||
}
|
||||
|
||||
public Date getLastFailedLogin() {
|
||||
return lastFailedLogin;
|
||||
}
|
||||
|
||||
public void setLastFailedLogin(Date lastFailedLogin) {
|
||||
this.lastFailedLogin = lastFailedLogin;
|
||||
}
|
||||
|
||||
public int getFailureCount() {
|
||||
return failureCount;
|
||||
}
|
||||
|
||||
public void setFailureCount(int failureCount) {
|
||||
this.failureCount = failureCount;
|
||||
}
|
||||
|
||||
public boolean getPasswordResetOngoing() {
|
||||
return passwordResetOngoing;
|
||||
}
|
||||
|
||||
public void setPasswordResetOngoing(boolean passwordResetOngoing) {
|
||||
this.passwordResetOngoing = passwordResetOngoing;
|
||||
}
|
||||
|
||||
public Date getPasswordResetValidTo() {
|
||||
return passwordResetValidTo;
|
||||
}
|
||||
|
||||
public void setPasswordResetValidTo(Date passwordResetValidTo) {
|
||||
this.passwordResetValidTo = passwordResetValidTo;
|
||||
}
|
||||
|
||||
public String getPasswordResetHash() {
|
||||
return passwordResetHash;
|
||||
}
|
||||
|
||||
public void setPasswordResetHash(String passwordResetHash) {
|
||||
this.passwordResetHash = passwordResetHash;
|
||||
}
|
||||
|
||||
public Date getCreatedOn() {
|
||||
return createdOn;
|
||||
}
|
||||
|
||||
public void setCreatedOn(Date createdOn) {
|
||||
this.createdOn = createdOn;
|
||||
}
|
||||
|
||||
public String getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
|
||||
public void setCreatedBy(String createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
public Date getLastUpdatedOn() {
|
||||
return lastUpdatedOn;
|
||||
}
|
||||
|
||||
public void setLastUpdatedOn(Date lastUpdatedOn) {
|
||||
this.lastUpdatedOn = lastUpdatedOn;
|
||||
}
|
||||
|
||||
public String getLastUpdatedBy() {
|
||||
return lastUpdatedBy;
|
||||
}
|
||||
|
||||
public void setLastUpdatedBy(String lastUpdatedBy) {
|
||||
this.lastUpdatedBy = lastUpdatedBy;
|
||||
}
|
||||
|
||||
public AccountEntity getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public void setAccount(AccountEntity account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getEmailaddress() {
|
||||
return emailaddress;
|
||||
}
|
||||
|
||||
public void setEmailaddress(String emailaddress) {
|
||||
this.emailaddress = emailaddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (id != null ? id.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||
if (!(object instanceof AccountLoginEntity)) {
|
||||
return false;
|
||||
}
|
||||
AccountLoginEntity other = (AccountLoginEntity) object;
|
||||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "de.muehlencord.shared.account.business.account.entity.AccountLoginEntity[ id=" + id + " ]";
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.account.business.account.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "account_login")
|
||||
@XmlRootElement
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "AccountLoginEntity.findAll", query = "SELECT a FROM AccountLoginEntity a"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByAccountPassword", query = "SELECT a FROM AccountLoginEntity a WHERE a.accountPassword = :accountPassword"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByLastLogin", query = "SELECT a FROM AccountLoginEntity a WHERE a.lastLogin = :lastLogin"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByLastFailedLogin", query = "SELECT a FROM AccountLoginEntity a WHERE a.lastFailedLogin = :lastFailedLogin"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByFailureCount", query = "SELECT a FROM AccountLoginEntity a WHERE a.failureCount = :failureCount"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByPasswordResetOngoing", query = "SELECT a FROM AccountLoginEntity a WHERE a.passwordResetOngoing = :passwordResetOngoing"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByPasswordResetValidTo", query = "SELECT a FROM AccountLoginEntity a WHERE a.passwordResetValidTo = :passwordResetValidTo"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByPasswordResetHash", query = "SELECT a FROM AccountLoginEntity a WHERE a.passwordResetHash = :passwordResetHash"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByCreatedOn", query = "SELECT a FROM AccountLoginEntity a WHERE a.createdOn = :createdOn"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByCreatedBy", query = "SELECT a FROM AccountLoginEntity a WHERE a.createdBy = :createdBy"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByLastUpdatedOn", query = "SELECT a FROM AccountLoginEntity a WHERE a.lastUpdatedOn = :lastUpdatedOn"),
|
||||
@NamedQuery(name = "AccountLoginEntity.findByLastUpdatedBy", query = "SELECT a FROM AccountLoginEntity a WHERE a.lastUpdatedBy = :lastUpdatedBy")})
|
||||
public class AccountLoginEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -799045989045040077L;
|
||||
|
||||
@Id
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(generator = "uuid2")
|
||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
@Type(type = "pg-uuid")
|
||||
private UUID id;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 200)
|
||||
@Column(name = "account_password")
|
||||
private String accountPassword;
|
||||
@Column(name = "last_login")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastLogin;
|
||||
@Column(name = "last_failed_login")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastFailedLogin;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "failure_count")
|
||||
private int failureCount;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "password_reset_ongoing")
|
||||
private boolean passwordResetOngoing;
|
||||
@Column(name = "password_reset_valid_to")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date passwordResetValidTo;
|
||||
@Size(max = 200)
|
||||
@Column(name = "password_reset_hash")
|
||||
private String passwordResetHash;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "created_on")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createdOn;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 32)
|
||||
@Column(name = "created_by")
|
||||
private String createdBy;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "last_updated_on")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastUpdatedOn;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 32)
|
||||
@Column(name = "last_updated_by")
|
||||
private String lastUpdatedBy;
|
||||
@JoinColumn(name = "account", referencedColumnName = "id")
|
||||
@OneToOne(optional = false)
|
||||
private AccountEntity account;
|
||||
|
||||
public AccountLoginEntity() {
|
||||
}
|
||||
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAccountPassword() {
|
||||
return accountPassword;
|
||||
}
|
||||
|
||||
public void setAccountPassword(String accountPassword) {
|
||||
this.accountPassword = accountPassword;
|
||||
}
|
||||
|
||||
public Date getLastLogin() {
|
||||
return lastLogin;
|
||||
}
|
||||
|
||||
public void setLastLogin(Date lastLogin) {
|
||||
this.lastLogin = lastLogin;
|
||||
}
|
||||
|
||||
public Date getLastFailedLogin() {
|
||||
return lastFailedLogin;
|
||||
}
|
||||
|
||||
public void setLastFailedLogin(Date lastFailedLogin) {
|
||||
this.lastFailedLogin = lastFailedLogin;
|
||||
}
|
||||
|
||||
public int getFailureCount() {
|
||||
return failureCount;
|
||||
}
|
||||
|
||||
public void setFailureCount(int failureCount) {
|
||||
this.failureCount = failureCount;
|
||||
}
|
||||
|
||||
public boolean getPasswordResetOngoing() {
|
||||
return passwordResetOngoing;
|
||||
}
|
||||
|
||||
public void setPasswordResetOngoing(boolean passwordResetOngoing) {
|
||||
this.passwordResetOngoing = passwordResetOngoing;
|
||||
}
|
||||
|
||||
public Date getPasswordResetValidTo() {
|
||||
return passwordResetValidTo;
|
||||
}
|
||||
|
||||
public void setPasswordResetValidTo(Date passwordResetValidTo) {
|
||||
this.passwordResetValidTo = passwordResetValidTo;
|
||||
}
|
||||
|
||||
public String getPasswordResetHash() {
|
||||
return passwordResetHash;
|
||||
}
|
||||
|
||||
public void setPasswordResetHash(String passwordResetHash) {
|
||||
this.passwordResetHash = passwordResetHash;
|
||||
}
|
||||
|
||||
public Date getCreatedOn() {
|
||||
return createdOn;
|
||||
}
|
||||
|
||||
public void setCreatedOn(Date createdOn) {
|
||||
this.createdOn = createdOn;
|
||||
}
|
||||
|
||||
public String getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
|
||||
public void setCreatedBy(String createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
public Date getLastUpdatedOn() {
|
||||
return lastUpdatedOn;
|
||||
}
|
||||
|
||||
public void setLastUpdatedOn(Date lastUpdatedOn) {
|
||||
this.lastUpdatedOn = lastUpdatedOn;
|
||||
}
|
||||
|
||||
public String getLastUpdatedBy() {
|
||||
return lastUpdatedBy;
|
||||
}
|
||||
|
||||
public void setLastUpdatedBy(String lastUpdatedBy) {
|
||||
this.lastUpdatedBy = lastUpdatedBy;
|
||||
}
|
||||
|
||||
public AccountEntity getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public void setAccount(AccountEntity account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (id != null ? id.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||
if (!(object instanceof AccountLoginEntity)) {
|
||||
return false;
|
||||
}
|
||||
AccountLoginEntity other = (AccountLoginEntity) object;
|
||||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "de.muehlencord.shared.account.business.account.entity.AccountLoginEntity[ id=" + id + " ]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,82 +1,87 @@
|
||||
package de.muehlencord.shared.account.business.application.boundary;
|
||||
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@Stateless
|
||||
public class ApplicationService implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4262608935325326191L;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationService.class);
|
||||
|
||||
@Inject
|
||||
EntityManager em;
|
||||
|
||||
public List<ApplicationEntity> getAllApplications() {
|
||||
Query query = em.createNamedQuery("ApplicationEntity.findAll");
|
||||
List<ApplicationEntity> resultList = query.getResultList();
|
||||
if (resultList == null) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ApplicationEntity createOrUpdate(ApplicationEntity app) {
|
||||
if (app == null) {
|
||||
// TODO add error handling
|
||||
return null;
|
||||
} else {
|
||||
if (app.getId() == null) {
|
||||
em.persist(app);
|
||||
ApplicationEntity returnValue = findByApplicationName(app.getApplicationName());
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Application {} created", app.getApplicationName());
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
} else {
|
||||
ApplicationEntity returnValue = em.merge(app);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Applicateion {} updated", app.getApplicationName());
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ApplicationEntity findByApplicationName(String applicationName) {
|
||||
Query query = em.createNamedQuery("ApplicationEntity.findByApplicationName");
|
||||
query.setParameter("applicationName", applicationName);
|
||||
List<ApplicationEntity> resultList = query.getResultList();
|
||||
if ((resultList == null) || (resultList.isEmpty())) {
|
||||
return null;
|
||||
} else {
|
||||
return resultList.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void delete(ApplicationEntity app) {
|
||||
ApplicationEntity attachedApp = em.find(ApplicationEntity.class, app.getId());
|
||||
em.remove(attachedApp);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Application {} deleted", app.getApplicationName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package de.muehlencord.shared.account.business.application.boundary;
|
||||
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@Stateless
|
||||
public class ApplicationService implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4262608935325326191L;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationService.class);
|
||||
|
||||
@Inject
|
||||
EntityManager em;
|
||||
|
||||
public ApplicationEntity findById(UUID id) {
|
||||
return em.find(ApplicationEntity.class, id);
|
||||
}
|
||||
|
||||
public List<ApplicationEntity> getAllApplications() {
|
||||
Query query = em.createNamedQuery("ApplicationEntity.findAll");
|
||||
List<ApplicationEntity> resultList = query.getResultList();
|
||||
if (resultList == null) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ApplicationEntity createOrUpdate(ApplicationEntity app) {
|
||||
if (app == null) {
|
||||
// TODO add error handling
|
||||
return null;
|
||||
} else {
|
||||
if (app.getId() == null) {
|
||||
em.persist(app);
|
||||
ApplicationEntity returnValue = findByApplicationName(app.getApplicationName());
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Application {} created", app.getApplicationName());
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
} else {
|
||||
ApplicationEntity returnValue = em.merge(app);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Applicateion {} updated", app.getApplicationName());
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ApplicationEntity findByApplicationName(String applicationName) {
|
||||
Query query = em.createNamedQuery("ApplicationEntity.findByApplicationName");
|
||||
query.setParameter("applicationName", applicationName);
|
||||
List<ApplicationEntity> resultList = query.getResultList();
|
||||
if ((resultList == null) || (resultList.isEmpty())) {
|
||||
return null;
|
||||
} else {
|
||||
return resultList.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void delete(ApplicationEntity app) {
|
||||
ApplicationEntity attachedApp = em.find(ApplicationEntity.class, app.getId());
|
||||
em.remove(attachedApp);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Application {} deleted", app.getApplicationName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,131 +1,131 @@
|
||||
package de.muehlencord.shared.account.business.application.entity;
|
||||
|
||||
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
|
||||
import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
|
||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "application")
|
||||
@XmlRootElement
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "ApplicationEntity.findAll", query = "SELECT a FROM ApplicationEntity a"),
|
||||
@NamedQuery(name = "ApplicationEntity.findByApplicationName", query = "SELECT a FROM ApplicationEntity a WHERE a.applicationName = :applicationName")})
|
||||
public class ApplicationEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6407525020014743727L;
|
||||
|
||||
@Id
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(generator = "uuid2")
|
||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
@Type(type = "pg-uuid")
|
||||
private UUID id;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 200)
|
||||
@Column(name = "application_name", unique = true)
|
||||
private String applicationName;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "application")
|
||||
private List<ApplicationRoleEntity> applicationRoleEntityList;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "application")
|
||||
private List<ApplicationPermissionEntity> applicationPermissions;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "application")
|
||||
private List<ConfigEntity> configItems;
|
||||
|
||||
public ApplicationEntity() {
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getApplicationName() {
|
||||
return applicationName;
|
||||
}
|
||||
|
||||
public void setApplicationName(String applicationName) {
|
||||
this.applicationName = applicationName;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public List<ApplicationRoleEntity> getApplicationRoleEntityList() {
|
||||
return applicationRoleEntityList;
|
||||
}
|
||||
|
||||
public void setApplicationRoleEntityList(List<ApplicationRoleEntity> applicationRoleEntityList) {
|
||||
this.applicationRoleEntityList = applicationRoleEntityList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (id != null ? id.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||
if (!(object instanceof ApplicationEntity)) {
|
||||
return false;
|
||||
}
|
||||
ApplicationEntity other = (ApplicationEntity) object;
|
||||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "de.muehlencord.shared.account.business.application.entity.ApplicationEntity[ id=" + id + " ]";
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public List<ApplicationPermissionEntity> getApplicationPermissions() {
|
||||
return applicationPermissions;
|
||||
}
|
||||
|
||||
public void setApplicationPermissions(List<ApplicationPermissionEntity> applicationPermissions) {
|
||||
this.applicationPermissions = applicationPermissions;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public List<ConfigEntity> getConfigItems() {
|
||||
return configItems;
|
||||
}
|
||||
|
||||
public void setConfigItems(List<ConfigEntity> configItems) {
|
||||
this.configItems = configItems;
|
||||
}
|
||||
|
||||
}
|
||||
package de.muehlencord.shared.account.business.application.entity;
|
||||
|
||||
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
|
||||
import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
|
||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "application")
|
||||
@XmlRootElement
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "ApplicationEntity.findAll", query = "SELECT a FROM ApplicationEntity a"),
|
||||
@NamedQuery(name = "ApplicationEntity.findByApplicationName", query = "SELECT a FROM ApplicationEntity a WHERE a.applicationName = :applicationName")})
|
||||
public class ApplicationEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6407525020014743727L;
|
||||
|
||||
@Id
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(generator = "uuid2")
|
||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
@Type(type = "pg-uuid")
|
||||
private UUID id;
|
||||
@Basic(optional = false)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 200)
|
||||
@Column(name = "application_name", unique = true)
|
||||
private String applicationName;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "application")
|
||||
private List<ApplicationRoleEntity> applicationRoleEntityList;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "application")
|
||||
private List<ApplicationPermissionEntity> applicationPermissions;
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "application")
|
||||
private List<ConfigEntity> configEntityList;
|
||||
|
||||
public ApplicationEntity() {
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getApplicationName() {
|
||||
return applicationName;
|
||||
}
|
||||
|
||||
public void setApplicationName(String applicationName) {
|
||||
this.applicationName = applicationName;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public List<ApplicationRoleEntity> getApplicationRoleEntityList() {
|
||||
return applicationRoleEntityList;
|
||||
}
|
||||
|
||||
public void setApplicationRoleEntityList(List<ApplicationRoleEntity> applicationRoleEntityList) {
|
||||
this.applicationRoleEntityList = applicationRoleEntityList;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public List<ApplicationPermissionEntity> getApplicationPermissions() {
|
||||
return applicationPermissions;
|
||||
}
|
||||
|
||||
public void setApplicationPermissions(List<ApplicationPermissionEntity> applicationPermissions) {
|
||||
this.applicationPermissions = applicationPermissions;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public List<ConfigEntity> getConfigEntityList() {
|
||||
return configEntityList;
|
||||
}
|
||||
|
||||
public void setConfigEntityList(List<ConfigEntity> configEntityList) {
|
||||
this.configEntityList = configEntityList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (id != null ? id.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||
if (!(object instanceof ApplicationEntity)) {
|
||||
return false;
|
||||
}
|
||||
ApplicationEntity other = (ApplicationEntity) object;
|
||||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "de.muehlencord.shared.account.business.application.entity.ApplicationEntity[ id=" + id + " ]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,237 +1,204 @@
|
||||
package de.muehlencord.shared.account.business.config.boundary;
|
||||
|
||||
import de.muehlencord.shared.account.business.account.entity.Account;
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
|
||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntityPK;
|
||||
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Lock;
|
||||
import javax.ejb.LockType;
|
||||
import javax.ejb.Singleton;
|
||||
import javax.ejb.Startup;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
@Singleton
|
||||
@Startup
|
||||
public class ConfigService implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3195224653632853003L;
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigService.class);
|
||||
|
||||
@Inject
|
||||
EntityManager em;
|
||||
|
||||
// private String storagePath = null;
|
||||
// private int maxFailedLogins = 5;
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// ConfigEntity configEntity = em.find(ConfigEntity.class, "storage.path");
|
||||
// if (configEntity != null) {
|
||||
// this.storagePath = configEntity.getConfigValue();
|
||||
// }
|
||||
// configEntity = em.find(ConfigEntity.class, "account.maxFailedLogins");
|
||||
// if (configEntity != null) {
|
||||
// this.maxFailedLogins = Integer.parseInt(configEntity.getConfigValue());
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* returns global config key which is not assigned to any. If more than one
|
||||
* value is defined for the given key, the key assigned to system is
|
||||
* returned. If more than one key is defined but system key is not defined,
|
||||
* an exception is thrown.
|
||||
*
|
||||
* @param configKey the key to return
|
||||
* @return the configValue belonging to the given configKey
|
||||
* @throws
|
||||
* de.muehlencord.shared.account.business.config.entity.ConfigException if
|
||||
* more than one value is defined for the given key but none of the values
|
||||
* is defined for the system user
|
||||
*/
|
||||
public String getConfigValue(ApplicationEntity application, String configKey) throws ConfigException {
|
||||
Query query = em.createNamedQuery("ConfigEntity.findByConfigKey");
|
||||
query.setParameter ("application", application);
|
||||
query.setParameter("configKey", configKey);
|
||||
List<ConfigEntity> configList = query.getResultList();
|
||||
if ((configList == null) || (configList.isEmpty())) {
|
||||
// key is not found in the database at all
|
||||
return null;
|
||||
} else if (configList.size() == 1) {
|
||||
// exact one element found, return this one
|
||||
return configList.get(0).getConfigValue();
|
||||
} else {
|
||||
// if more than one result found, return the one which is assigned to system if present
|
||||
// if not present, throw exception
|
||||
Optional<ConfigEntity> firstItem = configList.stream()
|
||||
.filter(config -> config.getConfigPK().getConfigKeyAccount().getUsername().equals("system"))
|
||||
.findFirst();
|
||||
if (firstItem.isPresent()) {
|
||||
return firstItem.get().getConfigValue();
|
||||
} else {
|
||||
throw new ConfigException("ConfigKey " + configKey + " not unique and system value not defined");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getConfigValue(ApplicationEntity application, String configKey, String defaultValue) throws ConfigException {
|
||||
return getConfigValue(application, configKey, defaultValue, false);
|
||||
}
|
||||
|
||||
public String getConfigValue(ApplicationEntity application, String configKey, String defaultValue, boolean storeDefaultValue) throws ConfigException {
|
||||
// get configValue as usual
|
||||
String configValue = getConfigValue(application, configKey);
|
||||
|
||||
// if config value is not found null has been returned
|
||||
// in this case the value to return is the defaultValue
|
||||
if (configValue == null) {
|
||||
configValue = defaultValue;
|
||||
}
|
||||
|
||||
// check if the default value should be stored in the database
|
||||
if (storeDefaultValue) {
|
||||
AccountEntity account = getAccount("system");
|
||||
updateConfigValue(application, configKey, account, configValue);
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public String getConfigValue(ApplicationEntity application, String configKey, Account account, boolean fallbackToSystem) throws ConfigException {
|
||||
Query query = em.createNamedQuery("ConfigEntity.findByConfigKeyAndAccount");
|
||||
query.setParameter("configKey", configKey);
|
||||
query.setParameter("account", account);
|
||||
List<ConfigEntity> configList = query.getResultList();
|
||||
if ((configList == null) || (configList.isEmpty())) {
|
||||
// fallback to default / system value
|
||||
if (fallbackToSystem) {
|
||||
return getConfigValue(application, configKey);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else if (configList.size() == 1) {
|
||||
// exact one element found, return this one
|
||||
return configList.get(0).getConfigValue();
|
||||
} else {
|
||||
// more than one value must not happen - this is not possible per the defintion of the datamodel
|
||||
throw new ConfigException("Cannot have more than one value for the the given key " + configKey + " and the given account " + account.getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
public String getConfigValue(ApplicationEntity application, String configKey, String defaultValue, boolean storeDefaultValue, Account account, boolean fallbackToSystem) throws ConfigException {
|
||||
String configValue = getConfigValue(application, configKey, account, fallbackToSystem);
|
||||
|
||||
if (configValue == null) {
|
||||
// value not found for given account and if allowed also not found for system user
|
||||
configValue = defaultValue;
|
||||
}
|
||||
|
||||
// check if the default value should be stored in the database
|
||||
if (storeDefaultValue) {
|
||||
updateConfigValue(application, configKey, account, configValue);
|
||||
}
|
||||
|
||||
return configValue;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Lock(LockType.WRITE)
|
||||
public boolean updateConfigValue(ApplicationEntity application,String configKey, String configValue) throws ConfigException {
|
||||
Account account = getAccount("system");
|
||||
return updateConfigValue(application, configKey, account, configValue);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Lock(LockType.WRITE)
|
||||
public boolean updateConfigValue(ApplicationEntity application,String configKey, String accountName, String configValue) {
|
||||
Account account = getAccount(accountName);
|
||||
if (accountName == null) {
|
||||
return false;
|
||||
}
|
||||
if (account == null) {
|
||||
LOGGER.error("Account for usreName {} not found", accountName);
|
||||
return false;
|
||||
}
|
||||
return updateConfigValue(application, configKey, account, configValue);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Lock(LockType.WRITE)
|
||||
public boolean updateConfigValue(ApplicationEntity application, String configKey, Account account, String configValue) {
|
||||
if ((configKey == null) || (configKey.equals("")) || (configValue == null) || (configValue.equals(""))) {
|
||||
// null or empty key / values are not possible
|
||||
return false;
|
||||
}
|
||||
|
||||
if (account == null) {
|
||||
LOGGER.error("Account must not be null, not updating");
|
||||
return false;
|
||||
}
|
||||
|
||||
AccountEntity accountEntity = getAccount (account.getUsername());
|
||||
ConfigEntityPK pk = new ConfigEntityPK(application, configKey, accountEntity);
|
||||
ConfigEntity currentEntity = em.find(ConfigEntity.class, pk);
|
||||
if (currentEntity == null) {
|
||||
currentEntity = new ConfigEntity(pk);
|
||||
currentEntity.setConfigValue(configValue);
|
||||
em.persist(currentEntity);
|
||||
return true; // config item created - udpate performed
|
||||
} else {
|
||||
if ((currentEntity.getConfigValue() != null) && (currentEntity.getConfigValue().equals(configValue))) {
|
||||
// value is the same - no update
|
||||
return false;
|
||||
} else {
|
||||
currentEntity.setConfigValue(configValue);
|
||||
em.merge(currentEntity);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AccountEntity getAccount(String accountName) {
|
||||
Query query = em.createNamedQuery("AccountEntity.findByUsername");
|
||||
query.setParameter("username", accountName);
|
||||
List<AccountEntity> accountList = query.getResultList();
|
||||
if ((accountList == null) || (accountList.isEmpty())) {
|
||||
return null;
|
||||
} else {
|
||||
return accountList.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* *** getter *** */
|
||||
/**
|
||||
* FIXME remove, this is application specific
|
||||
*
|
||||
* @return
|
||||
* @deprecated replace by getConfigValue ("storage.path")
|
||||
*/
|
||||
// @Deprecated
|
||||
// public String getStoragePath() {
|
||||
// return storagePath;
|
||||
// }
|
||||
/**
|
||||
* // TODO move to accountControl
|
||||
*
|
||||
* @return
|
||||
* @deprecated replace by getConfigValue ("account.maxFailedLogins")
|
||||
*/
|
||||
// @Deprecated
|
||||
// public int getMaxFailedLogins() {
|
||||
// return maxFailedLogins;
|
||||
// }
|
||||
}
|
||||
package de.muehlencord.shared.account.business.config.boundary;
|
||||
|
||||
import de.muehlencord.shared.account.business.account.entity.Account;
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
|
||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntityPK;
|
||||
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Lock;
|
||||
import javax.ejb.LockType;
|
||||
import javax.ejb.Singleton;
|
||||
import javax.ejb.Startup;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
@Singleton
|
||||
@Startup
|
||||
public class ConfigService implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3195224653632853003L;
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigService.class);
|
||||
|
||||
@Inject
|
||||
EntityManager em;
|
||||
|
||||
@Inject
|
||||
ApplicationEntity application;
|
||||
|
||||
/**
|
||||
* returns global config key which is not assigned to any. If more than one
|
||||
* value is defined for the given key, the key assigned to system is
|
||||
* returned. If more than one key is defined but system key is not defined,
|
||||
* an exception is thrown.
|
||||
*
|
||||
* @param configKey the key to return
|
||||
* @return the configValue belonging to the given configKey
|
||||
* @throws
|
||||
* de.muehlencord.shared.account.business.config.entity.ConfigException if
|
||||
* more than one value is defined for the given key but none of the values
|
||||
* is defined for the system user
|
||||
*/
|
||||
public String getConfigValue(String configKey) throws ConfigException {
|
||||
Query query = em.createNamedQuery("ConfigEntity.findByConfigKey");
|
||||
query.setParameter("application", application);
|
||||
query.setParameter("configKey", configKey);
|
||||
List<ConfigEntity> configList = query.getResultList();
|
||||
if ((configList == null) || (configList.isEmpty())) {
|
||||
// key is not found in the database at all
|
||||
return null;
|
||||
} else if (configList.size() == 1) {
|
||||
// exact one element found, return this one
|
||||
return configList.get(0).getConfigValue();
|
||||
} else {
|
||||
// if more than one result found, return the one which is assigned to system if present
|
||||
// if not present, throw exception
|
||||
Optional<ConfigEntity> firstItem = configList.stream()
|
||||
.filter(config -> config.getConfigPK().getConfigKeyAccount().getUsername().equals("system"))
|
||||
.findFirst();
|
||||
if (firstItem.isPresent()) {
|
||||
return firstItem.get().getConfigValue();
|
||||
} else {
|
||||
throw new ConfigException("ConfigKey " + configKey + " not unique and system value not defined");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getConfigValue(String configKey, String defaultValue) throws ConfigException {
|
||||
return getConfigValue(configKey, defaultValue, false);
|
||||
}
|
||||
|
||||
public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue) throws ConfigException {
|
||||
// get configValue as usual
|
||||
String configValue = getConfigValue(configKey);
|
||||
|
||||
// if config value is not found null has been returned
|
||||
// in this case the value to return is the defaultValue
|
||||
if (configValue == null) {
|
||||
configValue = defaultValue;
|
||||
}
|
||||
|
||||
// check if the default value should be stored in the database
|
||||
if (storeDefaultValue) {
|
||||
AccountEntity account = getAccount("system");
|
||||
updateConfigValue(configKey, account, configValue);
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public String getConfigValue(String configKey, Account account, boolean fallbackToSystem) throws ConfigException {
|
||||
Query query = em.createNamedQuery("ConfigEntity.findByConfigKeyAndAccount");
|
||||
query.setParameter("configKey", configKey);
|
||||
query.setParameter("account", account);
|
||||
List<ConfigEntity> configList = query.getResultList();
|
||||
if ((configList == null) || (configList.isEmpty())) {
|
||||
// fallback to default / system value
|
||||
if (fallbackToSystem) {
|
||||
return getConfigValue(configKey);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else if (configList.size() == 1) {
|
||||
// exact one element found, return this one
|
||||
return configList.get(0).getConfigValue();
|
||||
} else {
|
||||
// more than one value must not happen - this is not possible per the defintion of the datamodel
|
||||
throw new ConfigException("Cannot have more than one value for the the given key " + configKey + " and the given account " + account.getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue, Account account, boolean fallbackToSystem) throws ConfigException {
|
||||
String configValue = getConfigValue(configKey, account, fallbackToSystem);
|
||||
|
||||
if (configValue == null) {
|
||||
// value not found for given account and if allowed also not found for system user
|
||||
configValue = defaultValue;
|
||||
}
|
||||
|
||||
// check if the default value should be stored in the database
|
||||
if (storeDefaultValue) {
|
||||
updateConfigValue(configKey, account, configValue);
|
||||
}
|
||||
|
||||
return configValue;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Lock(LockType.WRITE)
|
||||
public boolean updateConfigValue(String configKey, String configValue) throws ConfigException {
|
||||
Account account = getAccount("system");
|
||||
return updateConfigValue(configKey, account, configValue);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Lock(LockType.WRITE)
|
||||
public boolean updateConfigValue(String configKey, String accountName, String configValue) {
|
||||
Account account = getAccount(accountName);
|
||||
if (accountName == null) {
|
||||
return false;
|
||||
}
|
||||
if (account == null) {
|
||||
LOGGER.error("Account for usreName {} not found", accountName);
|
||||
return false;
|
||||
}
|
||||
return updateConfigValue(configKey, account, configValue);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Lock(LockType.WRITE)
|
||||
public boolean updateConfigValue(String configKey, Account account, String configValue) {
|
||||
if ((configKey == null) || (configKey.equals("")) || (configValue == null) || (configValue.equals(""))) {
|
||||
// null or empty key / values are not possible
|
||||
return false;
|
||||
}
|
||||
|
||||
if (account == null) {
|
||||
LOGGER.error("Account must not be null, not updating");
|
||||
return false;
|
||||
}
|
||||
|
||||
AccountEntity accountEntity = getAccount(account.getUsername());
|
||||
ConfigEntityPK pk = new ConfigEntityPK(application, configKey, accountEntity);
|
||||
ConfigEntity currentEntity = em.find(ConfigEntity.class, pk);
|
||||
if (currentEntity == null) {
|
||||
currentEntity = new ConfigEntity(pk);
|
||||
currentEntity.setConfigValue(configValue);
|
||||
em.persist(currentEntity);
|
||||
return true; // config item created - udpate performed
|
||||
} else {
|
||||
if ((currentEntity.getConfigValue() != null) && (currentEntity.getConfigValue().equals(configValue))) {
|
||||
// value is the same - no update
|
||||
return false;
|
||||
} else {
|
||||
currentEntity.setConfigValue(configValue);
|
||||
em.merge(currentEntity);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AccountEntity getAccount(String accountName) {
|
||||
Query query = em.createNamedQuery("AccountEntity.findByUsername");
|
||||
query.setParameter("username", accountName);
|
||||
List<AccountEntity> accountList = query.getResultList();
|
||||
if ((accountList == null) || (accountList.isEmpty())) {
|
||||
return null;
|
||||
} else {
|
||||
return accountList.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,127 +1,149 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.account.business.config.entity;
|
||||
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Cacheable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.QueryHint;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "config")
|
||||
@XmlRootElement
|
||||
@Cacheable(true)
|
||||
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region = "Configuration")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "ConfigEntity.findAll", query = "SELECT c FROM ConfigEntity c ORDER BY c.configPK.configKey",
|
||||
hints = {
|
||||
@QueryHint(name = "org.hibernate.cacheable", value = "true"),
|
||||
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}),
|
||||
@NamedQuery(name = "ConfigEntity.findByConfigKey", query = "SELECT c FROM ConfigEntity c WHERE c.configPK.application = :application AND c.configPK.configKey = :configKey",
|
||||
hints = {
|
||||
@QueryHint(name = "org.hibernate.cacheable", value = "true"),
|
||||
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}),
|
||||
@NamedQuery(name = "ConfigEntity.findByConfigKeyAndAccount", query = "SELECT c FROM ConfigEntity c WHERE c.configPK.application = :application AND c.configPK.configKey = :configKey AND c.configPK.configKeyAccount = :account",
|
||||
hints = {
|
||||
@QueryHint(name = "org.hibernate.cacheable", value = "true"),
|
||||
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}),
|
||||
@NamedQuery(name = "ConfigEntity.findByConfigValue", query = "SELECT c FROM ConfigEntity c WHERE c.configPK.application = :application AND c.configValue = :configValue",
|
||||
hints = {
|
||||
@QueryHint(name = "org.hibernate.cacheable", value = "true"),
|
||||
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")})
|
||||
})
|
||||
|
||||
public class ConfigEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2013982316933782223L;
|
||||
|
||||
@EmbeddedId
|
||||
protected ConfigEntityPK configPK;
|
||||
@Size(max = 200)
|
||||
@Column(name = "config_value")
|
||||
private String configValue;
|
||||
@Size(max = 200)
|
||||
@Column(name = "config_key_group")
|
||||
private String configKeyGroup;
|
||||
|
||||
public ConfigEntity() {
|
||||
}
|
||||
|
||||
public ConfigEntity(ApplicationEntity application, String configKey, AccountEntity account) {
|
||||
this.configPK = new ConfigEntityPK(application, configKey, account);
|
||||
}
|
||||
|
||||
public ConfigEntity(ConfigEntityPK configPK) {
|
||||
this.configPK = configPK;
|
||||
}
|
||||
|
||||
public ConfigEntityPK getConfigPK() {
|
||||
return configPK;
|
||||
}
|
||||
|
||||
public void setConfigPK(ConfigEntityPK configPK) {
|
||||
this.configPK = configPK;
|
||||
}
|
||||
|
||||
public String getConfigValue() {
|
||||
return configValue;
|
||||
}
|
||||
|
||||
public void setConfigValue(String configValue) {
|
||||
this.configValue = configValue;
|
||||
}
|
||||
|
||||
public String getConfigKeyGroup() {
|
||||
return configKeyGroup;
|
||||
}
|
||||
|
||||
public void setConfigKeyGroup(String configKeyGroup) {
|
||||
this.configKeyGroup = configKeyGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (configPK != null ? configPK.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||
if (!(object instanceof ConfigEntity)) {
|
||||
return false;
|
||||
}
|
||||
ConfigEntity other = (ConfigEntity) object;
|
||||
if ((this.configPK == null && other.configPK != null) || (this.configPK != null && !this.configPK.equals(other.configPK))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "de.muehlencord.shared.account.business.config.entity.Config[ configPK=" + configPK + " ]";
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.account.business.config.entity;
|
||||
|
||||
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Cacheable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.QueryHint;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "config")
|
||||
@XmlRootElement
|
||||
@Cacheable(true)
|
||||
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region = "Configuration")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "ConfigEntity.findAll", query = "SELECT c FROM ConfigEntity c ORDER BY c.configPK.configKey",
|
||||
hints = {
|
||||
@QueryHint(name = "org.hibernate.cacheable", value = "true"),
|
||||
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}),
|
||||
@NamedQuery(name = "ConfigEntity.findByConfigKey", query = "SELECT c FROM ConfigEntity c WHERE c.configPK.application = :application AND c.configPK.configKey = :configKey",
|
||||
hints = {
|
||||
@QueryHint(name = "org.hibernate.cacheable", value = "true"),
|
||||
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}),
|
||||
@NamedQuery(name = "ConfigEntity.findByConfigKeyAndAccount", query = "SELECT c FROM ConfigEntity c WHERE c.configPK.application = :application AND c.configPK.configKey = :configKey AND c.configPK.configKeyAccount = :account",
|
||||
hints = {
|
||||
@QueryHint(name = "org.hibernate.cacheable", value = "true"),
|
||||
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}),
|
||||
@NamedQuery(name = "ConfigEntity.findByConfigValue", query = "SELECT c FROM ConfigEntity c WHERE c.configPK.application = :application AND c.configValue = :configValue",
|
||||
hints = {
|
||||
@QueryHint(name = "org.hibernate.cacheable", value = "true"),
|
||||
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")})
|
||||
})
|
||||
|
||||
public class ConfigEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2013982316933782223L;
|
||||
|
||||
@EmbeddedId
|
||||
protected ConfigEntityPK configPK;
|
||||
@Size(max = 200)
|
||||
@Column(name = "config_value")
|
||||
private String configValue;
|
||||
@Size(max = 200)
|
||||
@Column(name = "config_key_group")
|
||||
private String configKeyGroup;
|
||||
@JoinColumn(name = "config_key_account", referencedColumnName = "id", insertable = false, updatable = false)
|
||||
@ManyToOne(optional = false)
|
||||
private AccountEntity account;
|
||||
@JoinColumn(name = "application", referencedColumnName = "id", insertable = false, updatable = false)
|
||||
@ManyToOne(optional = false)
|
||||
private ApplicationEntity application;
|
||||
|
||||
public ConfigEntity() {
|
||||
}
|
||||
|
||||
public ConfigEntity(ApplicationEntity application, String configKey, AccountEntity account) {
|
||||
this.configPK = new ConfigEntityPK(application, configKey, account);
|
||||
}
|
||||
|
||||
public ConfigEntity(ConfigEntityPK configPK) {
|
||||
this.configPK = configPK;
|
||||
}
|
||||
|
||||
public ConfigEntityPK getConfigPK() {
|
||||
return configPK;
|
||||
}
|
||||
|
||||
public void setConfigPK(ConfigEntityPK configPK) {
|
||||
this.configPK = configPK;
|
||||
}
|
||||
|
||||
public String getConfigValue() {
|
||||
return configValue;
|
||||
}
|
||||
|
||||
public void setConfigValue(String configValue) {
|
||||
this.configValue = configValue;
|
||||
}
|
||||
|
||||
public String getConfigKeyGroup() {
|
||||
return configKeyGroup;
|
||||
}
|
||||
|
||||
public void setConfigKeyGroup(String configKeyGroup) {
|
||||
this.configKeyGroup = configKeyGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (configPK != null ? configPK.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
// TODO: Warning - this method won't work in the case the id fields are not set
|
||||
if (!(object instanceof ConfigEntity)) {
|
||||
return false;
|
||||
}
|
||||
ConfigEntity other = (ConfigEntity) object;
|
||||
if ((this.configPK == null && other.configPK != null) || (this.configPK != null && !this.configPK.equals(other.configPK))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "de.muehlencord.shared.account.business.config.entity.Config[ configPK=" + configPK + " ]";
|
||||
}
|
||||
|
||||
public AccountEntity getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public void setAccount(AccountEntity account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public ApplicationEntity getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
public void setApplication(ApplicationEntity application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ public class MailService implements Serializable {
|
||||
String resetUrlWithToken = passwordResetUrl + "?token=" + token;
|
||||
model.addParameter("url", baseUrl);
|
||||
model.addParameter("resetUrl", resetUrlWithToken);
|
||||
return sendHTMLMail(account.getAccountLogin().getEmailaddress(), "Reset your password", model, "password_reset_html");
|
||||
return sendHTMLMail(account.getEmailaddress(), "Reset your password", model, "password_reset_html");
|
||||
}
|
||||
|
||||
private String transportMail(Message message) throws MessagingException {
|
||||
|
||||
@ -37,9 +37,9 @@ public class ConfigServiceTest {
|
||||
application.setApplicationName("Test App");
|
||||
|
||||
AccountEntity account = new AccountEntity();
|
||||
account.setUsername("system");
|
||||
AccountLoginEntity login = new AccountLoginEntity();
|
||||
login.setAccount (account);
|
||||
login.setUsername("system");
|
||||
account.setAccountLogin(login);
|
||||
|
||||
ConfigEntityPK pk = new ConfigEntityPK(application, "account.maxFailedLogins", account);
|
||||
@ -52,7 +52,7 @@ public class ConfigServiceTest {
|
||||
@Ignore
|
||||
// TODO move to account test
|
||||
public void testGetMaxFailedLogins() {
|
||||
configService.init();
|
||||
// configService.init();
|
||||
// assertEquals ("maxFailedLogins", 7, configService.getMaxFailedLogins());
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.account.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
public class SecurityUtilTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreatePassword() {
|
||||
System.out.println (SecurityUtil.createPassword("secret"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user