diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/ConfigurationProducer.java b/account-ui/src/main/java/de/muehlencord/shared/account/web/ConfigurationProducer.java index 09bd878..2afebd5 100644 --- a/account-ui/src/main/java/de/muehlencord/shared/account/web/ConfigurationProducer.java +++ b/account-ui/src/main/java/de/muehlencord/shared/account/web/ConfigurationProducer.java @@ -6,8 +6,8 @@ package de.muehlencord.shared.account.web; import de.muehlencord.shared.account.business.config.boundary.ConfigService; -import de.muehlencord.shared.account.business.accountcounfig.entity.AccountConfigurationKey; -import de.muehlencord.shared.account.business.accountcounfig.entity.AccountConfigurationValue; +import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationKey; +import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationValue; import de.muehlencord.shared.account.business.config.entity.ConfigException; import javax.ejb.EJB; import javax.enterprise.context.Dependent; diff --git a/account/sql/account.dbm b/account/sql/account.dbm index 5d78fbf..3d64657 100644 --- a/account/sql/account.dbm +++ b/account/sql/account.dbm @@ -3,17 +3,20 @@ CAUTION: Do not modify this file unless you know what you are doing. Unexpected results may occur if the code is changed deliberately. --> - - + + - +
- + + + + @@ -27,13 +30,13 @@ CAUTION: Do not modify this file unless you know what you are doing. - +
- +
- + @@ -54,9 +57,9 @@ CAUTION: Do not modify this file unless you know what you are doing.
- +
- + @@ -72,30 +75,9 @@ CAUTION: Do not modify this file unless you know what you are doing. - - - - - - - - - - - - - - - - - - - - - @@ -116,9 +98,9 @@ CAUTION: Do not modify this file unless you know what you are doing.
- +
- + @@ -145,9 +127,9 @@ CAUTION: Do not modify this file unless you know what you are doing.
- +
- + @@ -159,9 +141,9 @@ CAUTION: Do not modify this file unless you know what you are doing.
- +
- + @@ -182,9 +164,9 @@ CAUTION: Do not modify this file unless you know what you are doing.
- +
- + @@ -196,9 +178,9 @@ CAUTION: Do not modify this file unless you know what you are doing.
- +
- + @@ -210,9 +192,9 @@ CAUTION: Do not modify this file unless you know what you are doing.
- +
- + @@ -224,16 +206,72 @@ CAUTION: Do not modify this file unless you know what you are doing.
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + @@ -276,6 +314,12 @@ CAUTION: Do not modify this file unless you know what you are doing. + + + + + + + + +
diff --git a/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/AccountControl.java b/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/AccountControl.java index 4b620de..e2e5f2f 100644 --- a/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/AccountControl.java +++ b/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/AccountControl.java @@ -281,7 +281,7 @@ public class AccountControl implements Serializable { em.merge(account); } - public void addLoginError(AccountEntity account) { + public void addLoginError(ApplicationEntity application, AccountEntity account) { try { Date now = new Date(); // TODO now in UTC account.setLastFailedLogin(now); diff --git a/account/src/main/java/de/muehlencord/shared/account/business/account/entity/AccountEntity.java b/account/src/main/java/de/muehlencord/shared/account/business/account/entity/AccountEntity.java index a0ae29e..3a83ac0 100644 --- a/account/src/main/java/de/muehlencord/shared/account/business/account/entity/AccountEntity.java +++ b/account/src/main/java/de/muehlencord/shared/account/business/account/entity/AccountEntity.java @@ -1,5 +1,6 @@ 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; @@ -18,6 +19,7 @@ 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; @@ -38,7 +40,6 @@ import org.hibernate.annotations.Type; @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.findByEmailaddress", query = "SELECT a FROM AccountEntity a WHERE a.emailaddress = :emailaddress ORDER BY a.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"), @@ -55,6 +56,9 @@ import org.hibernate.annotations.Type; @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 configEntityList; + private static final long serialVersionUID = 6216991757526150935L; @Id @@ -67,16 +71,6 @@ public class AccountEntity implements Serializable, Account { 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; @@ -142,43 +136,30 @@ public class AccountEntity implements Serializable, Account { private List applicationRoleList; @OneToMany(cascade = CascadeType.ALL, mappedBy = "accountId", fetch = FetchType.LAZY) private List accountHistoryList; + @OneToOne(cascade = CascadeType.ALL, mappedBy = "account") + private AccountLoginEntity accountLogin; public AccountEntity() { + // empty constructor required for JPA } - public AccountEntity(UUID id) { - this.id = id; - } - - public AccountEntity (String name) { - this.username = name; + @Override + public String getUsername() { + if (accountLogin == null) { + return null; + } else { + return accountLogin.getUsername(); + } } - public AccountEntity(UUID id, String username, String emailaddress, String firstname, String lastname, String accountPassword, int failureCount, String status, boolean passwordResetOngoing, Date createdOn, String createdBy, Date lastUpdatedOn, String lastUpdatedBy) { - this.id = id; - this.username = username; - this.emailaddress = emailaddress; - this.firstname = firstname; - this.lastname = lastname; - this.accountPassword = accountPassword; - this.failureCount = failureCount; - this.status = status; - this.passwordResetOngoing = passwordResetOngoing; - this.createdOn = createdOn; - this.createdBy = createdBy; - this.lastUpdatedOn = lastUpdatedOn; - this.lastUpdatedBy = lastUpdatedBy; - } - public void addApplicationRole(ApplicationRoleEntity applicationRole) { if (applicationRoleList == null) { applicationRoleList = new ArrayList<>(); } - applicationRoleList.add (applicationRole); + applicationRoleList.add(applicationRole); } - - /* **** getter / setter **** */ + /* **** getter / setter **** */ public UUID getId() { return id; } @@ -187,23 +168,6 @@ public class AccountEntity implements Serializable, Account { this.id = id; } - @Override - 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 String getFirstname() { return firstname; @@ -361,4 +325,21 @@ public class AccountEntity implements Serializable, Account { 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 getConfigEntityList() { + return configEntityList; + } + + public void setConfigEntityList(List configEntityList) { + this.configEntityList = configEntityList; + } + } diff --git a/account/src/main/java/de/muehlencord/shared/account/business/account/entity/AccountLoginEntity.java b/account/src/main/java/de/muehlencord/shared/account/business/account/entity/AccountLoginEntity.java new file mode 100644 index 0000000..b4f32eb --- /dev/null +++ b/account/src/main/java/de/muehlencord/shared/account/business/account/entity/AccountLoginEntity.java @@ -0,0 +1,270 @@ +/* + * 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 + " ]"; + } + +} diff --git a/account/src/main/java/de/muehlencord/shared/account/business/accountcounfig/entity/AccountConfigurationKey.java b/account/src/main/java/de/muehlencord/shared/account/business/accountconfig/entity/AccountConfigurationKey.java similarity index 83% rename from account/src/main/java/de/muehlencord/shared/account/business/accountcounfig/entity/AccountConfigurationKey.java rename to account/src/main/java/de/muehlencord/shared/account/business/accountconfig/entity/AccountConfigurationKey.java index 03af1b4..0877822 100644 --- a/account/src/main/java/de/muehlencord/shared/account/business/accountcounfig/entity/AccountConfigurationKey.java +++ b/account/src/main/java/de/muehlencord/shared/account/business/accountconfig/entity/AccountConfigurationKey.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package de.muehlencord.shared.account.business.accountcounfig.entity; +package de.muehlencord.shared.account.business.accountconfig.entity; /** * diff --git a/account/src/main/java/de/muehlencord/shared/account/business/accountcounfig/entity/AccountConfigurationValue.java b/account/src/main/java/de/muehlencord/shared/account/business/accountconfig/entity/AccountConfigurationValue.java similarity index 87% rename from account/src/main/java/de/muehlencord/shared/account/business/accountcounfig/entity/AccountConfigurationValue.java rename to account/src/main/java/de/muehlencord/shared/account/business/accountconfig/entity/AccountConfigurationValue.java index cb1c455..4052f5b 100644 --- a/account/src/main/java/de/muehlencord/shared/account/business/accountcounfig/entity/AccountConfigurationValue.java +++ b/account/src/main/java/de/muehlencord/shared/account/business/accountconfig/entity/AccountConfigurationValue.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package de.muehlencord.shared.account.business.accountcounfig.entity; +package de.muehlencord.shared.account.business.accountconfig.entity; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/account/src/main/java/de/muehlencord/shared/account/business/application/entity/ApplicationEntity.java b/account/src/main/java/de/muehlencord/shared/account/business/application/entity/ApplicationEntity.java index b5c5ef2..d1a4d53 100644 --- a/account/src/main/java/de/muehlencord/shared/account/business/application/entity/ApplicationEntity.java +++ b/account/src/main/java/de/muehlencord/shared/account/business/application/entity/ApplicationEntity.java @@ -2,6 +2,7 @@ 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; @@ -53,7 +54,9 @@ public class ApplicationEntity implements Serializable { private List applicationRoleEntityList; @OneToMany(cascade = CascadeType.ALL, mappedBy = "application") private List applicationPermissions; - + @OneToMany(cascade = CascadeType.ALL, mappedBy = "application") + private List configItems; + public ApplicationEntity() { } @@ -116,4 +119,13 @@ public class ApplicationEntity implements Serializable { this.applicationPermissions = applicationPermissions; } + @XmlTransient + public List getConfigItems() { + return configItems; + } + + public void setConfigItems(List configItems) { + this.configItems = configItems; + } + } diff --git a/account/src/main/java/de/muehlencord/shared/account/business/config/boundary/ConfigService.java b/account/src/main/java/de/muehlencord/shared/account/business/config/boundary/ConfigService.java index b37fb3f..c3e44ca 100644 --- a/account/src/main/java/de/muehlencord/shared/account/business/config/boundary/ConfigService.java +++ b/account/src/main/java/de/muehlencord/shared/account/business/config/boundary/ConfigService.java @@ -2,6 +2,7 @@ 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; @@ -62,8 +63,9 @@ public class ConfigService implements Serializable { * 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 { + public String getConfigValue(ApplicationEntity application, String configKey) throws ConfigException { Query query = em.createNamedQuery("ConfigEntity.findByConfigKey"); + query.setParameter ("application", application); query.setParameter("configKey", configKey); List configList = query.getResultList(); if ((configList == null) || (configList.isEmpty())) { @@ -86,13 +88,13 @@ public class ConfigService implements Serializable { } } - public String getConfigValue(String configKey, String defaultValue) throws ConfigException { - return getConfigValue(configKey, defaultValue, false); + public String getConfigValue(ApplicationEntity application, String configKey, String defaultValue) throws ConfigException { + return getConfigValue(application, configKey, defaultValue, false); } - public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue) throws ConfigException { + public String getConfigValue(ApplicationEntity application, String configKey, String defaultValue, boolean storeDefaultValue) throws ConfigException { // get configValue as usual - String configValue = getConfigValue(configKey); + 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 @@ -103,13 +105,13 @@ public class ConfigService implements Serializable { // check if the default value should be stored in the database if (storeDefaultValue) { AccountEntity account = getAccount("system"); - updateConfigValue(configKey, account, configValue); + updateConfigValue(application, configKey, account, configValue); } return defaultValue; } - public String getConfigValue(String configKey, Account account, boolean fallbackToSystem) throws ConfigException { + 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); @@ -117,7 +119,7 @@ public class ConfigService implements Serializable { if ((configList == null) || (configList.isEmpty())) { // fallback to default / system value if (fallbackToSystem) { - return getConfigValue(configKey); + return getConfigValue(application, configKey); } else { return null; } @@ -130,8 +132,8 @@ public class ConfigService implements Serializable { } } - public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue, Account account, boolean fallbackToSystem) throws ConfigException { - String configValue = getConfigValue(configKey, account, fallbackToSystem); + 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 @@ -140,7 +142,7 @@ public class ConfigService implements Serializable { // check if the default value should be stored in the database if (storeDefaultValue) { - updateConfigValue(configKey, account, configValue); + updateConfigValue(application, configKey, account, configValue); } return configValue; @@ -148,14 +150,14 @@ public class ConfigService implements Serializable { @Transactional @Lock(LockType.WRITE) - public boolean updateConfigValue(String configKey, String configValue) throws ConfigException { + public boolean updateConfigValue(ApplicationEntity application,String configKey, String configValue) throws ConfigException { Account account = getAccount("system"); - return updateConfigValue(configKey, account, configValue); + return updateConfigValue(application, configKey, account, configValue); } @Transactional @Lock(LockType.WRITE) - public boolean updateConfigValue(String configKey, String accountName, String configValue) { + public boolean updateConfigValue(ApplicationEntity application,String configKey, String accountName, String configValue) { Account account = getAccount(accountName); if (accountName == null) { return false; @@ -164,12 +166,12 @@ public class ConfigService implements Serializable { LOGGER.error("Account for usreName {} not found", accountName); return false; } - return updateConfigValue(configKey, account, configValue); + return updateConfigValue(application, configKey, account, configValue); } @Transactional @Lock(LockType.WRITE) - public boolean updateConfigValue(String configKey, Account account, String configValue) { + 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; @@ -181,7 +183,7 @@ public class ConfigService implements Serializable { } AccountEntity accountEntity = getAccount (account.getUsername()); - ConfigEntityPK pk = new ConfigEntityPK(configKey, accountEntity); + ConfigEntityPK pk = new ConfigEntityPK(application, configKey, accountEntity); ConfigEntity currentEntity = em.find(ConfigEntity.class, pk); if (currentEntity == null) { currentEntity = new ConfigEntity(pk); diff --git a/account/src/main/java/de/muehlencord/shared/account/business/config/entity/ConfigEntity.java b/account/src/main/java/de/muehlencord/shared/account/business/config/entity/ConfigEntity.java index 2254c75..0e50f11 100644 --- a/account/src/main/java/de/muehlencord/shared/account/business/config/entity/ConfigEntity.java +++ b/account/src/main/java/de/muehlencord/shared/account/business/config/entity/ConfigEntity.java @@ -6,11 +6,14 @@ 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; @@ -34,15 +37,15 @@ import org.hibernate.annotations.CacheConcurrencyStrategy; 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.configKey = :configKey", + @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.configKey = :configKey AND c.configPK.configKeyAccount = :account", + @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.configValue = :configValue", + @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")}) @@ -59,13 +62,13 @@ public class ConfigEntity implements Serializable { private String configValue; @Size(max = 200) @Column(name = "config_key_group") - private String configKeyGroup; + private String configKeyGroup; public ConfigEntity() { } - public ConfigEntity(String configKey, AccountEntity account) { - this.configPK = new ConfigEntityPK(configKey, account); + public ConfigEntity(ApplicationEntity application, String configKey, AccountEntity account) { + this.configPK = new ConfigEntityPK(application, configKey, account); } public ConfigEntity(ConfigEntityPK configPK) { @@ -95,7 +98,7 @@ public class ConfigEntity implements Serializable { public void setConfigKeyGroup(String configKeyGroup) { this.configKeyGroup = configKeyGroup; } - + @Override public int hashCode() { int hash = 0; diff --git a/account/src/main/java/de/muehlencord/shared/account/business/config/entity/ConfigEntityPK.java b/account/src/main/java/de/muehlencord/shared/account/business/config/entity/ConfigEntityPK.java index cf13fb2..e76433a 100644 --- a/account/src/main/java/de/muehlencord/shared/account/business/config/entity/ConfigEntityPK.java +++ b/account/src/main/java/de/muehlencord/shared/account/business/config/entity/ConfigEntityPK.java @@ -6,6 +6,7 @@ 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.Basic; import javax.persistence.Column; @@ -23,20 +24,25 @@ import javax.validation.constraints.Size; public class ConfigEntityPK implements Serializable { private static final long serialVersionUID = 8133795368429249008L; - + @Basic(optional = false) @NotNull @Size(min = 1, max = 100) @Column(name = "config_key") private String configKey; - @JoinColumn(name = "config_key_account", referencedColumnName = "id") + @JoinColumn(name = "config_key_account", referencedColumnName = "id", insertable = false, updatable = false) @ManyToOne(optional = false) private AccountEntity configKeyAccount; + @JoinColumn(name = "application", referencedColumnName = "id", insertable = false, updatable = false) + @ManyToOne(optional = false) + private ApplicationEntity application; public ConfigEntityPK() { + // empty constructor required for JPA } - public ConfigEntityPK(String configKey, AccountEntity configKeyAccount) { + public ConfigEntityPK(ApplicationEntity application, String configKey, AccountEntity configKeyAccount) { + this.application = application; this.configKey = configKey; this.configKeyAccount = configKeyAccount; } @@ -57,6 +63,14 @@ public class ConfigEntityPK implements Serializable { this.configKeyAccount = configKeyAccount; } + public ApplicationEntity getApplication() { + return application; + } + + public void setApplication(ApplicationEntity application) { + this.application = application; + } + @Override public int hashCode() { int hash = 0; @@ -85,5 +99,5 @@ public class ConfigEntityPK implements Serializable { public String toString() { return "de.muehlencord.shared.account.business.config.entity.ConfigPK[ configKey=" + configKey + ", configKeyAccount=" + configKeyAccount + " ]"; } - + } diff --git a/account/src/main/java/de/muehlencord/shared/account/business/mail/boundary/MailService.java b/account/src/main/java/de/muehlencord/shared/account/business/mail/boundary/MailService.java index 189acfe..096a26d 100644 --- a/account/src/main/java/de/muehlencord/shared/account/business/mail/boundary/MailService.java +++ b/account/src/main/java/de/muehlencord/shared/account/business/mail/boundary/MailService.java @@ -1,8 +1,9 @@ package de.muehlencord.shared.account.business.mail.boundary; import de.muehlencord.shared.account.business.mail.entity.MailTemplateException; -import de.muehlencord.shared.account.business.accountcounfig.entity.AccountConfigurationKey; +import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationKey; import de.muehlencord.shared.account.business.account.entity.AccountEntity; +import de.muehlencord.shared.account.business.account.entity.AccountLoginEntity; import de.muehlencord.shared.account.business.mail.entity.MailDatamodel; import de.muehlencord.shared.account.business.mail.entity.MailException; import java.util.Date; @@ -22,7 +23,7 @@ import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import de.muehlencord.shared.account.business.accountcounfig.entity.AccountConfigurationValue; +import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationValue; import java.io.File; import java.io.IOException; import java.io.Serializable; @@ -62,7 +63,14 @@ public class MailService implements Serializable { public String sendTestHtmlEmail(String recipient) throws MailException { Date now = new Date(); - AccountEntity account = new AccountEntity(UUID.randomUUID(), "joern.muehlencord", "joern@muehlencord.de", "Jörn", "Mühlencord", "secret", 0, "NEW", false, now, "admin", now, "admin"); + AccountEntity account = new AccountEntity(); + account.setId (UUID.randomUUID()); + account.setFirstname("Jörn"); + account.setLastname ("Mühlencord"); + AccountLoginEntity accountLogin = new AccountLoginEntity(); + accountLogin.setAccountPassword("secret"); + accountLogin.setAccount(account); + account.setAccountLogin(accountLogin); MailDatamodel dataModel = new MailDatamodel(account); dataModel.addParameter("url", "http://url.de"); dataModel.addParameter("resetUrl", "http://reseturl.de"); @@ -181,7 +189,7 @@ public class MailService implements Serializable { String resetUrlWithToken = passwordResetUrl + "?token=" + token; model.addParameter("url", baseUrl); model.addParameter("resetUrl", resetUrlWithToken); - return sendHTMLMail(account.getEmailaddress(), "Reset your password", model, "password_reset_html"); + return sendHTMLMail(account.getAccountLogin().getEmailaddress(), "Reset your password", model, "password_reset_html"); } private String transportMail(Message message) throws MessagingException { diff --git a/account/src/test/java/de/muehlencord/shared/account/business/config/boundary/ConfigServiceTest.java b/account/src/test/java/de/muehlencord/shared/account/business/config/boundary/ConfigServiceTest.java index e37dd6f..534b60f 100644 --- a/account/src/test/java/de/muehlencord/shared/account/business/config/boundary/ConfigServiceTest.java +++ b/account/src/test/java/de/muehlencord/shared/account/business/config/boundary/ConfigServiceTest.java @@ -2,8 +2,11 @@ package de.muehlencord.shared.account.business.config.boundary; import de.muehlencord.shared.account.business.account.entity.AccountEntity; +import de.muehlencord.shared.account.business.account.entity.AccountLoginEntity; +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 java.util.UUID; import javax.persistence.EntityManager; import org.junit.Test; import org.junit.Before; @@ -28,9 +31,18 @@ public class ConfigServiceTest { private EntityManager entityManagerMock; @Before - public void init() { - AccountEntity account = new AccountEntity ("system"); - ConfigEntityPK pk = new ConfigEntityPK("account.maxFailedLogins", account); + public void init() { + ApplicationEntity application = new ApplicationEntity(); + application.setId(UUID.randomUUID()); + application.setApplicationName("Test App"); + + AccountEntity account = new AccountEntity(); + AccountLoginEntity login = new AccountLoginEntity(); + login.setAccount (account); + login.setUsername("system"); + account.setAccountLogin(login); + + ConfigEntityPK pk = new ConfigEntityPK(application, "account.maxFailedLogins", account); ConfigEntity configEntity = new ConfigEntity (pk); configEntity.setConfigValue("7"); when (entityManagerMock.find(ConfigEntity.class, "account.maxFailedLogins")).thenReturn (configEntity);