updated license headers

This commit is contained in:
2018-12-14 10:48:10 +01:00
parent 452ffa4f9d
commit 0b123bec0f
57 changed files with 3642 additions and 2936 deletions

View File

@ -1,41 +1,51 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
*/ * you may not use this file except in compliance with the License.
package de.muehlencord.shared.account.business.account.boundary; * You may obtain a copy of the License at
*
import de.muehlencord.shared.account.util.Permission; * http://www.apache.org/licenses/LICENSE-2.0
*
/** * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* @author Joern Muehlencord <joern at muehlencord.de> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/ * See the License for the specific language governing permissions and
public enum AccountPermissions implements Permission { * limitations under the License.
*/
ACCOUNT_ADD("account:add", "Allow to create a new account"), package de.muehlencord.shared.account.business.account.boundary;
ACCOUNT_EDIT ("account:edit", "Allow to edit an existing account"),
ACCOUNT_DELETE("account:delete", "Allow to delete an existing account"), import de.muehlencord.shared.account.util.Permission;
ACCOUNT_LOGIN_ADD ("account:login:add", "Allow to create a login for a user"),
ACCOUNT_LOGIN_EDIT ("account:login:edit", "Allow to change a login for a user"), /**
ACCOUNT_LOGIN_DELETE ("account:login:delete", "Allow to delete a login for a user"); *
* @author Joern Muehlencord <joern at muehlencord.de>
private final String name; */
private final String description; public enum AccountPermissions implements Permission {
private AccountPermissions(String permissionName, String permissionDesc) { ACCOUNT_ADD("account:add", "Allow to create a new account"),
this.name = permissionName; ACCOUNT_EDIT ("account:edit", "Allow to edit an existing account"),
this.description = permissionDesc; ACCOUNT_DELETE("account:delete", "Allow to delete an existing account"),
} ACCOUNT_LOGIN_ADD ("account:login:add", "Allow to create a login for a user"),
ACCOUNT_LOGIN_EDIT ("account:login:edit", "Allow to change a login for a user"),
@Override ACCOUNT_LOGIN_DELETE ("account:login:delete", "Allow to delete a login for a user");
public String getName() {
return name; private final String name;
} private final String description;
@Override private AccountPermissions(String permissionName, String permissionDesc) {
public String getDescription() { this.name = permissionName;
return description; this.description = permissionDesc;
} }
} @Override
public String getName() {
return name;
}
@Override
public String getDescription() {
return description;
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2017 Joern Muehlencord <joern at muehlencord.de>. * Copyright 2018 joern.muehlencord.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,9 +1,18 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package de.muehlencord.shared.account.business.account.boundary; package de.muehlencord.shared.account.business.account.boundary;
/** /**

View File

@ -1,3 +1,18 @@
/*
* Copyright 2018 joern.muehlencord.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.business.account.boundary; package de.muehlencord.shared.account.business.account.boundary;
import de.muehlencord.shared.account.business.account.control.AccountControl; import de.muehlencord.shared.account.business.account.control.AccountControl;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2018 joern.muehlencord.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.business.account.control; package de.muehlencord.shared.account.business.account.control;
import de.muehlencord.shared.account.business.account.entity.AccountEntity; import de.muehlencord.shared.account.business.account.entity.AccountEntity;

View File

@ -1,18 +1,28 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
*/ * you may not use this file except in compliance with the License.
package de.muehlencord.shared.account.business.account.entity; * You may obtain a copy of the License at
*
/** * http://www.apache.org/licenses/LICENSE-2.0
* *
* @author Joern Muehlencord <joern at muehlencord.de> * Unless required by applicable law or agreed to in writing, software
*/ * distributed under the License is distributed on an "AS IS" BASIS,
public interface Account { * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
String getUsername(); * limitations under the License.
String getFirstname(); */
String getLastname(); package de.muehlencord.shared.account.business.account.entity;
} /**
*
* @author Joern Muehlencord <joern at muehlencord.de>
*/
public interface Account {
String getUsername();
String getFirstname();
String getLastname();
}

View File

@ -1,265 +1,280 @@
package de.muehlencord.shared.account.business.account.entity; /*
* Copyright 2018 joern.muehlencord.
import de.muehlencord.shared.account.business.application.entity.ApplicationRoleEntity; *
import de.muehlencord.shared.account.business.config.entity.ConfigEntity; * Licensed under the Apache License, Version 2.0 (the "License");
import java.io.Serializable; * you may not use this file except in compliance with the License.
import java.util.ArrayList; * You may obtain a copy of the License at
import java.util.Date; *
import java.util.List; * http://www.apache.org/licenses/LICENSE-2.0
import java.util.UUID; *
import javax.persistence.Basic; * Unless required by applicable law or agreed to in writing, software
import javax.persistence.CascadeType; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.persistence.Column; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.persistence.Entity; * See the License for the specific language governing permissions and
import javax.persistence.FetchType; * limitations under the License.
import javax.persistence.GeneratedValue; */
import javax.persistence.Id; package de.muehlencord.shared.account.business.account.entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable; import de.muehlencord.shared.account.business.application.entity.ApplicationRoleEntity;
import javax.persistence.ManyToMany; import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
import javax.persistence.NamedQueries; import java.io.Serializable;
import javax.persistence.NamedQuery; import java.util.ArrayList;
import javax.persistence.OneToMany; import java.util.Date;
import javax.persistence.OneToOne; import java.util.List;
import javax.persistence.Table; import java.util.UUID;
import javax.persistence.Temporal; import javax.persistence.Basic;
import javax.persistence.TemporalType; import javax.persistence.CascadeType;
import javax.validation.constraints.NotNull; import javax.persistence.Column;
import javax.validation.constraints.Size; import javax.persistence.Entity;
import javax.xml.bind.annotation.XmlRootElement; import javax.persistence.FetchType;
import org.hibernate.annotations.GenericGenerator; import javax.persistence.GeneratedValue;
import org.hibernate.annotations.Type; import javax.persistence.Id;
import javax.persistence.JoinColumn;
/** import javax.persistence.JoinTable;
* import javax.persistence.ManyToMany;
* @author joern.muehlencord import javax.persistence.NamedQueries;
*/ import javax.persistence.NamedQuery;
@Entity import javax.persistence.OneToMany;
@Table(name = "account") import javax.persistence.OneToOne;
@XmlRootElement import javax.persistence.Table;
@NamedQueries({ import javax.persistence.Temporal;
@NamedQuery(name = "AccountEntity.findAll", query = "SELECT a FROM AccountEntity a ORDER by a.lastname, a.firstname"), import javax.persistence.TemporalType;
@NamedQuery(name = "AccountEntity.findByUsername", query = "SELECT a FROM AccountEntity a WHERE a.username = :username"), import javax.validation.constraints.NotNull;
@NamedQuery(name = "AccountEntity.findByStatus", query = "SELECT a FROM AccountEntity a WHERE a.status = :status"), import javax.validation.constraints.Size;
@NamedQuery(name = "AccountEntity.findByCreatedOn", query = "SELECT a FROM AccountEntity a WHERE a.createdOn = :createdOn"), import javax.xml.bind.annotation.XmlRootElement;
@NamedQuery(name = "AccountEntity.findByCreatedBy", query = "SELECT a FROM AccountEntity a WHERE a.createdBy = :createdBy"), import org.hibernate.annotations.GenericGenerator;
@NamedQuery(name = "AccountEntity.findByLastUpdatedOn", query = "SELECT a FROM AccountEntity a WHERE a.lastUpdatedOn = :lastUpdatedOn"), 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 { /**
*
private static final long serialVersionUID = 6216991757526150935L; * @author joern.muehlencord
*/
@Id @Entity
@Basic(optional = false) @Table(name = "account")
@NotNull @XmlRootElement
@Column(name = "id") @NamedQueries({
@GeneratedValue(generator = "uuid2") @NamedQuery(name = "AccountEntity.findAll", query = "SELECT a FROM AccountEntity a ORDER by a.lastname, a.firstname"),
@GenericGenerator(name = "uuid2", strategy = "uuid2") @NamedQuery(name = "AccountEntity.findByUsername", query = "SELECT a FROM AccountEntity a WHERE a.username = :username"),
@Type(type = "pg-uuid") @NamedQuery(name = "AccountEntity.findByStatus", query = "SELECT a FROM AccountEntity a WHERE a.status = :status"),
private UUID id; @NamedQuery(name = "AccountEntity.findByCreatedOn", query = "SELECT a FROM AccountEntity a WHERE a.createdOn = :createdOn"),
@Basic(optional = false) @NamedQuery(name = "AccountEntity.findByCreatedBy", query = "SELECT a FROM AccountEntity a WHERE a.createdBy = :createdBy"),
@NotNull @NamedQuery(name = "AccountEntity.findByLastUpdatedOn", query = "SELECT a FROM AccountEntity a WHERE a.lastUpdatedOn = :lastUpdatedOn"),
@Size(min = 1, max = 32) @NamedQuery(name = "AccountEntity.findByLastUpdatedBy", query = "SELECT a FROM AccountEntity a WHERE a.lastUpdatedBy = :lastUpdatedBy")})
@Column(name = "username") public class AccountEntity implements Serializable, Account {
private String username;
@Basic(optional = false) private static final long serialVersionUID = 6216991757526150935L;
@NotNull
@Size(min = 1, max = 200) @Id
@Column(name = "emailaddress") @Basic(optional = false)
private String emailaddress; @NotNull
@Basic(optional = false) @Column(name = "id")
@NotNull @GeneratedValue(generator = "uuid2")
@Size(min = 1, max = 100) @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "firstname") @Type(type = "pg-uuid")
private String firstname; private UUID id;
@Basic(optional = false) @Basic(optional = false)
@NotNull @NotNull
@Size(min = 1, max = 100) @Size(min = 1, max = 32)
@Column(name = "lastname") @Column(name = "username")
private String lastname; private String username;
@Basic(optional = false) @Basic(optional = false)
@NotNull @NotNull
@Size(min = 1, max = 10) @Size(min = 1, max = 200)
@Column(name = "status") @Column(name = "emailaddress")
private String status; private String emailaddress;
@Basic(optional = false) @Basic(optional = false)
@NotNull @NotNull
@Column(name = "created_on") @Size(min = 1, max = 100)
@Temporal(TemporalType.TIMESTAMP) @Column(name = "firstname")
private Date createdOn; private String firstname;
@Basic(optional = false) @Basic(optional = false)
@NotNull @NotNull
@Size(min = 1, max = 32) @Size(min = 1, max = 100)
@Column(name = "created_by") @Column(name = "lastname")
private String createdBy; private String lastname;
@Basic(optional = false) @Basic(optional = false)
@NotNull @NotNull
@Column(name = "last_updated_on") @Size(min = 1, max = 10)
@Temporal(TemporalType.TIMESTAMP) @Column(name = "status")
private Date lastUpdatedOn; private String status;
@Basic(optional = false) @Basic(optional = false)
@NotNull @NotNull
@Size(min = 1, max = 32) @Column(name = "created_on")
@Column(name = "last_updated_by") @Temporal(TemporalType.TIMESTAMP)
private String lastUpdatedBy; private Date createdOn;
@JoinTable(name = "account_role", joinColumns = { @Basic(optional = false)
@JoinColumn(name = "account", referencedColumnName = "id")}, inverseJoinColumns = { @NotNull
@JoinColumn(name = "account_role", referencedColumnName = "id")}) @Size(min = 1, max = 32)
@ManyToMany(fetch = FetchType.LAZY) @Column(name = "created_by")
private List<ApplicationRoleEntity> applicationRoleList; private String createdBy;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "accountId", fetch = FetchType.LAZY) @Basic(optional = false)
private List<AccountHistoryEntity> accountHistoryList; @NotNull
@OneToOne(cascade = CascadeType.ALL, mappedBy = "account") @Column(name = "last_updated_on")
private AccountLoginEntity accountLogin; @Temporal(TemporalType.TIMESTAMP)
@OneToMany(cascade = CascadeType.ALL, mappedBy = "account") private Date lastUpdatedOn;
private List<ConfigEntity> configItems; @Basic(optional = false)
@NotNull
public AccountEntity() { @Size(min = 1, max = 32)
// empty constructor required for JPA @Column(name = "last_updated_by")
} private String lastUpdatedBy;
@JoinTable(name = "account_role", joinColumns = {
public void addApplicationRole(ApplicationRoleEntity applicationRole) { @JoinColumn(name = "account", referencedColumnName = "id")}, inverseJoinColumns = {
if (applicationRoleList == null) { @JoinColumn(name = "account_role", referencedColumnName = "id")})
applicationRoleList = new ArrayList<>(); @ManyToMany(fetch = FetchType.LAZY)
} private List<ApplicationRoleEntity> applicationRoleList;
applicationRoleList.add(applicationRole); @OneToMany(cascade = CascadeType.ALL, mappedBy = "accountId", fetch = FetchType.LAZY)
} private List<AccountHistoryEntity> accountHistoryList;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "account")
/* **** getter / setter **** */ private AccountLoginEntity accountLogin;
public UUID getId() { @OneToMany(cascade = CascadeType.ALL, mappedBy = "account")
return id; private List<ConfigEntity> configItems;
}
public AccountEntity() {
public void setId(UUID id) { // empty constructor required for JPA
this.id = id; }
}
public void addApplicationRole(ApplicationRoleEntity applicationRole) {
public String getUsername() { if (applicationRoleList == null) {
return username; applicationRoleList = new ArrayList<>();
} }
applicationRoleList.add(applicationRole);
public void setUsername(String username) { }
this.username = username;
} /* **** getter / setter **** */
public UUID getId() {
public String getEmailaddress() { return id;
return emailaddress; }
}
public void setId(UUID id) {
public void setEmailaddress(String emailaddress) { this.id = id;
this.emailaddress = emailaddress; }
}
public String getUsername() {
public String getFirstname() { return username;
return firstname; }
}
public void setUsername(String username) {
public void setFirstname(String firstname) { this.username = username;
this.firstname = firstname; }
}
public String getEmailaddress() {
public String getLastname() { return emailaddress;
return lastname; }
}
public void setEmailaddress(String emailaddress) {
public void setLastname(String lastname) { this.emailaddress = emailaddress;
this.lastname = lastname; }
}
public String getFirstname() {
public String getStatus() { return firstname;
return status; }
}
public void setFirstname(String firstname) {
public void setStatus(String status) { this.firstname = firstname;
this.status = status; }
}
public String getLastname() {
public Date getCreatedOn() { return lastname;
return createdOn; }
}
public void setLastname(String lastname) {
public void setCreatedOn(Date createdOn) { this.lastname = lastname;
this.createdOn = createdOn; }
}
public String getStatus() {
public String getCreatedBy() { return status;
return createdBy; }
}
public void setStatus(String status) {
public void setCreatedBy(String createdBy) { this.status = status;
this.createdBy = createdBy; }
}
public Date getCreatedOn() {
public Date getLastUpdatedOn() { return createdOn;
return lastUpdatedOn; }
}
public void setCreatedOn(Date createdOn) {
public void setLastUpdatedOn(Date lastUpdatedOn) { this.createdOn = createdOn;
this.lastUpdatedOn = lastUpdatedOn; }
}
public String getCreatedBy() {
public String getLastUpdatedBy() { return createdBy;
return lastUpdatedBy; }
}
public void setCreatedBy(String createdBy) {
public void setLastUpdatedBy(String lastUpdatedBy) { this.createdBy = createdBy;
this.lastUpdatedBy = lastUpdatedBy; }
}
public Date getLastUpdatedOn() {
public List<ApplicationRoleEntity> getApplicationRoleList() { return lastUpdatedOn;
return applicationRoleList; }
}
public void setLastUpdatedOn(Date lastUpdatedOn) {
public void setApplicationRoleList(List<ApplicationRoleEntity> applicationRoleList) { this.lastUpdatedOn = lastUpdatedOn;
this.applicationRoleList = applicationRoleList; }
}
public String getLastUpdatedBy() {
public List<AccountHistoryEntity> getAccountHistoryList() { return lastUpdatedBy;
return accountHistoryList; }
}
public void setLastUpdatedBy(String lastUpdatedBy) {
public void setAccountHistoryList(List<AccountHistoryEntity> accountHistoryList) { this.lastUpdatedBy = lastUpdatedBy;
this.accountHistoryList = accountHistoryList; }
}
public List<ApplicationRoleEntity> getApplicationRoleList() {
public AccountLoginEntity getAccountLogin() { return applicationRoleList;
return accountLogin; }
}
public void setApplicationRoleList(List<ApplicationRoleEntity> applicationRoleList) {
public void setAccountLogin(AccountLoginEntity accountLogin) { this.applicationRoleList = applicationRoleList;
this.accountLogin = accountLogin; }
}
public List<AccountHistoryEntity> getAccountHistoryList() {
public List<ConfigEntity> getConfigItems() { return accountHistoryList;
return configItems; }
}
public void setAccountHistoryList(List<AccountHistoryEntity> accountHistoryList) {
public void setConfigItems(List<ConfigEntity> configItems) { this.accountHistoryList = accountHistoryList;
this.configItems = configItems; }
}
public AccountLoginEntity getAccountLogin() {
@Override return accountLogin;
public int hashCode() { }
int hash = 0;
hash += (id != null ? id.hashCode() : 0); public void setAccountLogin(AccountLoginEntity accountLogin) {
return hash; this.accountLogin = accountLogin;
} }
@Override public List<ConfigEntity> getConfigItems() {
public boolean equals(Object object) { return configItems;
// TODO: Warning - this method won't work in the case the id fields are not set }
if (!(object instanceof AccountEntity)) {
return false; public void setConfigItems(List<ConfigEntity> configItems) {
} this.configItems = configItems;
AccountEntity other = (AccountEntity) object; }
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false; @Override
} public int hashCode() {
return true; int hash = 0;
} hash += (id != null ? id.hashCode() : 0);
return hash;
@Override }
public String toString() {
return "de.muehlencord.shared.account.entity.Account[ id=" + id + " ]"; @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 + " ]";
}
}

View File

@ -1,29 +1,44 @@
package de.muehlencord.shared.account.business.account.entity; /*
* Copyright 2018 joern.muehlencord.
/** *
* * Licensed under the Apache License, Version 2.0 (the "License");
* @author Raimund * you may not use this file except in compliance with the License.
*/ * You may obtain a copy of the License at
public class AccountException extends Exception { *
* http://www.apache.org/licenses/LICENSE-2.0
/** *
* Creates a new instance of <code>AccountException</code> without detail * Unless required by applicable law or agreed to in writing, software
* message. * distributed under the License is distributed on an "AS IS" BASIS,
*/ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
public AccountException() { * See the License for the specific language governing permissions and
} * limitations under the License.
*/
/** package de.muehlencord.shared.account.business.account.entity;
* Constructs an instance of <code>AccountException</code> with the
* specified detail message. /**
* *
* @param msg the detail message. * @author Raimund
*/ */
public AccountException(String msg) { public class AccountException extends Exception {
super(msg);
} /**
* Creates a new instance of <code>AccountException</code> without detail
public AccountException(String entity_updated__deleted_please_reload, boolean b) { * message.
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. */
} public AccountException() {
} }
/**
* Constructs an instance of <code>AccountException</code> with the
* specified detail message.
*
* @param msg the detail message.
*/
public AccountException(String msg) {
super(msg);
}
public AccountException(String entity_updated__deleted_please_reload, boolean b) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -1,172 +1,187 @@
package de.muehlencord.shared.account.business.account.entity; /*
* Copyright 2018 joern.muehlencord.
import java.io.Serializable; *
import java.util.Date; * Licensed under the Apache License, Version 2.0 (the "License");
import java.util.UUID; * you may not use this file except in compliance with the License.
import javax.persistence.Basic; * You may obtain a copy of the License at
import javax.persistence.Column; *
import javax.persistence.Entity; * http://www.apache.org/licenses/LICENSE-2.0
import javax.persistence.GeneratedValue; *
import javax.persistence.Id; * Unless required by applicable law or agreed to in writing, software
import javax.persistence.JoinColumn; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.persistence.ManyToOne; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.persistence.NamedQueries; * See the License for the specific language governing permissions and
import javax.persistence.NamedQuery; * limitations under the License.
import javax.persistence.Table; */
import javax.persistence.Temporal; package de.muehlencord.shared.account.business.account.entity;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull; import java.io.Serializable;
import javax.validation.constraints.Size; import java.util.Date;
import javax.xml.bind.annotation.XmlRootElement; import java.util.UUID;
import org.hibernate.annotations.GenericGenerator; import javax.persistence.Basic;
import org.hibernate.annotations.Type; import javax.persistence.Column;
import javax.persistence.Entity;
/** import javax.persistence.GeneratedValue;
* import javax.persistence.Id;
* @author joern.muehlencord import javax.persistence.JoinColumn;
*/ import javax.persistence.ManyToOne;
@Entity import javax.persistence.NamedQueries;
@Table(name = "account_history") import javax.persistence.NamedQuery;
@XmlRootElement import javax.persistence.Table;
@NamedQueries({ import javax.persistence.Temporal;
@NamedQuery(name = "AccountHistoryEntity.findAll", query = "SELECT a FROM AccountHistoryEntity a"), import javax.persistence.TemporalType;
@NamedQuery(name = "AccountHistoryEntity.findById", query = "SELECT a FROM AccountHistoryEntity a WHERE a.id = :id"), import javax.validation.constraints.NotNull;
@NamedQuery(name = "AccountHistoryEntity.findByMessage", query = "SELECT a FROM AccountHistoryEntity a WHERE a.message = :message"), import javax.validation.constraints.Size;
@NamedQuery(name = "AccountHistoryEntity.findByFailureCount", query = "SELECT a FROM AccountHistoryEntity a WHERE a.failureCount = :failureCount"), import javax.xml.bind.annotation.XmlRootElement;
@NamedQuery(name = "AccountHistoryEntity.findByStatus", query = "SELECT a FROM AccountHistoryEntity a WHERE a.status = :status"), import org.hibernate.annotations.GenericGenerator;
@NamedQuery(name = "AccountHistoryEntity.findByLastUpdatedOn", query = "SELECT a FROM AccountHistoryEntity a WHERE a.lastUpdatedOn = :lastUpdatedOn"), import org.hibernate.annotations.Type;
@NamedQuery(name = "AccountHistoryEntity.findByLastUpdatedBy", query = "SELECT a FROM AccountHistoryEntity a WHERE a.lastUpdatedBy = :lastUpdatedBy")})
public class AccountHistoryEntity implements Serializable { /**
*
private static final long serialVersionUID = 1L; * @author joern.muehlencord
@Id */
@Basic(optional = false) @Entity
@NotNull @Table(name = "account_history")
@Column(name = "id") @XmlRootElement
@GeneratedValue(generator = "uuid2") @NamedQueries({
@GenericGenerator(name = "uuid2", strategy = "uuid2") @NamedQuery(name = "AccountHistoryEntity.findAll", query = "SELECT a FROM AccountHistoryEntity a"),
@Type(type = "pg-uuid") @NamedQuery(name = "AccountHistoryEntity.findById", query = "SELECT a FROM AccountHistoryEntity a WHERE a.id = :id"),
private UUID id; @NamedQuery(name = "AccountHistoryEntity.findByMessage", query = "SELECT a FROM AccountHistoryEntity a WHERE a.message = :message"),
@Size(max = 200) @NamedQuery(name = "AccountHistoryEntity.findByFailureCount", query = "SELECT a FROM AccountHistoryEntity a WHERE a.failureCount = :failureCount"),
@Column(name = "message") @NamedQuery(name = "AccountHistoryEntity.findByStatus", query = "SELECT a FROM AccountHistoryEntity a WHERE a.status = :status"),
private String message; @NamedQuery(name = "AccountHistoryEntity.findByLastUpdatedOn", query = "SELECT a FROM AccountHistoryEntity a WHERE a.lastUpdatedOn = :lastUpdatedOn"),
@Basic(optional = false) @NamedQuery(name = "AccountHistoryEntity.findByLastUpdatedBy", query = "SELECT a FROM AccountHistoryEntity a WHERE a.lastUpdatedBy = :lastUpdatedBy")})
@NotNull public class AccountHistoryEntity implements Serializable {
@Column(name = "failure_count")
private int failureCount; private static final long serialVersionUID = 1L;
@Basic(optional = false) @Id
@NotNull @Basic(optional = false)
@Size(min = 1, max = 20) @NotNull
@Column(name = "status") @Column(name = "id")
private String status; @GeneratedValue(generator = "uuid2")
@Basic(optional = false) @GenericGenerator(name = "uuid2", strategy = "uuid2")
@NotNull @Type(type = "pg-uuid")
@Column(name = "last_updated_on") private UUID id;
@Temporal(TemporalType.TIMESTAMP) @Size(max = 200)
private Date lastUpdatedOn; @Column(name = "message")
@Basic(optional = false) private String message;
@NotNull @Basic(optional = false)
@Size(min = 1, max = 32) @NotNull
@Column(name = "last_updated_by") @Column(name = "failure_count")
private String lastUpdatedBy; private int failureCount;
@JoinColumn(name = "account_id", referencedColumnName = "id") @Basic(optional = false)
@ManyToOne(optional = false) @NotNull
private AccountEntity accountId; @Size(min = 1, max = 20)
@Column(name = "status")
public AccountHistoryEntity() { private String status;
} @Basic(optional = false)
@NotNull
public AccountHistoryEntity(UUID id) { @Column(name = "last_updated_on")
this.id = id; @Temporal(TemporalType.TIMESTAMP)
} private Date lastUpdatedOn;
@Basic(optional = false)
public AccountHistoryEntity(UUID id, int failureCount, String status, Date lastUpdatedOn, String lastUpdatedBy) { @NotNull
this.id = id; @Size(min = 1, max = 32)
this.failureCount = failureCount; @Column(name = "last_updated_by")
this.status = status; private String lastUpdatedBy;
this.lastUpdatedOn = lastUpdatedOn; @JoinColumn(name = "account_id", referencedColumnName = "id")
this.lastUpdatedBy = lastUpdatedBy; @ManyToOne(optional = false)
} private AccountEntity accountId;
public UUID getId() { public AccountHistoryEntity() {
return id; }
}
public AccountHistoryEntity(UUID id) {
public void setId(UUID id) { this.id = id;
this.id = id; }
}
public AccountHistoryEntity(UUID id, int failureCount, String status, Date lastUpdatedOn, String lastUpdatedBy) {
public String getMessage() { this.id = id;
return message; this.failureCount = failureCount;
} this.status = status;
this.lastUpdatedOn = lastUpdatedOn;
public void setMessage(String message) { this.lastUpdatedBy = lastUpdatedBy;
this.message = message; }
}
public UUID getId() {
public int getFailureCount() { return id;
return failureCount; }
}
public void setId(UUID id) {
public void setFailureCount(int failureCount) { this.id = id;
this.failureCount = failureCount; }
}
public String getMessage() {
public String getStatus() { return message;
return status; }
}
public void setMessage(String message) {
public void setStatus(String status) { this.message = message;
this.status = status; }
}
public int getFailureCount() {
public Date getLastUpdatedOn() { return failureCount;
return lastUpdatedOn; }
}
public void setFailureCount(int failureCount) {
public void setLastUpdatedOn(Date lastUpdatedOn) { this.failureCount = failureCount;
this.lastUpdatedOn = lastUpdatedOn; }
}
public String getStatus() {
public String getLastUpdatedBy() { return status;
return lastUpdatedBy; }
}
public void setStatus(String status) {
public void setLastUpdatedBy(String lastUpdatedBy) { this.status = status;
this.lastUpdatedBy = lastUpdatedBy; }
}
public Date getLastUpdatedOn() {
public AccountEntity getAccountId() { return lastUpdatedOn;
return accountId; }
}
public void setLastUpdatedOn(Date lastUpdatedOn) {
public void setAccountId(AccountEntity accountId) { this.lastUpdatedOn = lastUpdatedOn;
this.accountId = accountId; }
}
public String getLastUpdatedBy() {
@Override return lastUpdatedBy;
public int hashCode() { }
int hash = 0;
hash += (id != null ? id.hashCode() : 0); public void setLastUpdatedBy(String lastUpdatedBy) {
return hash; this.lastUpdatedBy = lastUpdatedBy;
} }
@Override public AccountEntity getAccountId() {
public boolean equals(Object object) { return accountId;
// TODO: Warning - this method won't work in the case the id fields are not set }
if (!(object instanceof AccountHistoryEntity)) {
return false; public void setAccountId(AccountEntity accountId) {
} this.accountId = accountId;
AccountHistoryEntity other = (AccountHistoryEntity) object; }
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false; @Override
} public int hashCode() {
return true; int hash = 0;
} hash += (id != null ? id.hashCode() : 0);
return hash;
@Override }
public String toString() {
return "de.muehlencord.shared.account.entity.AccountHistory[ id=" + id + " ]"; @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 AccountHistoryEntity)) {
return false;
}
AccountHistoryEntity other = (AccountHistoryEntity) 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.AccountHistory[ id=" + id + " ]";
}
}

View File

@ -1,243 +1,253 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
*/ * you may not use this file except in compliance with the License.
package de.muehlencord.shared.account.business.account.entity; * You may obtain a copy of the License at
*
import java.io.Serializable; * http://www.apache.org/licenses/LICENSE-2.0
import java.util.Date; *
import java.util.UUID; * Unless required by applicable law or agreed to in writing, software
import javax.persistence.Basic; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.persistence.Column; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.persistence.Entity; * See the License for the specific language governing permissions and
import javax.persistence.GeneratedValue; * limitations under the License.
import javax.persistence.Id; */
import javax.persistence.JoinColumn; package de.muehlencord.shared.account.business.account.entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import java.io.Serializable;
import javax.persistence.OneToOne; import java.util.Date;
import javax.persistence.Table; import java.util.UUID;
import javax.persistence.Temporal; import javax.persistence.Basic;
import javax.persistence.TemporalType; import javax.persistence.Column;
import javax.validation.constraints.NotNull; import javax.persistence.Entity;
import javax.validation.constraints.Size; import javax.persistence.GeneratedValue;
import javax.xml.bind.annotation.XmlRootElement; import javax.persistence.Id;
import org.hibernate.annotations.GenericGenerator; import javax.persistence.JoinColumn;
import org.hibernate.annotations.Type; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
/** import javax.persistence.OneToOne;
* import javax.persistence.Table;
* @author jomu import javax.persistence.Temporal;
*/ import javax.persistence.TemporalType;
@Entity import javax.validation.constraints.NotNull;
@Table(name = "account_login") import javax.validation.constraints.Size;
@XmlRootElement import javax.xml.bind.annotation.XmlRootElement;
@NamedQueries({ import org.hibernate.annotations.GenericGenerator;
@NamedQuery(name = "AccountLoginEntity.findAll", query = "SELECT a FROM AccountLoginEntity a"), import org.hibernate.annotations.Type;
@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"), * @author jomu
@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"), @Entity
@NamedQuery(name = "AccountLoginEntity.findByPasswordResetHash", query = "SELECT a FROM AccountLoginEntity a WHERE a.passwordResetHash = :passwordResetHash"), @Table(name = "account_login")
@NamedQuery(name = "AccountLoginEntity.findByCreatedOn", query = "SELECT a FROM AccountLoginEntity a WHERE a.createdOn = :createdOn"), @XmlRootElement
@NamedQuery(name = "AccountLoginEntity.findByCreatedBy", query = "SELECT a FROM AccountLoginEntity a WHERE a.createdBy = :createdBy"), @NamedQueries({
@NamedQuery(name = "AccountLoginEntity.findByLastUpdatedOn", query = "SELECT a FROM AccountLoginEntity a WHERE a.lastUpdatedOn = :lastUpdatedOn"), @NamedQuery(name = "AccountLoginEntity.findAll", query = "SELECT a FROM AccountLoginEntity a"),
@NamedQuery(name = "AccountLoginEntity.findByLastUpdatedBy", query = "SELECT a FROM AccountLoginEntity a WHERE a.lastUpdatedBy = :lastUpdatedBy")}) @NamedQuery(name = "AccountLoginEntity.findByAccountPassword", query = "SELECT a FROM AccountLoginEntity a WHERE a.accountPassword = :accountPassword"),
public class AccountLoginEntity implements Serializable { @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"),
private static final long serialVersionUID = -799045989045040077L; @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"),
@Id @NamedQuery(name = "AccountLoginEntity.findByPasswordResetValidTo", query = "SELECT a FROM AccountLoginEntity a WHERE a.passwordResetValidTo = :passwordResetValidTo"),
@Basic(optional = false) @NamedQuery(name = "AccountLoginEntity.findByPasswordResetHash", query = "SELECT a FROM AccountLoginEntity a WHERE a.passwordResetHash = :passwordResetHash"),
@NotNull @NamedQuery(name = "AccountLoginEntity.findByCreatedOn", query = "SELECT a FROM AccountLoginEntity a WHERE a.createdOn = :createdOn"),
@Column(name = "id") @NamedQuery(name = "AccountLoginEntity.findByCreatedBy", query = "SELECT a FROM AccountLoginEntity a WHERE a.createdBy = :createdBy"),
@GeneratedValue(generator = "uuid2") @NamedQuery(name = "AccountLoginEntity.findByLastUpdatedOn", query = "SELECT a FROM AccountLoginEntity a WHERE a.lastUpdatedOn = :lastUpdatedOn"),
@GenericGenerator(name = "uuid2", strategy = "uuid2") @NamedQuery(name = "AccountLoginEntity.findByLastUpdatedBy", query = "SELECT a FROM AccountLoginEntity a WHERE a.lastUpdatedBy = :lastUpdatedBy")})
@Type(type = "pg-uuid") public class AccountLoginEntity implements Serializable {
private UUID id;
@Basic(optional = false) private static final long serialVersionUID = -799045989045040077L;
@NotNull
@Size(min = 1, max = 200) @Id
@Column(name = "account_password") @Basic(optional = false)
private String accountPassword; @NotNull
@Column(name = "last_login") @Column(name = "id")
@Temporal(TemporalType.TIMESTAMP) @GeneratedValue(generator = "uuid2")
private Date lastLogin; @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "last_failed_login") @Type(type = "pg-uuid")
@Temporal(TemporalType.TIMESTAMP) private UUID id;
private Date lastFailedLogin; @Basic(optional = false)
@Basic(optional = false) @NotNull
@NotNull @Size(min = 1, max = 200)
@Column(name = "failure_count") @Column(name = "account_password")
private int failureCount; private String accountPassword;
@Basic(optional = false) @Column(name = "last_login")
@NotNull @Temporal(TemporalType.TIMESTAMP)
@Column(name = "password_reset_ongoing") private Date lastLogin;
private boolean passwordResetOngoing; @Column(name = "last_failed_login")
@Column(name = "password_reset_valid_to") @Temporal(TemporalType.TIMESTAMP)
@Temporal(TemporalType.TIMESTAMP) private Date lastFailedLogin;
private Date passwordResetValidTo; @Basic(optional = false)
@Size(max = 200) @NotNull
@Column(name = "password_reset_hash") @Column(name = "failure_count")
private String passwordResetHash; private int failureCount;
@Basic(optional = false) @Basic(optional = false)
@NotNull @NotNull
@Column(name = "created_on") @Column(name = "password_reset_ongoing")
@Temporal(TemporalType.TIMESTAMP) private boolean passwordResetOngoing;
private Date createdOn; @Column(name = "password_reset_valid_to")
@Basic(optional = false) @Temporal(TemporalType.TIMESTAMP)
@NotNull private Date passwordResetValidTo;
@Size(min = 1, max = 32) @Size(max = 200)
@Column(name = "created_by") @Column(name = "password_reset_hash")
private String createdBy; private String passwordResetHash;
@Basic(optional = false) @Basic(optional = false)
@NotNull @NotNull
@Column(name = "last_updated_on") @Column(name = "created_on")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Date lastUpdatedOn; private Date createdOn;
@Basic(optional = false) @Basic(optional = false)
@NotNull @NotNull
@Size(min = 1, max = 32) @Size(min = 1, max = 32)
@Column(name = "last_updated_by") @Column(name = "created_by")
private String lastUpdatedBy; private String createdBy;
@JoinColumn(name = "account", referencedColumnName = "id") @Basic(optional = false)
@OneToOne(optional = false) @NotNull
private AccountEntity account; @Column(name = "last_updated_on")
@Temporal(TemporalType.TIMESTAMP)
public AccountLoginEntity() { private Date lastUpdatedOn;
} @Basic(optional = false)
@NotNull
@Size(min = 1, max = 32)
public UUID getId() { @Column(name = "last_updated_by")
return id; private String lastUpdatedBy;
} @JoinColumn(name = "account", referencedColumnName = "id")
@OneToOne(optional = false)
public void setId(UUID id) { private AccountEntity account;
this.id = id;
} public AccountLoginEntity() {
}
public String getAccountPassword() {
return accountPassword;
} public UUID getId() {
return id;
public void setAccountPassword(String accountPassword) { }
this.accountPassword = accountPassword;
} public void setId(UUID id) {
this.id = id;
public Date getLastLogin() { }
return lastLogin;
} public String getAccountPassword() {
return accountPassword;
public void setLastLogin(Date lastLogin) { }
this.lastLogin = lastLogin;
} public void setAccountPassword(String accountPassword) {
this.accountPassword = accountPassword;
public Date getLastFailedLogin() { }
return lastFailedLogin;
} public Date getLastLogin() {
return lastLogin;
public void setLastFailedLogin(Date lastFailedLogin) { }
this.lastFailedLogin = lastFailedLogin;
} public void setLastLogin(Date lastLogin) {
this.lastLogin = lastLogin;
public int getFailureCount() { }
return failureCount;
} public Date getLastFailedLogin() {
return lastFailedLogin;
public void setFailureCount(int failureCount) { }
this.failureCount = failureCount;
} public void setLastFailedLogin(Date lastFailedLogin) {
this.lastFailedLogin = lastFailedLogin;
public boolean getPasswordResetOngoing() { }
return passwordResetOngoing;
} public int getFailureCount() {
return failureCount;
public void setPasswordResetOngoing(boolean passwordResetOngoing) { }
this.passwordResetOngoing = passwordResetOngoing;
} public void setFailureCount(int failureCount) {
this.failureCount = failureCount;
public Date getPasswordResetValidTo() { }
return passwordResetValidTo;
} public boolean getPasswordResetOngoing() {
return passwordResetOngoing;
public void setPasswordResetValidTo(Date passwordResetValidTo) { }
this.passwordResetValidTo = passwordResetValidTo;
} public void setPasswordResetOngoing(boolean passwordResetOngoing) {
this.passwordResetOngoing = passwordResetOngoing;
public String getPasswordResetHash() { }
return passwordResetHash;
} public Date getPasswordResetValidTo() {
return passwordResetValidTo;
public void setPasswordResetHash(String passwordResetHash) { }
this.passwordResetHash = passwordResetHash;
} public void setPasswordResetValidTo(Date passwordResetValidTo) {
this.passwordResetValidTo = passwordResetValidTo;
public Date getCreatedOn() { }
return createdOn;
} public String getPasswordResetHash() {
return passwordResetHash;
public void setCreatedOn(Date createdOn) { }
this.createdOn = createdOn;
} public void setPasswordResetHash(String passwordResetHash) {
this.passwordResetHash = passwordResetHash;
public String getCreatedBy() { }
return createdBy;
} public Date getCreatedOn() {
return createdOn;
public void setCreatedBy(String createdBy) { }
this.createdBy = createdBy;
} public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
public Date getLastUpdatedOn() { }
return lastUpdatedOn;
} public String getCreatedBy() {
return createdBy;
public void setLastUpdatedOn(Date lastUpdatedOn) { }
this.lastUpdatedOn = lastUpdatedOn;
} public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
public String getLastUpdatedBy() { }
return lastUpdatedBy;
} public Date getLastUpdatedOn() {
return lastUpdatedOn;
public void setLastUpdatedBy(String lastUpdatedBy) { }
this.lastUpdatedBy = lastUpdatedBy;
} public void setLastUpdatedOn(Date lastUpdatedOn) {
this.lastUpdatedOn = lastUpdatedOn;
public AccountEntity getAccount() { }
return account;
} public String getLastUpdatedBy() {
return lastUpdatedBy;
public void setAccount(AccountEntity account) { }
this.account = account;
} public void setLastUpdatedBy(String lastUpdatedBy) {
this.lastUpdatedBy = lastUpdatedBy;
@Override }
public int hashCode() {
int hash = 0; public AccountEntity getAccount() {
hash += (id != null ? id.hashCode() : 0); return account;
return hash; }
}
public void setAccount(AccountEntity account) {
@Override this.account = account;
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)) { @Override
return false; public int hashCode() {
} int hash = 0;
AccountLoginEntity other = (AccountLoginEntity) object; hash += (id != null ? id.hashCode() : 0);
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return hash;
return false; }
}
return true; @Override
} public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
@Override if (!(object instanceof AccountLoginEntity)) {
public String toString() { return false;
return "de.muehlencord.shared.account.business.account.entity.AccountLoginEntity[ id=" + id + " ]"; }
} 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 + " ]";
}
}

View File

@ -1,3 +1,18 @@
/*
* Copyright 2018 joern.muehlencord.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.business.account.entity; package de.muehlencord.shared.account.business.account.entity;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,134 +1,149 @@
package de.muehlencord.shared.account.business.account.entity; /*
* Copyright 2018 joern.muehlencord.
import java.io.Serializable; *
import java.util.Date; * Licensed under the Apache License, Version 2.0 (the "License");
import java.util.UUID; * you may not use this file except in compliance with the License.
import javax.persistence.Basic; * You may obtain a copy of the License at
import javax.persistence.Column; *
import javax.persistence.Entity; * http://www.apache.org/licenses/LICENSE-2.0
import javax.persistence.GeneratedValue; *
import javax.persistence.Id; * Unless required by applicable law or agreed to in writing, software
import javax.persistence.JoinColumn; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.persistence.ManyToOne; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.persistence.NamedQueries; * See the License for the specific language governing permissions and
import javax.persistence.NamedQuery; * limitations under the License.
import javax.persistence.Table; */
import javax.persistence.Temporal; package de.muehlencord.shared.account.business.account.entity;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull; import java.io.Serializable;
import javax.validation.constraints.Size; import java.util.Date;
import javax.xml.bind.annotation.XmlRootElement; import java.util.UUID;
import org.hibernate.annotations.GenericGenerator; import javax.persistence.Basic;
import org.hibernate.annotations.Type; import javax.persistence.Column;
import javax.persistence.Entity;
/** import javax.persistence.GeneratedValue;
* import javax.persistence.Id;
* @author Joern Muehlencord <joern at muehlencord.de> import javax.persistence.JoinColumn;
*/ import javax.persistence.ManyToOne;
@Entity import javax.persistence.NamedQueries;
@Table(name = "api_key") import javax.persistence.NamedQuery;
@XmlRootElement import javax.persistence.Table;
@NamedQueries({ import javax.persistence.Temporal;
@NamedQuery(name = "ApiKeyEntity.findAll", query = "SELECT a FROM ApiKeyEntity a"), import javax.persistence.TemporalType;
@NamedQuery(name = "ApiKeyEntity.findByApiKey", query = "SELECT a FROM ApiKeyEntity a WHERE a.apiKey = :apiKey"), import javax.validation.constraints.NotNull;
@NamedQuery(name = "ApiKeyEntity.findByIssuedOn", query = "SELECT a FROM ApiKeyEntity a WHERE a.issuedOn = :issuedOn"), import javax.validation.constraints.Size;
@NamedQuery(name = "ApiKeyEntity.findByAccount", query = "SELECT a FROM ApiKeyEntity a WHERE a.account = :account"), import javax.xml.bind.annotation.XmlRootElement;
@NamedQuery(name = "ApiKeyEntity.findByExpiration", query = "SELECT a FROM ApiKeyEntity a WHERE a.expiration = :expiration")}) import org.hibernate.annotations.GenericGenerator;
public class ApiKeyEntity implements Serializable { import org.hibernate.annotations.Type;
private static final long serialVersionUID = -1044658457228215810L; /**
*
@Id * @author Joern Muehlencord <joern at muehlencord.de>
@Basic(optional = false) */
@NotNull @Entity
@Column(name = "id") @Table(name = "api_key")
@GeneratedValue(generator = "uuid2") @XmlRootElement
@GenericGenerator(name = "uuid2", strategy = "uuid2") @NamedQueries({
@Type(type = "pg-uuid") @NamedQuery(name = "ApiKeyEntity.findAll", query = "SELECT a FROM ApiKeyEntity a"),
private UUID id; @NamedQuery(name = "ApiKeyEntity.findByApiKey", query = "SELECT a FROM ApiKeyEntity a WHERE a.apiKey = :apiKey"),
@Basic(optional = false) @NamedQuery(name = "ApiKeyEntity.findByIssuedOn", query = "SELECT a FROM ApiKeyEntity a WHERE a.issuedOn = :issuedOn"),
@NotNull @NamedQuery(name = "ApiKeyEntity.findByAccount", query = "SELECT a FROM ApiKeyEntity a WHERE a.account = :account"),
@Size(min = 1, max = 200) @NamedQuery(name = "ApiKeyEntity.findByExpiration", query = "SELECT a FROM ApiKeyEntity a WHERE a.expiration = :expiration")})
@Column(name = "api_key") public class ApiKeyEntity implements Serializable {
private String apiKey;
@Basic(optional = false) private static final long serialVersionUID = -1044658457228215810L;
@NotNull
@Column(name = "issued_on") @Id
@Temporal(TemporalType.TIMESTAMP) @Basic(optional = false)
private Date issuedOn; @NotNull
@Column(name = "expiration") @Column(name = "id")
private Short expiration; @GeneratedValue(generator = "uuid2")
@JoinColumn(name = "account", referencedColumnName = "id") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@ManyToOne(optional = false) @Type(type = "pg-uuid")
private AccountEntity account; private UUID id;
@Basic(optional = false)
public ApiKeyEntity() { @NotNull
// empty constructor required for JPA @Size(min = 1, max = 200)
} @Column(name = "api_key")
private String apiKey;
public UUID getId() { @Basic(optional = false)
return id; @NotNull
} @Column(name = "issued_on")
@Temporal(TemporalType.TIMESTAMP)
public void setId(UUID id) { private Date issuedOn;
this.id = id; @Column(name = "expiration")
} private Short expiration;
@JoinColumn(name = "account", referencedColumnName = "id")
public String getApiKey() { @ManyToOne(optional = false)
return apiKey; private AccountEntity account;
}
public ApiKeyEntity() {
public void setApiKey(String apiKey) { // empty constructor required for JPA
this.apiKey = apiKey; }
}
public UUID getId() {
public Date getIssuedOn() { return id;
return issuedOn; }
}
public void setId(UUID id) {
public void setIssuedOn(Date issuedOn) { this.id = id;
this.issuedOn = issuedOn; }
}
public String getApiKey() {
public Short getExpiration() { return apiKey;
return expiration; }
}
public void setApiKey(String apiKey) {
public void setExpiration(Short expiration) { this.apiKey = apiKey;
this.expiration = expiration; }
}
public Date getIssuedOn() {
public AccountEntity getAccount() { return issuedOn;
return account; }
}
public void setIssuedOn(Date issuedOn) {
public void setAccount(AccountEntity account) { this.issuedOn = issuedOn;
this.account = account; }
}
public Short getExpiration() {
@Override return expiration;
public int hashCode() { }
int hash = 0;
hash += (id != null ? id.hashCode() : 0); public void setExpiration(Short expiration) {
return hash; this.expiration = expiration;
} }
@Override public AccountEntity getAccount() {
public boolean equals(Object object) { return account;
// TODO: Warning - this method won't work in the case the id fields are not set }
if (!(object instanceof ApiKeyEntity)) {
return false; public void setAccount(AccountEntity account) {
} this.account = account;
ApiKeyEntity other = (ApiKeyEntity) object; }
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false; @Override
} public int hashCode() {
return true; int hash = 0;
} hash += (id != null ? id.hashCode() : 0);
return hash;
@Override }
public String toString() {
return "com.wincornixdorf.pcd.business.account.ApiKeyEntity[ id=" + id + " ]"; @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 ApiKeyEntity)) {
return false;
}
ApiKeyEntity other = (ApiKeyEntity) 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 "com.wincornixdorf.pcd.business.account.ApiKeyEntity[ id=" + id + " ]";
}
}

View File

@ -1,56 +1,71 @@
package de.muehlencord.shared.account.business.account.entity; /*
* Copyright 2018 joern.muehlencord.
import com.fasterxml.jackson.annotation.JsonFormat; *
import com.google.gson.annotations.Expose; * Licensed under the Apache License, Version 2.0 (the "License");
import java.util.Date; * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
/** *
* * http://www.apache.org/licenses/LICENSE-2.0
* @author Joern Muehlencord <joern at muehlencord.de> *
*/ * Unless required by applicable law or agreed to in writing, software
public class ApiKeyObject { * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@Expose * See the License for the specific language governing permissions and
private String userName; * limitations under the License.
@Expose */
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm'Z'") package de.muehlencord.shared.account.business.account.entity;
private Date issuedOn;
@Expose import com.fasterxml.jackson.annotation.JsonFormat;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm'Z'") import com.google.gson.annotations.Expose;
private Date expiresOn; import java.util.Date;
@Expose
private String authToken; /**
*
public String getUserName() { * @author Joern Muehlencord <joern at muehlencord.de>
return userName; */
} public class ApiKeyObject {
public void setUserName(String userName) { @Expose
this.userName = userName; private String userName;
} @Expose
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm'Z'")
public Date getIssuedOn() { private Date issuedOn;
return issuedOn; @Expose
} @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm'Z'")
private Date expiresOn;
public void setIssuedOn(Date issuedOn) { @Expose
this.issuedOn = issuedOn; private String authToken;
}
public String getUserName() {
public Date getExpiresOn() { return userName;
return expiresOn; }
}
public void setUserName(String userName) {
public void setExpiresOn(Date expiresOn) { this.userName = userName;
this.expiresOn = expiresOn; }
}
public Date getIssuedOn() {
public String getAuthToken() { return issuedOn;
return authToken; }
}
public void setIssuedOn(Date issuedOn) {
public void setAuthToken(String authToken) { this.issuedOn = issuedOn;
this.authToken = authToken; }
}
public Date getExpiresOn() {
} return expiresOn;
}
public void setExpiresOn(Date expiresOn) {
this.expiresOn = expiresOn;
}
public String getAuthToken() {
return authToken;
}
public void setAuthToken(String authToken) {
this.authToken = authToken;
}
}

View File

@ -1,47 +1,57 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
*/ * you may not use this file except in compliance with the License.
package de.muehlencord.shared.account.business.account.entity; * You may obtain a copy of the License at
*
/** * http://www.apache.org/licenses/LICENSE-2.0
* *
* @author Joern Muehlencord <joern at muehlencord.de> * Unless required by applicable law or agreed to in writing, software
*/ * distributed under the License is distributed on an "AS IS" BASIS,
public class JWTObject { * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
private String userName; * limitations under the License.
private String unqiueId; */
private boolean valid; package de.muehlencord.shared.account.business.account.entity;
public String getUserName() { /**
return userName; *
} * @author Joern Muehlencord <joern at muehlencord.de>
*/
public void setUserName(String userName) { public class JWTObject {
this.userName = userName;
} private String userName;
private String unqiueId;
public String getUnqiueId() { private boolean valid;
return unqiueId;
} public String getUserName() {
return userName;
public void setUnqiueId(String unqiueId) { }
this.unqiueId = unqiueId;
} public void setUserName(String userName) {
this.userName = userName;
public boolean isValid() { }
return valid;
} public String getUnqiueId() {
return unqiueId;
public void setValid(boolean valid) { }
this.valid = valid;
} public void setUnqiueId(String unqiueId) {
this.unqiueId = unqiueId;
}
public boolean isValid() {
return valid;
}
}
public void setValid(boolean valid) {
this.valid = valid;
}
}

View File

@ -1,19 +1,29 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
*/ * you may not use this file except in compliance with the License.
package de.muehlencord.shared.account.business.accountconfig.entity; * You may obtain a copy of the License at
*
/** * http://www.apache.org/licenses/LICENSE-2.0
* *
* @author Joern Muehlencord <joern at muehlencord.de> * Unless required by applicable law or agreed to in writing, software
*/ * distributed under the License is distributed on an "AS IS" BASIS,
public enum AccountConfigurationKey { * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// the base path of the application * See the License for the specific language governing permissions and
BaseUrl, * limitations under the License.
// the full pass to the reset password page */
PasswordResetUrl, package de.muehlencord.shared.account.business.accountconfig.entity;
// injection handler
Producer; /**
} *
* @author Joern Muehlencord <joern at muehlencord.de>
*/
public enum AccountConfigurationKey {
// the base path of the application
BaseUrl,
// the full pass to the reset password page
PasswordResetUrl,
// injection handler
Producer;
}

View File

@ -1,30 +1,40 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
*/ * you may not use this file except in compliance with the License.
package de.muehlencord.shared.account.business.accountconfig.entity; * You may obtain a copy of the License at
*
import java.lang.annotation.ElementType; * http://www.apache.org/licenses/LICENSE-2.0
import java.lang.annotation.Retention; *
import java.lang.annotation.RetentionPolicy; * Unless required by applicable law or agreed to in writing, software
import java.lang.annotation.Target; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.enterprise.util.Nonbinding; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.inject.Qualifier; * See the License for the specific language governing permissions and
* limitations under the License.
/** */
* package de.muehlencord.shared.account.business.accountconfig.entity;
* @author Joern Muehlencord <joern at muehlencord.de>
*/ import java.lang.annotation.ElementType;
@Target({ElementType.FIELD, ElementType.METHOD}) import java.lang.annotation.Retention;
@Retention(RetentionPolicy.RUNTIME) import java.lang.annotation.RetentionPolicy;
@Qualifier import java.lang.annotation.Target;
public @interface AccountConfigurationValue { import javax.enterprise.util.Nonbinding;
import javax.inject.Qualifier;
@Nonbinding
AccountConfigurationKey key(); /**
} *
* @author Joern Muehlencord <joern at muehlencord.de>
*/
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface AccountConfigurationValue {
@Nonbinding
AccountConfigurationKey key();
}

View File

@ -1,41 +1,56 @@
package de.muehlencord.shared.account.business.application.boundary; /*
* Copyright 2018 joern.muehlencord.
import de.muehlencord.shared.account.util.Permission; *
* Licensed under the Apache License, Version 2.0 (the "License");
/** * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* @author Joern Muehlencord <joern at muehlencord.de> *
*/ * http://www.apache.org/licenses/LICENSE-2.0
public enum ApplicationPermissions implements Permission { *
* Unless required by applicable law or agreed to in writing, software
APP_LISTALL("application:listall", "Allows to list all avaiable applications"), * distributed under the License is distributed on an "AS IS" BASIS,
APP_ADD("application:add", "Allow to add a new application"), * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
APP_EDIT("application:edit", "Allow to edit an application"), * See the License for the specific language governing permissions and
APP_DELETE("application:delete", "Allow to delete an application"), * limitations under the License.
PERMISSION_ADD("permission:add", "Allow to add a permission to an application"), */
PERMISSION_EDIT("permission:edit", "Allow to edit a permission"), package de.muehlencord.shared.account.business.application.boundary;
PERMISSION_DELETE("permmission:delete", "Allow to delete a permission"),
ROLE_ADD("role:add", "Allow to add a role to an application"), import de.muehlencord.shared.account.util.Permission;
ROLE_EDIT("role:edit", "Allow to edit a role"),
ROLE_DELETE("role:delete", "Allow to delete a role"), /**
ROLE_PERMISSION_ASSIGN("role:permission:assign", "Allow to assign a permission to role"), *
ROLE_PERMISSION_REVOKE("role:permission:revoke", "All ow to revoke a permission from a role"); * @author Joern Muehlencord <joern at muehlencord.de>
*/
private final String name; public enum ApplicationPermissions implements Permission {
private final String description;
APP_LISTALL("application:listall", "Allows to list all avaiable applications"),
private ApplicationPermissions(String permissionName, String permissionDesc) { APP_ADD("application:add", "Allow to add a new application"),
this.name = permissionName; APP_EDIT("application:edit", "Allow to edit an application"),
this.description = permissionDesc; APP_DELETE("application:delete", "Allow to delete an application"),
} PERMISSION_ADD("permission:add", "Allow to add a permission to an application"),
PERMISSION_EDIT("permission:edit", "Allow to edit a permission"),
@Override PERMISSION_DELETE("permmission:delete", "Allow to delete a permission"),
public String getName() { ROLE_ADD("role:add", "Allow to add a role to an application"),
return name; ROLE_EDIT("role:edit", "Allow to edit a role"),
} ROLE_DELETE("role:delete", "Allow to delete a role"),
ROLE_PERMISSION_ASSIGN("role:permission:assign", "Allow to assign a permission to role"),
@Override ROLE_PERMISSION_REVOKE("role:permission:revoke", "All ow to revoke a permission from a role");
public String getDescription() {
return description; private final String name;
} private final String description;
}
private ApplicationPermissions(String permissionName, String permissionDesc) {
this.name = permissionName;
this.description = permissionDesc;
}
@Override
public String getName() {
return name;
}
@Override
public String getDescription() {
return description;
}
}

View File

@ -1,92 +1,107 @@
package de.muehlencord.shared.account.business.application.boundary; /*
* Copyright 2018 joern.muehlencord.
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity; *
import de.muehlencord.shared.account.util.AccountPU; * Licensed under the Apache License, Version 2.0 (the "License");
import de.muehlencord.shared.account.util.AccountSecurityException; * you may not use this file except in compliance with the License.
import de.muehlencord.shared.account.util.SecurityUtil; * You may obtain a copy of the License at
import java.io.Serializable; *
import java.util.ArrayList; * http://www.apache.org/licenses/LICENSE-2.0
import java.util.List; *
import java.util.UUID; * Unless required by applicable law or agreed to in writing, software
import javax.ejb.Stateless; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.inject.Inject; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.persistence.EntityManager; * See the License for the specific language governing permissions and
import javax.persistence.Query; * limitations under the License.
import javax.transaction.Transactional; */
import org.slf4j.Logger; package de.muehlencord.shared.account.business.application.boundary;
import org.slf4j.LoggerFactory;
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
/** import de.muehlencord.shared.account.util.AccountPU;
* import de.muehlencord.shared.account.util.AccountSecurityException;
* @author Joern Muehlencord <joern at muehlencord.de> import de.muehlencord.shared.account.util.SecurityUtil;
*/ import java.io.Serializable;
@Stateless import java.util.ArrayList;
public class ApplicationService implements Serializable { import java.util.List;
import java.util.UUID;
private static final long serialVersionUID = 4262608935325326191L; import javax.ejb.Stateless;
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationService.class); import javax.inject.Inject;
import javax.persistence.EntityManager;
@Inject import javax.persistence.Query;
@AccountPU import javax.transaction.Transactional;
EntityManager em; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public ApplicationEntity findById(UUID id) {
return em.find(ApplicationEntity.class, id); /**
} *
* @author Joern Muehlencord <joern at muehlencord.de>
public List<ApplicationEntity> getAllApplications() throws AccountSecurityException { */
SecurityUtil.checkPermission(ApplicationPermissions.APP_LISTALL, ApplicationServiceError.LISTALL_DENIED); @Stateless
Query query = em.createNamedQuery("ApplicationEntity.findAll"); public class ApplicationService implements Serializable {
List<ApplicationEntity> resultList = query.getResultList();
if (resultList == null) { private static final long serialVersionUID = 4262608935325326191L;
return new ArrayList<>(); private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationService.class);
} else {
return resultList; @Inject
} @AccountPU
} EntityManager em;
@Transactional public ApplicationEntity findById(UUID id) {
public ApplicationEntity createOrUpdate(ApplicationEntity app) { return em.find(ApplicationEntity.class, id);
if (app == null) { }
// TODO add error handling
return null; public List<ApplicationEntity> getAllApplications() throws AccountSecurityException {
} else { SecurityUtil.checkPermission(ApplicationPermissions.APP_LISTALL, ApplicationServiceError.LISTALL_DENIED);
if (app.getId() == null) { Query query = em.createNamedQuery("ApplicationEntity.findAll");
em.persist(app); List<ApplicationEntity> resultList = query.getResultList();
ApplicationEntity returnValue = findByApplicationName(app.getApplicationName()); if (resultList == null) {
if (LOGGER.isDebugEnabled()) { return new ArrayList<>();
LOGGER.debug("Application {} created", app.getApplicationName()); } else {
} return resultList;
}
return returnValue; }
} else {
ApplicationEntity returnValue = em.merge(app); @Transactional
if (LOGGER.isDebugEnabled()) { public ApplicationEntity createOrUpdate(ApplicationEntity app) {
LOGGER.debug("Applicateion {} updated", app.getApplicationName()); if (app == null) {
} // TODO add error handling
return returnValue; return null;
} } else {
} if (app.getId() == null) {
} em.persist(app);
ApplicationEntity returnValue = findByApplicationName(app.getApplicationName());
public ApplicationEntity findByApplicationName(String applicationName) { if (LOGGER.isDebugEnabled()) {
Query query = em.createNamedQuery("ApplicationEntity.findByApplicationName"); LOGGER.debug("Application {} created", app.getApplicationName());
query.setParameter("applicationName", applicationName); }
List<ApplicationEntity> resultList = query.getResultList();
if ((resultList == null) || (resultList.isEmpty())) { return returnValue;
return null; } else {
} else { ApplicationEntity returnValue = em.merge(app);
return resultList.get(0); if (LOGGER.isDebugEnabled()) {
} LOGGER.debug("Applicateion {} updated", app.getApplicationName());
} }
return returnValue;
@Transactional }
public void delete(ApplicationEntity app) { }
ApplicationEntity attachedApp = em.find(ApplicationEntity.class, app.getId()); }
em.remove(attachedApp);
if (LOGGER.isDebugEnabled()) { public ApplicationEntity findByApplicationName(String applicationName) {
LOGGER.debug("Application {} deleted", app.getApplicationName()); 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());
}
}
}

View File

@ -1,31 +1,46 @@
package de.muehlencord.shared.account.business.application.boundary; /*
* Copyright 2018 joern.muehlencord.
import de.muehlencord.shared.account.util.SecurityError; *
* Licensed under the Apache License, Version 2.0 (the "License");
/** * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* @author Joern Muehlencord <joern at muehlencord.de> *
*/ * http://www.apache.org/licenses/LICENSE-2.0
public enum ApplicationServiceError implements SecurityError { *
* Unless required by applicable law or agreed to in writing, software
LISTALL_DENIED("1000", "listall_denied"); * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
private final String errorCode; * See the License for the specific language governing permissions and
private final String messageKey; * limitations under the License.
*/
private ApplicationServiceError(String errorCode, String messageKey) { package de.muehlencord.shared.account.business.application.boundary;
this.errorCode = errorCode;
this.messageKey = messageKey; import de.muehlencord.shared.account.util.SecurityError;
}
/**
@Override *
public String getErrorCode() { * @author Joern Muehlencord <joern at muehlencord.de>
return errorCode; */
} public enum ApplicationServiceError implements SecurityError {
@Override LISTALL_DENIED("1000", "listall_denied");
public String getMessageKey() {
return messageKey; private final String errorCode;
} private final String messageKey;
} private ApplicationServiceError(String errorCode, String messageKey) {
this.errorCode = errorCode;
this.messageKey = messageKey;
}
@Override
public String getErrorCode() {
return errorCode;
}
@Override
public String getMessageKey() {
return messageKey;
}
}

View File

@ -1,71 +1,71 @@
/* /*
* Copyright 2018 Joern Muehlencord <joern at muehlencord.de>. * Copyright 2018 joern.muehlencord.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package de.muehlencord.shared.account.business.application.boundary; package de.muehlencord.shared.account.business.application.boundary;
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity; import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
import de.muehlencord.shared.account.business.config.boundary.ConfigService; import de.muehlencord.shared.account.business.config.boundary.ConfigService;
import de.muehlencord.shared.account.business.config.entity.ConfigException; import de.muehlencord.shared.account.business.config.entity.ConfigException;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Initialized; import javax.enterprise.context.Initialized;
import javax.enterprise.event.Observes; import javax.enterprise.event.Observes;
import javax.inject.Inject; import javax.inject.Inject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* *
* @author Joern Muehlencord <joern at muehlencord.de> * @author Joern Muehlencord <joern at muehlencord.de>
*/ */
@ApplicationScoped @ApplicationScoped
public class StartupBean { public class StartupBean {
private static final Logger LOGGER = LoggerFactory.getLogger(StartupBean.class); private static final Logger LOGGER = LoggerFactory.getLogger(StartupBean.class);
@Inject @Inject
ConfigService configService; ConfigService configService;
@Inject @Inject
ApplicationEntity application; ApplicationEntity application;
public void init(@Observes @Initialized(ApplicationScoped.class) Object init) { public void init(@Observes @Initialized(ApplicationScoped.class) Object init) {
try { try {
LOGGER.info("Starting application {}", application.getApplicationName()); LOGGER.info("Starting application {}", application.getApplicationName());
String instanceName = configService.getConfigValue("base.instance", "Development System", true); String instanceName = configService.getConfigValue("base.instance", "Development System", true);
LOGGER.info("instanceName={}", instanceName); LOGGER.info("instanceName={}", instanceName);
// ensure maxFailedLogins is available // ensure maxFailedLogins is available
configService.getConfigValue("account.maxFailedLogins", "5", true); configService.getConfigValue("account.maxFailedLogins", "5", true);
LOGGER.info("Application startup complete"); LOGGER.info("Application startup complete");
} catch (ConfigException ex) { } catch (ConfigException ex) {
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(ex.toString(), ex); LOGGER.debug(ex.toString(), ex);
} else { } else {
LOGGER.error(ex.toString()); LOGGER.error(ex.toString());
} }
} }
} }
@PreDestroy @PreDestroy
public void shutdown() { public void shutdown() {
LOGGER.info("Shutting down application {}", application.getApplicationName()); LOGGER.info("Shutting down application {}", application.getApplicationName());
LOGGER.info("Application shutdown complete"); LOGGER.info("Application shutdown complete");
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2018 Joern Muehlencord <joern at muehlencord.de>. * Copyright 2018 joern.muehlencord.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,142 +1,157 @@
package de.muehlencord.shared.account.business.application.control; /*
* Copyright 2018 joern.muehlencord.
import de.muehlencord.shared.account.business.account.entity.AccountException; *
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity; * Licensed under the Apache License, Version 2.0 (the "License");
import de.muehlencord.shared.account.business.application.entity.ApplicationPermissionEntity; * you may not use this file except in compliance with the License.
import de.muehlencord.shared.account.util.AccountPU; * You may obtain a copy of the License at
import de.muehlencord.shared.account.util.Permission; *
import java.io.Serializable; * http://www.apache.org/licenses/LICENSE-2.0
import java.util.ArrayList; *
import java.util.List; * Unless required by applicable law or agreed to in writing, software
import javax.ejb.Stateless; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.inject.Inject; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.persistence.EntityManager; * See the License for the specific language governing permissions and
import javax.persistence.OptimisticLockException; * limitations under the License.
import javax.persistence.Query; */
import javax.transaction.Transactional; package de.muehlencord.shared.account.business.application.control;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import de.muehlencord.shared.account.business.account.entity.AccountException;
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
/** import de.muehlencord.shared.account.business.application.entity.ApplicationPermissionEntity;
* import de.muehlencord.shared.account.util.AccountPU;
* @author Joern Muehlencord <joern at muehlencord.de> import de.muehlencord.shared.account.util.Permission;
*/ import java.io.Serializable;
@Stateless import java.util.ArrayList;
public class ApplicationPermissionControl implements Serializable { import java.util.List;
import javax.ejb.Stateless;
private static final long serialVersionUID = -3761100587901739481L; import javax.inject.Inject;
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationPermissionControl.class); import javax.persistence.EntityManager;
import javax.persistence.OptimisticLockException;
@Inject import javax.persistence.Query;
@AccountPU import javax.transaction.Transactional;
EntityManager em; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Inject
ApplicationEntity application; /**
*
public List<ApplicationPermissionEntity> getApplicationPermissions(ApplicationEntity app) { * @author Joern Muehlencord <joern at muehlencord.de>
Query query = em.createNamedQuery("ApplicationPermissionEntity.findAll"); */
query.setParameter("application", app); @Stateless
List<ApplicationPermissionEntity> permissionList = query.getResultList(); public class ApplicationPermissionControl implements Serializable {
if (permissionList == null) {
return new ArrayList<>(); private static final long serialVersionUID = -3761100587901739481L;
} else { private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationPermissionControl.class);
return permissionList;
} @Inject
} @AccountPU
EntityManager em;
public ApplicationPermissionEntity findPermissionByName(ApplicationEntity application, String permissionName) {
Query query = em.createNamedQuery("ApplicationPermissionEntity.findByPermissionName"); @Inject
query.setParameter("application", application); ApplicationEntity application;
query.setParameter("permissionName", permissionName);
List<ApplicationPermissionEntity> resultList = query.getResultList(); public List<ApplicationPermissionEntity> getApplicationPermissions(ApplicationEntity app) {
if ((resultList == null) || (resultList.isEmpty())) { Query query = em.createNamedQuery("ApplicationPermissionEntity.findAll");
return null; query.setParameter("application", app);
} else { List<ApplicationPermissionEntity> permissionList = query.getResultList();
return resultList.get(0); if (permissionList == null) {
} return new ArrayList<>();
} } else {
return permissionList;
@Transactional }
public void create(ApplicationEntity application, String name, String description) { }
ApplicationPermissionEntity permission = new ApplicationPermissionEntity(application, name, description);
em.persist(permission); public ApplicationPermissionEntity findPermissionByName(ApplicationEntity application, String permissionName) {
} Query query = em.createNamedQuery("ApplicationPermissionEntity.findByPermissionName");
query.setParameter("application", application);
@Transactional query.setParameter("permissionName", permissionName);
public void update(ApplicationPermissionEntity permission) throws AccountException { List<ApplicationPermissionEntity> resultList = query.getResultList();
ApplicationPermissionEntity existing = attach(permission); if ((resultList == null) || (resultList.isEmpty())) {
em.merge(existing); return null;
} } else {
return resultList.get(0);
@Transactional }
public void createOrUpdate(ApplicationEntity application, String name, String description) { }
ApplicationPermissionEntity permission = findByName(application, name);
if (permission == null) { @Transactional
permission = new ApplicationPermissionEntity(name, description); public void create(ApplicationEntity application, String name, String description) {
em.persist(permission); ApplicationPermissionEntity permission = new ApplicationPermissionEntity(application, name, description);
} else { em.persist(permission);
permission.setPermissionDescription(description); }
em.merge(permission);
} @Transactional
} public void update(ApplicationPermissionEntity permission) throws AccountException {
ApplicationPermissionEntity existing = attach(permission);
@Transactional em.merge(existing);
public void delete(ApplicationPermissionEntity permission) throws AccountException { }
ApplicationPermissionEntity existingPermission = attach(permission);
em.remove(existingPermission); @Transactional
} public void createOrUpdate(ApplicationEntity application, String name, String description) {
ApplicationPermissionEntity permission = findByName(application, name);
public ApplicationPermissionEntity attach(ApplicationPermissionEntity permission) throws AccountException { if (permission == null) {
try { permission = new ApplicationPermissionEntity(name, description);
return em.merge(permission); em.persist(permission);
} catch (OptimisticLockException ex) { } else {
throw new AccountException("Entity updated / deleted, please reload", true); permission.setPermissionDescription(description);
} em.merge(permission);
} }
}
private ApplicationPermissionEntity findByName(ApplicationEntity application, String name) {
Query query = em.createNamedQuery("ApplicationPermissionEntity.findByPermissionName"); @Transactional
query.setParameter("application", application); public void delete(ApplicationPermissionEntity permission) throws AccountException {
query.setParameter("permissionName", name); ApplicationPermissionEntity existingPermission = attach(permission);
List<ApplicationPermissionEntity> permissions = query.getResultList(); em.remove(existingPermission);
if ((permissions == null) || (permissions.isEmpty())) { }
return null;
} else { public ApplicationPermissionEntity attach(ApplicationPermissionEntity permission) throws AccountException {
return permissions.get(0); try {
} return em.merge(permission);
} } catch (OptimisticLockException ex) {
throw new AccountException("Entity updated / deleted, please reload", true);
@Transactional }
public void setupPermissions(List<Permission> permissions) { }
for (Permission permission : permissions) {
ApplicationPermissionEntity existingPermission = findByName(application, permission.getName()); private ApplicationPermissionEntity findByName(ApplicationEntity application, String name) {
if (existingPermission == null) { Query query = em.createNamedQuery("ApplicationPermissionEntity.findByPermissionName");
// permission not available, create it query.setParameter("application", application);
LOGGER.info("missing permission {} of {}", permission.getName(), application.getApplicationName()); query.setParameter("permissionName", name);
existingPermission = new ApplicationPermissionEntity(permission.getName(), permission.getDescription()); List<ApplicationPermissionEntity> permissions = query.getResultList();
existingPermission.setApplication(application); if ((permissions == null) || (permissions.isEmpty())) {
em.persist(existingPermission); return null;
if (LOGGER.isDebugEnabled()) { } else {
LOGGER.debug("missing permission {} added to {}", permission.getName(), application.getApplicationName()); return permissions.get(0);
} }
} else { }
if (existingPermission.getPermissionDescription().equals(permission.getDescription())) {
if (LOGGER.isDebugEnabled()) { @Transactional
LOGGER.debug("Permission {} for {} already exists, skipping", permission.getName(), application.getApplicationName()); public void setupPermissions(List<Permission> permissions) {
} for (Permission permission : permissions) {
} else { ApplicationPermissionEntity existingPermission = findByName(application, permission.getName());
if (LOGGER.isDebugEnabled()) { if (existingPermission == null) {
LOGGER.debug("description of permssion {} for {} differs, resetting to orignal value {}", permission.getName(), application.getApplicationName(), permission.getDescription()); // permission not available, create it
} LOGGER.info("missing permission {} of {}", permission.getName(), application.getApplicationName());
existingPermission = new ApplicationPermissionEntity(permission.getName(), permission.getDescription());
existingPermission.setPermissionDescription(permission.getDescription()); existingPermission.setApplication(application);
em.merge (existingPermission); em.persist(existingPermission);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug("updated permission description {} for {}", permission.getName(), application.getApplicationName()); LOGGER.debug("missing permission {} added to {}", permission.getName(), application.getApplicationName());
} }
} } else {
} if (existingPermission.getPermissionDescription().equals(permission.getDescription())) {
} if (LOGGER.isDebugEnabled()) {
} LOGGER.debug("Permission {} for {} already exists, skipping", permission.getName(), application.getApplicationName());
} }
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("description of permssion {} for {} differs, resetting to orignal value {}", permission.getName(), application.getApplicationName(), permission.getDescription());
}
existingPermission.setPermissionDescription(permission.getDescription());
em.merge (existingPermission);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("updated permission description {} for {}", permission.getName(), application.getApplicationName());
}
}
}
}
}
}

View File

@ -1,7 +1,17 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package de.muehlencord.shared.account.business.application.control; package de.muehlencord.shared.account.business.application.control;

View File

@ -1,129 +1,144 @@
package de.muehlencord.shared.account.business.application.entity; /*
* Copyright 2018 joern.muehlencord.
import de.muehlencord.shared.account.business.config.entity.ConfigEntity; *
import java.io.Serializable; * Licensed under the Apache License, Version 2.0 (the "License");
import java.util.List; * you may not use this file except in compliance with the License.
import java.util.UUID; * You may obtain a copy of the License at
import javax.persistence.Basic; *
import javax.persistence.CascadeType; * http://www.apache.org/licenses/LICENSE-2.0
import javax.persistence.Column; *
import javax.persistence.Entity; * Unless required by applicable law or agreed to in writing, software
import javax.persistence.GeneratedValue; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.persistence.Id; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.persistence.NamedQueries; * See the License for the specific language governing permissions and
import javax.persistence.NamedQuery; * limitations under the License.
import javax.persistence.OneToMany; */
import javax.persistence.Table; package de.muehlencord.shared.account.business.application.entity;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable;
import javax.xml.bind.annotation.XmlTransient; import java.util.List;
import org.hibernate.annotations.GenericGenerator; import java.util.UUID;
import org.hibernate.annotations.Type; import javax.persistence.Basic;
import javax.persistence.CascadeType;
/** import javax.persistence.Column;
* import javax.persistence.Entity;
* @author Joern Muehlencord <joern at muehlencord.de> import javax.persistence.GeneratedValue;
*/ import javax.persistence.Id;
@Entity import javax.persistence.NamedQueries;
@Table(name = "application") import javax.persistence.NamedQuery;
@XmlRootElement import javax.persistence.OneToMany;
@NamedQueries({ import javax.persistence.Table;
@NamedQuery(name = "ApplicationEntity.findAll", query = "SELECT a FROM ApplicationEntity a"), import javax.validation.constraints.NotNull;
@NamedQuery(name = "ApplicationEntity.findByApplicationName", query = "SELECT a FROM ApplicationEntity a WHERE a.applicationName = :applicationName")}) import javax.validation.constraints.Size;
public class ApplicationEntity implements Serializable { import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
private static final long serialVersionUID = -6407525020014743727L; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
@Id
@Basic(optional = false) /**
@NotNull *
@Column(name = "id") * @author Joern Muehlencord <joern at muehlencord.de>
@GeneratedValue(generator = "uuid2") */
@GenericGenerator(name = "uuid2", strategy = "uuid2") @Entity
@Type(type = "pg-uuid") @Table(name = "application")
private UUID id; @XmlRootElement
@Basic(optional = false) @NamedQueries({
@NotNull @NamedQuery(name = "ApplicationEntity.findAll", query = "SELECT a FROM ApplicationEntity a"),
@Size(min = 1, max = 200) @NamedQuery(name = "ApplicationEntity.findByApplicationName", query = "SELECT a FROM ApplicationEntity a WHERE a.applicationName = :applicationName")})
@Column(name = "application_name", unique = true) public class ApplicationEntity implements Serializable {
private String applicationName;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "application") private static final long serialVersionUID = -6407525020014743727L;
private List<ApplicationRoleEntity> applicationRoleEntityList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "application") @Id
private List<ApplicationPermissionEntity> applicationPermissions; @Basic(optional = false)
@OneToMany(cascade = CascadeType.ALL, mappedBy = "application") @NotNull
private List<ConfigEntity> configEntityList; @Column(name = "id")
@GeneratedValue(generator = "uuid2")
public ApplicationEntity() { @GenericGenerator(name = "uuid2", strategy = "uuid2")
} @Type(type = "pg-uuid")
private UUID id;
public UUID getId() { @Basic(optional = false)
return id; @NotNull
} @Size(min = 1, max = 200)
@Column(name = "application_name", unique = true)
public void setId(UUID id) { private String applicationName;
this.id = id; @OneToMany(cascade = CascadeType.ALL, mappedBy = "application")
} private List<ApplicationRoleEntity> applicationRoleEntityList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "application")
public String getApplicationName() { private List<ApplicationPermissionEntity> applicationPermissions;
return applicationName; @OneToMany(cascade = CascadeType.ALL, mappedBy = "application")
} private List<ConfigEntity> configEntityList;
public void setApplicationName(String applicationName) { public ApplicationEntity() {
this.applicationName = applicationName; }
}
public UUID getId() {
@XmlTransient return id;
public List<ApplicationRoleEntity> getApplicationRoleEntityList() { }
return applicationRoleEntityList;
} public void setId(UUID id) {
this.id = id;
public void setApplicationRoleEntityList(List<ApplicationRoleEntity> applicationRoleEntityList) { }
this.applicationRoleEntityList = applicationRoleEntityList;
} public String getApplicationName() {
return applicationName;
@XmlTransient }
public List<ApplicationPermissionEntity> getApplicationPermissions() {
return applicationPermissions; public void setApplicationName(String applicationName) {
} this.applicationName = applicationName;
}
public void setApplicationPermissions(List<ApplicationPermissionEntity> applicationPermissions) {
this.applicationPermissions = applicationPermissions; @XmlTransient
} public List<ApplicationRoleEntity> getApplicationRoleEntityList() {
return applicationRoleEntityList;
@XmlTransient }
public List<ConfigEntity> getConfigEntityList() {
return configEntityList; public void setApplicationRoleEntityList(List<ApplicationRoleEntity> applicationRoleEntityList) {
} this.applicationRoleEntityList = applicationRoleEntityList;
}
public void setConfigEntityList(List<ConfigEntity> configEntityList) {
this.configEntityList = configEntityList; @XmlTransient
} public List<ApplicationPermissionEntity> getApplicationPermissions() {
return applicationPermissions;
@Override }
public int hashCode() {
int hash = 0; public void setApplicationPermissions(List<ApplicationPermissionEntity> applicationPermissions) {
hash += (id != null ? id.hashCode() : 0); this.applicationPermissions = applicationPermissions;
return hash; }
}
@XmlTransient
@Override public List<ConfigEntity> getConfigEntityList() {
public boolean equals(Object object) { return configEntityList;
// TODO: Warning - this method won't work in the case the id fields are not set }
if (!(object instanceof ApplicationEntity)) {
return false; public void setConfigEntityList(List<ConfigEntity> configEntityList) {
} this.configEntityList = configEntityList;
ApplicationEntity other = (ApplicationEntity) object; }
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false; @Override
} public int hashCode() {
return true; int hash = 0;
} hash += (id != null ? id.hashCode() : 0);
return hash;
@Override }
public String toString() {
return "de.muehlencord.shared.account.business.application.entity.ApplicationEntity[ id=" + id + " ]"; @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 + " ]";
}
}

View File

@ -1,158 +1,173 @@
package de.muehlencord.shared.account.business.application.entity; /*
* Copyright 2018 joern.muehlencord.
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity; *
import java.io.Serializable; * Licensed under the Apache License, Version 2.0 (the "License");
import java.util.List; * you may not use this file except in compliance with the License.
import java.util.UUID; * You may obtain a copy of the License at
import javax.persistence.Basic; *
import javax.persistence.Column; * http://www.apache.org/licenses/LICENSE-2.0
import javax.persistence.Entity; *
import javax.persistence.GeneratedValue; * Unless required by applicable law or agreed to in writing, software
import javax.persistence.Id; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.persistence.JoinColumn; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.persistence.ManyToMany; * See the License for the specific language governing permissions and
import javax.persistence.ManyToOne; * limitations under the License.
import javax.persistence.NamedQueries; */
import javax.persistence.NamedQuery; package de.muehlencord.shared.account.business.application.entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull; import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
import javax.validation.constraints.Size; import java.io.Serializable;
import javax.xml.bind.annotation.XmlRootElement; import java.util.List;
import javax.xml.bind.annotation.XmlTransient; import java.util.UUID;
import org.hibernate.annotations.GenericGenerator; import javax.persistence.Basic;
import org.hibernate.annotations.Type; import javax.persistence.Column;
import javax.persistence.Entity;
/** import javax.persistence.GeneratedValue;
* import javax.persistence.Id;
* @author joern.muehlencord import javax.persistence.JoinColumn;
*/ import javax.persistence.ManyToMany;
@Entity import javax.persistence.ManyToOne;
@Table(name = "application_permission") import javax.persistence.NamedQueries;
@XmlRootElement import javax.persistence.NamedQuery;
@NamedQueries({ import javax.persistence.Table;
@NamedQuery(name = "ApplicationPermissionEntity.findAll", query = "SELECT a FROM ApplicationPermissionEntity a WHERE a.application=:application order by a.permissionName"), import javax.validation.constraints.NotNull;
@NamedQuery(name = "ApplicationPermissionEntity.findNotAssigned", query = "SELECT a FROM ApplicationPermissionEntity a LEFT OUTER JOIN a.applicationRoles r WHERE a.application=:application AND r NOT IN :permissions"), import javax.validation.constraints.Size;
@NamedQuery(name = "ApplicationPermissionEntity.findByPermissionName", query = "SELECT a FROM ApplicationPermissionEntity a WHERE a.application=:application AND a.permissionName = :permissionName"), import javax.xml.bind.annotation.XmlRootElement;
@NamedQuery(name = "ApplicationPermissionEntity.findByPermissionDescription", query = "SELECT a FROM ApplicationPermissionEntity a WHERE a.application=:application AND a.permissionDescription = :permissionDescription")}) import javax.xml.bind.annotation.XmlTransient;
public class ApplicationPermissionEntity implements Serializable { import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
private static final long serialVersionUID = -8985982754544829534L;
/**
@Id *
@Basic(optional = false) * @author joern.muehlencord
@NotNull */
@Column(name = "id") @Entity
@GeneratedValue(generator = "uuid2") @Table(name = "application_permission")
@GenericGenerator(name = "uuid2", strategy = "uuid2") @XmlRootElement
@Type(type = "pg-uuid") @NamedQueries({
private UUID id; @NamedQuery(name = "ApplicationPermissionEntity.findAll", query = "SELECT a FROM ApplicationPermissionEntity a WHERE a.application=:application order by a.permissionName"),
@Basic(optional = false) @NamedQuery(name = "ApplicationPermissionEntity.findNotAssigned", query = "SELECT a FROM ApplicationPermissionEntity a LEFT OUTER JOIN a.applicationRoles r WHERE a.application=:application AND r NOT IN :permissions"),
@NotNull @NamedQuery(name = "ApplicationPermissionEntity.findByPermissionName", query = "SELECT a FROM ApplicationPermissionEntity a WHERE a.application=:application AND a.permissionName = :permissionName"),
@Size(min = 1, max = 80) @NamedQuery(name = "ApplicationPermissionEntity.findByPermissionDescription", query = "SELECT a FROM ApplicationPermissionEntity a WHERE a.application=:application AND a.permissionDescription = :permissionDescription")})
@Column(name = "permission_name") public class ApplicationPermissionEntity implements Serializable {
private String permissionName;
@Basic(optional = false) private static final long serialVersionUID = -8985982754544829534L;
@NotNull
@Size(min = 1, max = 200) @Id
@Column(name = "permission_description") @Basic(optional = false)
private String permissionDescription; @NotNull
@JoinColumn(name = "application", referencedColumnName = "id") @Column(name = "id")
@ManyToOne(optional = false) @GeneratedValue(generator = "uuid2")
private ApplicationEntity application; @GenericGenerator(name = "uuid2", strategy = "uuid2")
@ManyToMany(mappedBy = "applicationPermissionList") @Type(type = "pg-uuid")
private List<ApplicationRoleEntity> applicationRoles; private UUID id;
@Basic(optional = false)
public ApplicationPermissionEntity() { @NotNull
} @Size(min = 1, max = 80)
@Column(name = "permission_name")
public ApplicationPermissionEntity(UUID id) { private String permissionName;
this.id = id; @Basic(optional = false)
} @NotNull
@Size(min = 1, max = 200)
public ApplicationPermissionEntity(String permissionName, String permissionDescription) { @Column(name = "permission_description")
this.id = null; private String permissionDescription;
this.permissionName = permissionName; @JoinColumn(name = "application", referencedColumnName = "id")
this.permissionDescription = permissionDescription; @ManyToOne(optional = false)
} private ApplicationEntity application;
@ManyToMany(mappedBy = "applicationPermissionList")
public ApplicationPermissionEntity(ApplicationEntity application, String permissionName, String permissionDescription) { private List<ApplicationRoleEntity> applicationRoles;
this.id = null;
this.application = application; public ApplicationPermissionEntity() {
this.permissionName = permissionName; }
this.permissionDescription = permissionDescription;
} public ApplicationPermissionEntity(UUID id) {
this.id = id;
public ApplicationPermissionEntity(UUID id, ApplicationEntity application, String permissionName, String permissionDescription) { }
this.id = id;
this.application = application; public ApplicationPermissionEntity(String permissionName, String permissionDescription) {
this.permissionName = permissionName; this.id = null;
this.permissionDescription = permissionDescription; this.permissionName = permissionName;
} this.permissionDescription = permissionDescription;
}
public UUID getId() {
return id; public ApplicationPermissionEntity(ApplicationEntity application, String permissionName, String permissionDescription) {
} this.id = null;
this.application = application;
public void setId(UUID id) { this.permissionName = permissionName;
this.id = id; this.permissionDescription = permissionDescription;
} }
public String getPermissionName() { public ApplicationPermissionEntity(UUID id, ApplicationEntity application, String permissionName, String permissionDescription) {
return permissionName; this.id = id;
} this.application = application;
this.permissionName = permissionName;
public void setPermissionName(String permissionName) { this.permissionDescription = permissionDescription;
this.permissionName = permissionName; }
}
public UUID getId() {
public String getPermissionDescription() { return id;
return permissionDescription; }
}
public void setId(UUID id) {
public void setPermissionDescription(String permissionDescription) { this.id = id;
this.permissionDescription = permissionDescription; }
}
public String getPermissionName() {
@XmlTransient return permissionName;
public List<ApplicationRoleEntity> getApplicationRoles() { }
return applicationRoles;
} public void setPermissionName(String permissionName) {
this.permissionName = permissionName;
public void setApplicationRoles(List<ApplicationRoleEntity> applicationRoles) { }
this.applicationRoles = applicationRoles;
} public String getPermissionDescription() {
return permissionDescription;
@Override }
public int hashCode() {
int hash = 0; public void setPermissionDescription(String permissionDescription) {
hash += (id != null ? id.hashCode() : 0); this.permissionDescription = permissionDescription;
return hash; }
}
@XmlTransient
@Override public List<ApplicationRoleEntity> getApplicationRoles() {
public boolean equals(Object object) { return applicationRoles;
// TODO: Warning - this method won't work in the case the id fields are not set }
if (!(object instanceof ApplicationPermissionEntity)) {
return false; public void setApplicationRoles(List<ApplicationRoleEntity> applicationRoles) {
} this.applicationRoles = applicationRoles;
ApplicationPermissionEntity other = (ApplicationPermissionEntity) object; }
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false; @Override
} public int hashCode() {
return true; int hash = 0;
} hash += (id != null ? id.hashCode() : 0);
return hash;
@Override }
public String toString() {
return "de.muehlencord.shared.account.entity.ApplicationPermission[ id=" + id + " ]"; @Override
} public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
public ApplicationEntity getApplication() { if (!(object instanceof ApplicationPermissionEntity)) {
return application; return false;
} }
ApplicationPermissionEntity other = (ApplicationPermissionEntity) object;
public void setApplication(ApplicationEntity application) { if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
this.application = application; return false;
} }
return true;
} }
@Override
public String toString() {
return "de.muehlencord.shared.account.entity.ApplicationPermission[ id=" + id + " ]";
}
public ApplicationEntity getApplication() {
return application;
}
public void setApplication(ApplicationEntity application) {
this.application = application;
}
}

View File

@ -1,171 +1,186 @@
package de.muehlencord.shared.account.business.application.entity; /*
* Copyright 2018 joern.muehlencord.
import de.muehlencord.shared.account.business.account.entity.AccountEntity; *
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity; * Licensed under the Apache License, Version 2.0 (the "License");
import java.io.Serializable; * you may not use this file except in compliance with the License.
import java.util.List; * You may obtain a copy of the License at
import java.util.UUID; *
import javax.persistence.Basic; * http://www.apache.org/licenses/LICENSE-2.0
import javax.persistence.Column; *
import javax.persistence.Entity; * Unless required by applicable law or agreed to in writing, software
import javax.persistence.GeneratedValue; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.persistence.Id; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.persistence.JoinColumn; * See the License for the specific language governing permissions and
import javax.persistence.JoinTable; * limitations under the License.
import javax.persistence.ManyToMany; */
import javax.persistence.ManyToOne; package de.muehlencord.shared.account.business.application.entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import de.muehlencord.shared.account.business.account.entity.AccountEntity;
import javax.persistence.Table; import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
import javax.validation.constraints.NotNull; import java.io.Serializable;
import javax.validation.constraints.Size; import java.util.List;
import javax.xml.bind.annotation.XmlRootElement; import java.util.UUID;
import javax.xml.bind.annotation.XmlTransient; import javax.persistence.Basic;
import org.hibernate.annotations.GenericGenerator; import javax.persistence.Column;
import org.hibernate.annotations.Type; import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
/** import javax.persistence.Id;
* import javax.persistence.JoinColumn;
* @author joern.muehlencord import javax.persistence.JoinTable;
*/ import javax.persistence.ManyToMany;
@Entity import javax.persistence.ManyToOne;
@Table(name = "application_role") import javax.persistence.NamedQueries;
@XmlRootElement import javax.persistence.NamedQuery;
@NamedQueries({ import javax.persistence.Table;
@NamedQuery(name = "ApplicationRoleEntity.findAll", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.application = :application ORDER BY a.roleName"), import javax.validation.constraints.NotNull;
@NamedQuery(name = "ApplicationRoleEntity.findByRoleName", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.application = :application AND a.roleName = :roleName"), import javax.validation.constraints.Size;
@NamedQuery(name = "ApplicationRoleEntity.findByRoleDescription", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.application = :application AND a.roleDescription = :roleDescription")}) import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
public class ApplicationRoleEntity implements Serializable { import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
private static final long serialVersionUID = -8324054525780893823L;
/**
@Id *
@Basic(optional = false) * @author joern.muehlencord
@NotNull */
@Column(name = "id") @Entity
@GeneratedValue(generator = "uuid2") @Table(name = "application_role")
@GenericGenerator(name = "uuid2", strategy = "uuid2") @XmlRootElement
@Type(type = "pg-uuid") @NamedQueries({
private UUID id; @NamedQuery(name = "ApplicationRoleEntity.findAll", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.application = :application ORDER BY a.roleName"),
@Basic(optional = false) @NamedQuery(name = "ApplicationRoleEntity.findByRoleName", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.application = :application AND a.roleName = :roleName"),
@NotNull @NamedQuery(name = "ApplicationRoleEntity.findByRoleDescription", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.application = :application AND a.roleDescription = :roleDescription")})
@Size(min = 1, max = 80)
@Column(name = "role_name") public class ApplicationRoleEntity implements Serializable {
private String roleName;
@Basic(optional = false) private static final long serialVersionUID = -8324054525780893823L;
@NotNull
@Size(min = 1, max = 200) @Id
@Column(name = "role_description") @Basic(optional = false)
private String roleDescription; @NotNull
@ManyToMany(mappedBy = "applicationRoleList") @Column(name = "id")
private List<AccountEntity> accountList; @GeneratedValue(generator = "uuid2")
@JoinTable(name = "role_permission", joinColumns = { @GenericGenerator(name = "uuid2", strategy = "uuid2")
@JoinColumn(name = "application_role", referencedColumnName = "id")}, inverseJoinColumns = { @Type(type = "pg-uuid")
@JoinColumn(name = "role_permission", referencedColumnName = "id")}) private UUID id;
@ManyToMany @Basic(optional = false)
private List<ApplicationPermissionEntity> applicationPermissionList; @NotNull
@JoinColumn(name = "application", referencedColumnName = "id") @Size(min = 1, max = 80)
@ManyToOne(optional = false) @Column(name = "role_name")
private ApplicationEntity application; private String roleName;
@Basic(optional = false)
public ApplicationRoleEntity() { @NotNull
} @Size(min = 1, max = 200)
@Column(name = "role_description")
public ApplicationRoleEntity(ApplicationEntity application) { private String roleDescription;
this.id = null; @ManyToMany(mappedBy = "applicationRoleList")
this.application = application; private List<AccountEntity> accountList;
this.roleName = ""; @JoinTable(name = "role_permission", joinColumns = {
this.roleDescription = ""; @JoinColumn(name = "application_role", referencedColumnName = "id")}, inverseJoinColumns = {
} @JoinColumn(name = "role_permission", referencedColumnName = "id")})
@ManyToMany
public ApplicationRoleEntity(ApplicationEntity application, String roleName, String roleDescription) { private List<ApplicationPermissionEntity> applicationPermissionList;
this.id = null; @JoinColumn(name = "application", referencedColumnName = "id")
this.application = application; @ManyToOne(optional = false)
this.roleName = roleName; private ApplicationEntity application;
this.roleDescription = roleDescription;
} public ApplicationRoleEntity() {
}
public ApplicationRoleEntity(UUID id, ApplicationEntity application, String roleName, String roleDescription) {
this.id = id; public ApplicationRoleEntity(ApplicationEntity application) {
this.application = application; this.id = null;
this.roleName = roleName; this.application = application;
this.roleDescription = roleDescription; this.roleName = "";
} this.roleDescription = "";
}
public UUID getId() {
return id; public ApplicationRoleEntity(ApplicationEntity application, String roleName, String roleDescription) {
} this.id = null;
this.application = application;
public void setId(UUID id) { this.roleName = roleName;
this.id = id; this.roleDescription = roleDescription;
} }
public String getRoleName() { public ApplicationRoleEntity(UUID id, ApplicationEntity application, String roleName, String roleDescription) {
return roleName; this.id = id;
} this.application = application;
this.roleName = roleName;
public void setRoleName(String roleName) { this.roleDescription = roleDescription;
this.roleName = roleName; }
}
public UUID getId() {
public String getRoleDescription() { return id;
return roleDescription; }
}
public void setId(UUID id) {
public void setRoleDescription(String roleDescription) { this.id = id;
this.roleDescription = roleDescription; }
}
public String getRoleName() {
@XmlTransient return roleName;
public List<AccountEntity> getAccountList() { }
return accountList;
} public void setRoleName(String roleName) {
this.roleName = roleName;
public void setAccountList(List<AccountEntity> accountList) { }
this.accountList = accountList;
} public String getRoleDescription() {
return roleDescription;
@XmlTransient }
public List<ApplicationPermissionEntity> getApplicationPermissionList() {
return applicationPermissionList; public void setRoleDescription(String roleDescription) {
} this.roleDescription = roleDescription;
}
public void setApplicationPermissionList(List<ApplicationPermissionEntity> applicationPermissionList) {
this.applicationPermissionList = applicationPermissionList; @XmlTransient
} public List<AccountEntity> getAccountList() {
return accountList;
public ApplicationEntity getApplication() { }
return application;
} public void setAccountList(List<AccountEntity> accountList) {
this.accountList = accountList;
public void setApplication(ApplicationEntity application) { }
this.application = application;
} @XmlTransient
public List<ApplicationPermissionEntity> getApplicationPermissionList() {
@Override return applicationPermissionList;
public int hashCode() { }
int hash = 0;
hash += (id != null ? id.hashCode() : 0); public void setApplicationPermissionList(List<ApplicationPermissionEntity> applicationPermissionList) {
return hash; this.applicationPermissionList = applicationPermissionList;
} }
@Override public ApplicationEntity getApplication() {
public boolean equals(Object object) { return application;
// TODO: Warning - this method won't work in the case the id fields are not set }
if (!(object instanceof ApplicationRoleEntity)) {
return false; public void setApplication(ApplicationEntity application) {
} this.application = application;
ApplicationRoleEntity other = (ApplicationRoleEntity) object; }
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false; @Override
} public int hashCode() {
return true; int hash = 0;
} hash += (id != null ? id.hashCode() : 0);
return hash;
@Override }
public String toString() {
return "de.muehlencord.shared.account.entity.ApplicationRole[ id=" + id + " ]"; @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 ApplicationRoleEntity)) {
return false;
}
ApplicationRoleEntity other = (ApplicationRoleEntity) 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.ApplicationRole[ id=" + id + " ]";
}
}

View File

@ -1,3 +1,18 @@
/*
* Copyright 2018 joern.muehlencord.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.business.config.boundary; 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.Account;

View File

@ -1,52 +1,62 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
*/ * you may not use this file except in compliance with the License.
package de.muehlencord.shared.account.business.config.boundary; * You may obtain a copy of the License at
*
import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationKey; * http://www.apache.org/licenses/LICENSE-2.0
import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationValue; *
import de.muehlencord.shared.account.business.config.entity.ConfigException; * Unless required by applicable law or agreed to in writing, software
import javax.ejb.EJB; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.enterprise.context.Dependent; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.enterprise.inject.Produces; * See the License for the specific language governing permissions and
import javax.enterprise.inject.spi.Annotated; * limitations under the License.
import javax.enterprise.inject.spi.InjectionPoint; */
package de.muehlencord.shared.account.business.config.boundary;
/**
* import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationKey;
* @author Joern Muehlencord <joern at muehlencord.de> import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationValue;
*/ import de.muehlencord.shared.account.business.config.entity.ConfigException;
@Dependent import javax.ejb.EJB;
public class ConfigurationProducer { import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Produces;
@EJB import javax.enterprise.inject.spi.Annotated;
ConfigService configService; import javax.enterprise.inject.spi.InjectionPoint;
@Produces /**
@AccountConfigurationValue(key = AccountConfigurationKey.Producer) *
public String produceConfigurationValue(InjectionPoint injectionPoint) { * @author Joern Muehlencord <joern at muehlencord.de>
Annotated annotated = injectionPoint.getAnnotated(); */
AccountConfigurationValue annotation = annotated.getAnnotation(AccountConfigurationValue.class); @Dependent
if (annotation != null) { public class ConfigurationProducer {
AccountConfigurationKey key = annotation.key();
if (key != null) { @EJB
try { ConfigService configService;
switch (key) {
case BaseUrl: @Produces
return configService.getConfigValue("base.url"); @AccountConfigurationValue(key = AccountConfigurationKey.Producer)
case PasswordResetUrl: public String produceConfigurationValue(InjectionPoint injectionPoint) {
return configService.getConfigValue("base.url") + "/login.xhtml"; Annotated annotated = injectionPoint.getAnnotated();
default: AccountConfigurationValue annotation = annotated.getAnnotation(AccountConfigurationValue.class);
throw new IllegalStateException("Invalid key " + key + " for injection point: " + injectionPoint); if (annotation != null) {
} AccountConfigurationKey key = annotation.key();
} catch (ConfigException ex) { if (key != null) {
throw new IllegalStateException("Invalid key " + key + " for injection point: " + injectionPoint + ". Exception: " + ex.getMessage()); try {
} switch (key) {
} case BaseUrl:
} return configService.getConfigValue("base.url");
throw new IllegalStateException("No key for injection point: " + injectionPoint); case PasswordResetUrl:
} return configService.getConfigValue("base.url") + "/login.xhtml";
default:
} throw new IllegalStateException("Invalid key " + key + " for injection point: " + injectionPoint);
}
} catch (ConfigException ex) {
throw new IllegalStateException("Invalid key " + key + " for injection point: " + injectionPoint + ". Exception: " + ex.getMessage());
}
}
}
throw new IllegalStateException("No key for injection point: " + injectionPoint);
}
}

View File

@ -1,149 +1,159 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
*/ * you may not use this file except in compliance with the License.
package de.muehlencord.shared.account.business.config.entity; * You may obtain a copy of the License at
*
import de.muehlencord.shared.account.business.account.entity.AccountEntity; * http://www.apache.org/licenses/LICENSE-2.0
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity; *
import java.io.Serializable; * Unless required by applicable law or agreed to in writing, software
import javax.persistence.Cacheable; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.persistence.Column; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.persistence.EmbeddedId; * See the License for the specific language governing permissions and
import javax.persistence.Entity; * limitations under the License.
import javax.persistence.JoinColumn; */
import javax.persistence.ManyToOne; package de.muehlencord.shared.account.business.config.entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import de.muehlencord.shared.account.business.account.entity.AccountEntity;
import javax.persistence.QueryHint; import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
import javax.persistence.Table; import java.io.Serializable;
import javax.validation.constraints.Size; import javax.persistence.Cacheable;
import javax.xml.bind.annotation.XmlRootElement; import javax.persistence.Column;
import org.hibernate.annotations.Cache; import javax.persistence.EmbeddedId;
import org.hibernate.annotations.CacheConcurrencyStrategy; import javax.persistence.Entity;
import javax.persistence.JoinColumn;
/** import javax.persistence.ManyToOne;
* import javax.persistence.NamedQueries;
* @author Joern Muehlencord <joern at muehlencord.de> import javax.persistence.NamedQuery;
*/ import javax.persistence.QueryHint;
@Entity import javax.persistence.Table;
@Table(name = "config") import javax.validation.constraints.Size;
@XmlRootElement import javax.xml.bind.annotation.XmlRootElement;
@Cacheable(true) import org.hibernate.annotations.Cache;
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region = "Configuration") import org.hibernate.annotations.CacheConcurrencyStrategy;
@NamedQueries({
@NamedQuery(name = "ConfigEntity.findAll", query = "SELECT c FROM ConfigEntity c ORDER BY c.configPK.configKey", /**
hints = { *
@QueryHint(name = "org.hibernate.cacheable", value = "true"), * @author Joern Muehlencord <joern at muehlencord.de>
@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", @Entity
hints = { @Table(name = "config")
@QueryHint(name = "org.hibernate.cacheable", value = "true"), @XmlRootElement
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}), @Cacheable(true)
@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", @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region = "Configuration")
hints = { @NamedQueries({
@QueryHint(name = "org.hibernate.cacheable", value = "true"), @NamedQuery(name = "ConfigEntity.findAll", query = "SELECT c FROM ConfigEntity c ORDER BY c.configPK.configKey",
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}), hints = {
@NamedQuery(name = "ConfigEntity.findByConfigValue", query = "SELECT c FROM ConfigEntity c WHERE c.configPK.application = :application AND c.configValue = :configValue", @QueryHint(name = "org.hibernate.cacheable", value = "true"),
hints = { @QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}),
@QueryHint(name = "org.hibernate.cacheable", value = "true"), @NamedQuery(name = "ConfigEntity.findByConfigKey", query = "SELECT c FROM ConfigEntity c WHERE c.configPK.application = :application AND c.configPK.configKey = :configKey",
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}) hints = {
}) @QueryHint(name = "org.hibernate.cacheable", value = "true"),
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}),
public class ConfigEntity implements Serializable { @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 = {
private static final long serialVersionUID = -2013982316933782223L; @QueryHint(name = "org.hibernate.cacheable", value = "true"),
@QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")}),
@EmbeddedId @NamedQuery(name = "ConfigEntity.findByConfigValue", query = "SELECT c FROM ConfigEntity c WHERE c.configPK.application = :application AND c.configValue = :configValue",
protected ConfigEntityPK configPK; hints = {
@Size(max = 200) @QueryHint(name = "org.hibernate.cacheable", value = "true"),
@Column(name = "config_value") @QueryHint(name = "org.hibernate.cacheRegion", value = "Queries")})
private String configValue; })
@Size(max = 200)
@Column(name = "config_key_group") public class ConfigEntity implements Serializable {
private String configKeyGroup;
@JoinColumn(name = "config_key_account", referencedColumnName = "id", insertable = false, updatable = false) private static final long serialVersionUID = -2013982316933782223L;
@ManyToOne(optional = false)
private AccountEntity account; @EmbeddedId
@JoinColumn(name = "application", referencedColumnName = "id", insertable = false, updatable = false) protected ConfigEntityPK configPK;
@ManyToOne(optional = false) @Size(max = 200)
private ApplicationEntity application; @Column(name = "config_value")
private String configValue;
public ConfigEntity() { @Size(max = 200)
} @Column(name = "config_key_group")
private String configKeyGroup;
public ConfigEntity(ApplicationEntity application, String configKey, AccountEntity account) { @JoinColumn(name = "config_key_account", referencedColumnName = "id", insertable = false, updatable = false)
this.configPK = new ConfigEntityPK(application, configKey, account); @ManyToOne(optional = false)
} private AccountEntity account;
@JoinColumn(name = "application", referencedColumnName = "id", insertable = false, updatable = false)
public ConfigEntity(ConfigEntityPK configPK) { @ManyToOne(optional = false)
this.configPK = configPK; private ApplicationEntity application;
}
public ConfigEntity() {
public ConfigEntityPK getConfigPK() { }
return configPK;
} public ConfigEntity(ApplicationEntity application, String configKey, AccountEntity account) {
this.configPK = new ConfigEntityPK(application, configKey, account);
public void setConfigPK(ConfigEntityPK configPK) { }
this.configPK = configPK;
} public ConfigEntity(ConfigEntityPK configPK) {
this.configPK = configPK;
public String getConfigValue() { }
return configValue;
} public ConfigEntityPK getConfigPK() {
return configPK;
public void setConfigValue(String configValue) { }
this.configValue = configValue;
} public void setConfigPK(ConfigEntityPK configPK) {
this.configPK = configPK;
public String getConfigKeyGroup() { }
return configKeyGroup;
} public String getConfigValue() {
return configValue;
public void setConfigKeyGroup(String configKeyGroup) { }
this.configKeyGroup = configKeyGroup;
} public void setConfigValue(String configValue) {
this.configValue = configValue;
@Override }
public int hashCode() {
int hash = 0; public String getConfigKeyGroup() {
hash += (configPK != null ? configPK.hashCode() : 0); return configKeyGroup;
return hash; }
}
public void setConfigKeyGroup(String configKeyGroup) {
@Override this.configKeyGroup = configKeyGroup;
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)) { @Override
return false; public int hashCode() {
} int hash = 0;
ConfigEntity other = (ConfigEntity) object; hash += (configPK != null ? configPK.hashCode() : 0);
if ((this.configPK == null && other.configPK != null) || (this.configPK != null && !this.configPK.equals(other.configPK))) { return hash;
return false; }
}
return true; @Override
} public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
@Override if (!(object instanceof ConfigEntity)) {
public String toString() { return false;
return "de.muehlencord.shared.account.business.config.entity.Config[ configPK=" + configPK + " ]"; }
} ConfigEntity other = (ConfigEntity) object;
if ((this.configPK == null && other.configPK != null) || (this.configPK != null && !this.configPK.equals(other.configPK))) {
public AccountEntity getAccount() { return false;
return account; }
} return true;
}
public void setAccount(AccountEntity account) {
this.account = account; @Override
} public String toString() {
return "de.muehlencord.shared.account.business.config.entity.Config[ configPK=" + configPK + " ]";
public ApplicationEntity getApplication() { }
return application;
} public AccountEntity getAccount() {
return account;
public void setApplication(ApplicationEntity application) { }
this.application = application;
} public void setAccount(AccountEntity account) {
this.account = account;
} }
public ApplicationEntity getApplication() {
return application;
}
public void setApplication(ApplicationEntity application) {
this.application = application;
}
}

View File

@ -1,7 +1,17 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package de.muehlencord.shared.account.business.config.entity; package de.muehlencord.shared.account.business.config.entity;

View File

@ -1,7 +1,17 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package de.muehlencord.shared.account.business.config.entity; package de.muehlencord.shared.account.business.config.entity;

View File

@ -1,203 +1,218 @@
package de.muehlencord.shared.account.business.mail.boundary; /*
* Copyright 2018 joern.muehlencord.
import de.muehlencord.shared.account.business.mail.entity.MailTemplateException; *
import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationKey; * Licensed under the Apache License, Version 2.0 (the "License");
import de.muehlencord.shared.account.business.account.entity.AccountEntity; * you may not use this file except in compliance with the License.
import de.muehlencord.shared.account.business.account.entity.AccountLoginEntity; * You may obtain a copy of the License at
import de.muehlencord.shared.account.business.mail.entity.MailDatamodel; *
import de.muehlencord.shared.account.business.mail.entity.MailException; * http://www.apache.org/licenses/LICENSE-2.0
import java.util.Date; *
import java.util.UUID; * Unless required by applicable law or agreed to in writing, software
import javax.annotation.Resource; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.ejb.EJB; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.ejb.Stateless; * See the License for the specific language governing permissions and
import javax.inject.Inject; * limitations under the License.
import javax.mail.Message; */
import javax.mail.MessagingException; package de.muehlencord.shared.account.business.mail.boundary;
import javax.mail.Multipart;
import javax.mail.Session; import de.muehlencord.shared.account.business.mail.entity.MailTemplateException;
import javax.mail.Transport; import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationKey;
import javax.mail.internet.InternetAddress; import de.muehlencord.shared.account.business.account.entity.AccountEntity;
import javax.mail.internet.MimeBodyPart; import de.muehlencord.shared.account.business.account.entity.AccountLoginEntity;
import javax.mail.internet.MimeMessage; import de.muehlencord.shared.account.business.mail.entity.MailDatamodel;
import javax.mail.internet.MimeMultipart; import de.muehlencord.shared.account.business.mail.entity.MailException;
import org.slf4j.Logger; import java.util.Date;
import org.slf4j.LoggerFactory; import java.util.UUID;
import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationValue; import javax.annotation.Resource;
import java.io.File; import javax.ejb.EJB;
import java.io.IOException; import javax.ejb.Stateless;
import java.io.Serializable; import javax.inject.Inject;
import java.nio.file.Files; import javax.mail.Message;
import java.util.ArrayList; import javax.mail.MessagingException;
import java.util.List; import javax.mail.Multipart;
import javax.mail.Session;
/** import javax.mail.Transport;
* import javax.mail.internet.InternetAddress;
* @author joern.muehlencord import javax.mail.internet.MimeBodyPart;
*/ import javax.mail.internet.MimeMessage;
@Stateless import javax.mail.internet.MimeMultipart;
public class MailService implements Serializable { import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final long serialVersionUID = -1937218474908356747L; import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationValue;
import java.io.File;
private static final Logger LOGGER = LoggerFactory.getLogger(MailService.class); import java.io.IOException;
import java.io.Serializable;
@EJB import java.nio.file.Files;
private MailTemplateService mailTemplateService; import java.util.ArrayList;
import java.util.List;
@Inject
@AccountConfigurationValue(key = AccountConfigurationKey.BaseUrl) /**
private String baseUrl; *
* @author joern.muehlencord
@Inject */
@AccountConfigurationValue(key = AccountConfigurationKey.PasswordResetUrl) @Stateless
private String passwordResetUrl; public class MailService implements Serializable {
// TODO make this configurable by injection from the application it uses it, fall back to defaul mail setup if not available private static final long serialVersionUID = -1937218474908356747L;
@Resource(lookup = "java:jboss/mail/ssgMail")
private Session mailSession; private static final Logger LOGGER = LoggerFactory.getLogger(MailService.class);
public String sendTestEmail(String recipient) throws MailException { @EJB
return sendMail(recipient, "Test email", "This is a test email"); private MailTemplateService mailTemplateService;
}
@Inject
public String sendTestHtmlEmail(String recipient) throws MailException { @AccountConfigurationValue(key = AccountConfigurationKey.BaseUrl)
Date now = new Date(); private String baseUrl;
AccountEntity account = new AccountEntity();
account.setId (UUID.randomUUID()); @Inject
account.setFirstname("Jörn"); @AccountConfigurationValue(key = AccountConfigurationKey.PasswordResetUrl)
account.setLastname ("Mühlencord"); private String passwordResetUrl;
AccountLoginEntity accountLogin = new AccountLoginEntity();
accountLogin.setAccountPassword("secret"); // TODO make this configurable by injection from the application it uses it, fall back to defaul mail setup if not available
accountLogin.setAccount(account); @Resource(lookup = "java:jboss/mail/ssgMail")
account.setAccountLogin(accountLogin); private Session mailSession;
MailDatamodel dataModel = new MailDatamodel(account);
dataModel.addParameter("url", "http://url.de"); public String sendTestEmail(String recipient) throws MailException {
dataModel.addParameter("resetUrl", "http://reseturl.de"); return sendMail(recipient, "Test email", "This is a test email");
return sendHTMLMail(recipient, "Test HTML Email", dataModel, "password_reset_html"); }
}
public String sendTestHtmlEmail(String recipient) throws MailException {
public String sendMail(String recipient, String subject, String body) throws MailException { Date now = new Date();
try { AccountEntity account = new AccountEntity();
MimeMessage message = new MimeMessage(mailSession); account.setId (UUID.randomUUID());
message.setSubject(subject, "UTF-8"); account.setFirstname("Jörn");
message.setFrom(); account.setLastname ("Mühlencord");
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient, false)); AccountLoginEntity accountLogin = new AccountLoginEntity();
message.setText(body, "UTF-8"); accountLogin.setAccountPassword("secret");
return transportMail(message); accountLogin.setAccount(account);
} catch (MessagingException ex) { account.setAccountLogin(accountLogin);
throw new MailException("Error while sending email.", ex); MailDatamodel dataModel = new MailDatamodel(account);
} dataModel.addParameter("url", "http://url.de");
} dataModel.addParameter("resetUrl", "http://reseturl.de");
return sendHTMLMail(recipient, "Test HTML Email", dataModel, "password_reset_html");
public String sendHTMLMail(String recipient, String subject, MailDatamodel dataModel, String templateName) throws MailException { }
return sendHTMLMail(recipient, subject, dataModel, templateName, null);
} public String sendMail(String recipient, String subject, String body) throws MailException {
try {
public String sendHTMLMail(String recipient, String subject, MailDatamodel dataModel, String htmlTemplateName, String plainTemplateName) throws MailException { MimeMessage message = new MimeMessage(mailSession);
return sendHTMLMail(recipient, null, null, subject, dataModel, htmlTemplateName, plainTemplateName, "UTF-8", new ArrayList<>()); message.setSubject(subject, "UTF-8");
} message.setFrom();
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient, false));
public String sendHTMLMail(String recipient, String ccRecipient, String bccRecipient, String subject, MailDatamodel dataModel, String htmlTemplateName, String plainTemplateName) throws MailException { message.setText(body, "UTF-8");
return sendHTMLMail(recipient, ccRecipient, bccRecipient, subject, dataModel, htmlTemplateName, plainTemplateName, "UTF-8", new ArrayList<>()); return transportMail(message);
} } catch (MessagingException ex) {
throw new MailException("Error while sending email.", ex);
public String sendHTMLMail(String recipient, String ccRecipient, String bccRecipient, String subject, }
MailDatamodel dataModel, String htmlTemplateName, String plainTemplateName, String encoding, List<File> attachments) throws MailException { }
try {
MimeMessage message = new MimeMessage(mailSession); public String sendHTMLMail(String recipient, String subject, MailDatamodel dataModel, String templateName) throws MailException {
message.setFrom(); // use default from return sendHTMLMail(recipient, subject, dataModel, templateName, null);
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient, false)); }
if (ccRecipient != null) {
message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(ccRecipient, false)); public String sendHTMLMail(String recipient, String subject, MailDatamodel dataModel, String htmlTemplateName, String plainTemplateName) throws MailException {
} return sendHTMLMail(recipient, null, null, subject, dataModel, htmlTemplateName, plainTemplateName, "UTF-8", new ArrayList<>());
if (bccRecipient != null) { }
message.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bccRecipient, false));
} public String sendHTMLMail(String recipient, String ccRecipient, String bccRecipient, String subject, MailDatamodel dataModel, String htmlTemplateName, String plainTemplateName) throws MailException {
return sendHTMLMail(recipient, ccRecipient, bccRecipient, subject, dataModel, htmlTemplateName, plainTemplateName, "UTF-8", new ArrayList<>());
message.setSubject(subject, encoding); }
Multipart contentMultiPart = new MimeMultipart("alternative"); public String sendHTMLMail(String recipient, String ccRecipient, String bccRecipient, String subject,
MailDatamodel dataModel, String htmlTemplateName, String plainTemplateName, String encoding, List<File> attachments) throws MailException {
String htmlBody = mailTemplateService.getStringFromTemplate(htmlTemplateName, dataModel); try {
MimeBodyPart htmlBodyPart = new MimeBodyPart(); MimeMessage message = new MimeMessage(mailSession);
htmlBodyPart.setContent(htmlBody, "text/html; charset=UTF-8"); message.setFrom(); // use default from
contentMultiPart.addBodyPart(htmlBodyPart); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient, false));
if (ccRecipient != null) {
if (plainTemplateName != null) { message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(ccRecipient, false));
String plainBody = mailTemplateService.getStringFromTemplate(plainTemplateName, dataModel); }
MimeBodyPart plainBodyPart = new MimeBodyPart(); if (bccRecipient != null) {
plainBodyPart.setText(plainBody, "UTF-8"); message.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bccRecipient, false));
contentMultiPart.addBodyPart(plainBodyPart); }
}
message.setSubject(subject, encoding);
if ((attachments == null) || (attachments.isEmpty())) { Multipart contentMultiPart = new MimeMultipart("alternative");
message.setContent(contentMultiPart);
} else { String htmlBody = mailTemplateService.getStringFromTemplate(htmlTemplateName, dataModel);
MimeBodyPart contentBodyPart = new MimeBodyPart(); MimeBodyPart htmlBodyPart = new MimeBodyPart();
contentBodyPart.setContent(contentMultiPart); htmlBodyPart.setContent(htmlBody, "text/html; charset=UTF-8");
contentMultiPart.addBodyPart(htmlBodyPart);
MimeMultipart messageMultipart = new MimeMultipart("related");
messageMultipart.addBodyPart(contentBodyPart); if (plainTemplateName != null) {
for (File attachment : attachments) { String plainBody = mailTemplateService.getStringFromTemplate(plainTemplateName, dataModel);
try { MimeBodyPart plainBodyPart = new MimeBodyPart();
MimeBodyPart attachmentBodyPart = new MimeBodyPart(); plainBodyPart.setText(plainBody, "UTF-8");
attachmentBodyPart.attachFile(attachment); contentMultiPart.addBodyPart(plainBodyPart);
String contentType = Files.probeContentType(attachment.toPath()); }
if (contentType != null) {
attachmentBodyPart.setHeader("Content-Type", contentType);
} if ((attachments == null) || (attachments.isEmpty())) {
messageMultipart.addBodyPart(attachmentBodyPart); message.setContent(contentMultiPart);
} catch (IOException ex) { } else {
throw new MailException("Cannot attach " + attachment.toString() + " to email. Reason: " + ex.toString(), ex); MimeBodyPart contentBodyPart = new MimeBodyPart();
} contentBodyPart.setContent(contentMultiPart);
}
MimeMultipart messageMultipart = new MimeMultipart("related");
message.setContent (messageMultipart); messageMultipart.addBodyPart(contentBodyPart);
} for (File attachment : attachments) {
try {
return transportMail(message); MimeBodyPart attachmentBodyPart = new MimeBodyPart();
} catch (MessagingException | MailTemplateException ex) { attachmentBodyPart.attachFile(attachment);
throw new MailException("Error while sending email.", ex); String contentType = Files.probeContentType(attachment.toPath());
} if (contentType != null) {
} attachmentBodyPart.setHeader("Content-Type", contentType);
}
public String sendPasswortResetStartEmail(AccountEntity account, String token) throws MailException { messageMultipart.addBodyPart(attachmentBodyPart);
MailDatamodel model = new MailDatamodel(account); } catch (IOException ex) {
throw new MailException("Cannot attach " + attachment.toString() + " to email. Reason: " + ex.toString(), ex);
/* old aproach via FacesContext - add this back as fallback if injection point if not configured }
try { }
// String absoluteWebPath = FacesContext.getCurrentInstance().getExternalContext().getApplicationContextPath();
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); message.setContent (messageMultipart);
String resetPage = "/login.xhtml?token=" + token; }
URL baseUrl;
return transportMail(message);
// TODO move out of this class, this is not mandatorily connected to a form } catch (MessagingException | MailTemplateException ex) {
baseUrl = new URL(externalContext.getRequestScheme(), throw new MailException("Error while sending email.", ex);
externalContext.getRequestServerName(), }
externalContext.getRequestServerPort(), }
externalContext.getRequestContextPath());
model.addParameter("url", baseUrl.toString()); public String sendPasswortResetStartEmail(AccountEntity account, String token) throws MailException {
model.addParameter("resetUrl", baseUrl.toString() + resetPage); MailDatamodel model = new MailDatamodel(account);
} catch (MalformedURLException ex) {
throw new MailException("Error while sending email.", ex); /* old aproach via FacesContext - add this back as fallback if injection point if not configured
} try {
String baseUrl = configService.getConfigValue(configKey); // String absoluteWebPath = FacesContext.getCurrentInstance().getExternalContext().getApplicationContextPath();
String resetUrlWithToken = baseUrl + "/login.xhtml?token=" + token; ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
*/ String resetPage = "/login.xhtml?token=" + token;
String resetUrlWithToken = passwordResetUrl + "?token=" + token; URL baseUrl;
model.addParameter("url", baseUrl);
model.addParameter("resetUrl", resetUrlWithToken); // TODO move out of this class, this is not mandatorily connected to a form
return sendHTMLMail(account.getEmailaddress(), "Reset your password", model, "password_reset_html"); baseUrl = new URL(externalContext.getRequestScheme(),
} externalContext.getRequestServerName(),
externalContext.getRequestServerPort(),
private String transportMail(Message message) throws MessagingException { externalContext.getRequestContextPath());
message.setSentDate(new Date()); model.addParameter("url", baseUrl.toString());
Transport.send(message); model.addParameter("resetUrl", baseUrl.toString() + resetPage);
String messageId = message.getHeader("Message-ID")[0]; } catch (MalformedURLException ex) {
LOGGER.info("Mail sent to {}, messageid = {}", message.getAllRecipients()[0].toString(), messageId); throw new MailException("Error while sending email.", ex);
return messageId; }
String baseUrl = configService.getConfigValue(configKey);
} String resetUrlWithToken = baseUrl + "/login.xhtml?token=" + token;
} */
String resetUrlWithToken = passwordResetUrl + "?token=" + token;
model.addParameter("url", baseUrl);
model.addParameter("resetUrl", resetUrlWithToken);
return sendHTMLMail(account.getEmailaddress(), "Reset your password", model, "password_reset_html");
}
private String transportMail(Message message) throws MessagingException {
message.setSentDate(new Date());
Transport.send(message);
String messageId = message.getHeader("Message-ID")[0];
LOGGER.info("Mail sent to {}, messageid = {}", message.getAllRecipients()[0].toString(), messageId);
return messageId;
}
}

View File

@ -1,3 +1,18 @@
/*
* Copyright 2018 joern.muehlencord.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.business.mail.boundary; package de.muehlencord.shared.account.business.mail.boundary;
import de.muehlencord.shared.account.business.mail.entity.MailDatamodel; import de.muehlencord.shared.account.business.mail.entity.MailDatamodel;

View File

@ -1,40 +1,55 @@
package de.muehlencord.shared.account.business.mail.entity; /*
* Copyright 2018 joern.muehlencord.
import de.muehlencord.shared.account.business.account.entity.AccountEntity; *
import java.util.HashMap; * Licensed under the Apache License, Version 2.0 (the "License");
import java.util.Map; * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
/** *
* * http://www.apache.org/licenses/LICENSE-2.0
* @author jomu *
*/ * Unless required by applicable law or agreed to in writing, software
public class MailDatamodel { * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
private final AccountEntity account; * See the License for the specific language governing permissions and
private final Map<String,Object> parameter; * limitations under the License.
*/
public MailDatamodel() { package de.muehlencord.shared.account.business.mail.entity;
this.account = null;
this.parameter = new HashMap<>(); import de.muehlencord.shared.account.business.account.entity.AccountEntity;
} import java.util.HashMap;
import java.util.Map;
public MailDatamodel(AccountEntity account) {
this.parameter = new HashMap<>(); /**
this.account = account; *
} * @author jomu
*/
public void addParameter(String name, Object value) { public class MailDatamodel {
this.parameter.put(name, value);
} private final AccountEntity account;
private final Map<String,Object> parameter;
/* **** getter / setter **** */ public MailDatamodel() {
this.account = null;
public AccountEntity getAccount() { this.parameter = new HashMap<>();
return account; }
}
public MailDatamodel(AccountEntity account) {
public Map<String, Object> getParameter() { this.parameter = new HashMap<>();
return parameter; this.account = account;
} }
}
public void addParameter(String name, Object value) {
this.parameter.put(name, value);
}
/* **** getter / setter **** */
public AccountEntity getAccount() {
return account;
}
public Map<String, Object> getParameter() {
return parameter;
}
}

View File

@ -1,36 +1,51 @@
package de.muehlencord.shared.account.business.mail.entity; /*
* Copyright 2018 joern.muehlencord.
/** *
* * Licensed under the Apache License, Version 2.0 (the "License");
* @author Raimund * you may not use this file except in compliance with the License.
*/ * You may obtain a copy of the License at
public class MailException extends Exception { *
* http://www.apache.org/licenses/LICENSE-2.0
/** *
* Creates a new instance of <code>MailException</code> without detail * Unless required by applicable law or agreed to in writing, software
* message. * distributed under the License is distributed on an "AS IS" BASIS,
*/ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
public MailException() { * See the License for the specific language governing permissions and
} * limitations under the License.
*/
/** package de.muehlencord.shared.account.business.mail.entity;
* Constructs an instance of <code>MailException</code> with the specified
* detail message. /**
* *
* @param msg the detail message. * @author Raimund
*/ */
public MailException(String msg) { public class MailException extends Exception {
super(msg);
} /**
* Creates a new instance of <code>MailException</code> without detail
/** * message.
* Constructs an instance of <code>MailException</code> with the specified */
* detail message. public MailException() {
* }
* @param msg the detail message.
* @param th the root cause /**
*/ * Constructs an instance of <code>MailException</code> with the specified
public MailException(String msg, Throwable th) { * detail message.
super(msg, th); *
} * @param msg the detail message.
} */
public MailException(String msg) {
super(msg);
}
/**
* Constructs an instance of <code>MailException</code> with the specified
* detail message.
*
* @param msg the detail message.
* @param th the root cause
*/
public MailException(String msg, Throwable th) {
super(msg, th);
}
}

View File

@ -1,95 +1,110 @@
package de.muehlencord.shared.account.business.mail.entity; /*
* Copyright 2018 joern.muehlencord.
import java.io.Serializable; *
import javax.persistence.Basic; * Licensed under the Apache License, Version 2.0 (the "License");
import javax.persistence.Column; * you may not use this file except in compliance with the License.
import javax.persistence.Entity; * You may obtain a copy of the License at
import javax.persistence.Id; *
import javax.persistence.NamedQueries; * http://www.apache.org/licenses/LICENSE-2.0
import javax.persistence.NamedQuery; *
import javax.persistence.Table; * Unless required by applicable law or agreed to in writing, software
import javax.validation.constraints.NotNull; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.validation.constraints.Size; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.xml.bind.annotation.XmlRootElement; * See the License for the specific language governing permissions and
* limitations under the License.
/** */
* package de.muehlencord.shared.account.business.mail.entity;
* @author joern.muehlencord
*/ import java.io.Serializable;
@Entity import javax.persistence.Basic;
@Table(name = "mail_template") import javax.persistence.Column;
@XmlRootElement import javax.persistence.Entity;
@NamedQueries({ import javax.persistence.Id;
@NamedQuery(name = "MailTemplateEntity.findAll", query = "SELECT m FROM MailTemplateEntity m"), import javax.persistence.NamedQueries;
@NamedQuery(name = "MailTemplateEntity.findByTemplateName", query = "SELECT m FROM MailTemplateEntity m WHERE m.templateName = :templateName"), import javax.persistence.NamedQuery;
@NamedQuery(name = "MailTemplateEntity.findByTemplateValue", query = "SELECT m FROM MailTemplateEntity m WHERE m.templateValue = :templateValue")}) import javax.persistence.Table;
public class MailTemplateEntity implements Serializable { import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
private static final long serialVersionUID = 4527399247302581555L; import javax.xml.bind.annotation.XmlRootElement;
@Id /**
@Basic(optional = false) *
@NotNull * @author joern.muehlencord
@Size(min = 1, max = 40) */
@Column(name = "template_name") @Entity
private String templateName; @Table(name = "mail_template")
@Basic(optional = false) @XmlRootElement
@NotNull @NamedQueries({
@Size(min = 1, max = 2147483647) @NamedQuery(name = "MailTemplateEntity.findAll", query = "SELECT m FROM MailTemplateEntity m"),
@Column(name = "template_value") @NamedQuery(name = "MailTemplateEntity.findByTemplateName", query = "SELECT m FROM MailTemplateEntity m WHERE m.templateName = :templateName"),
private String templateValue; @NamedQuery(name = "MailTemplateEntity.findByTemplateValue", query = "SELECT m FROM MailTemplateEntity m WHERE m.templateValue = :templateValue")})
public class MailTemplateEntity implements Serializable {
public MailTemplateEntity() {
} private static final long serialVersionUID = 4527399247302581555L;
public MailTemplateEntity(String templateName) { @Id
this.templateName = templateName; @Basic(optional = false)
} @NotNull
@Size(min = 1, max = 40)
public MailTemplateEntity(String templateName, String templateValue) { @Column(name = "template_name")
this.templateName = templateName; private String templateName;
this.templateValue = templateValue; @Basic(optional = false)
} @NotNull
@Size(min = 1, max = 2147483647)
public String getTemplateName() { @Column(name = "template_value")
return templateName; private String templateValue;
}
public MailTemplateEntity() {
public void setTemplateName(String templateName) { }
this.templateName = templateName;
} public MailTemplateEntity(String templateName) {
this.templateName = templateName;
public String getTemplateValue() { }
return templateValue;
} public MailTemplateEntity(String templateName, String templateValue) {
this.templateName = templateName;
public void setTemplateValue(String templateValue) { this.templateValue = templateValue;
this.templateValue = templateValue; }
}
public String getTemplateName() {
@Override return templateName;
public int hashCode() { }
int hash = 0;
hash += (templateName != null ? templateName.hashCode() : 0); public void setTemplateName(String templateName) {
return hash; this.templateName = templateName;
} }
@Override public String getTemplateValue() {
public boolean equals(Object object) { return templateValue;
// TODO: Warning - this method won't work in the case the id fields are not set }
if (!(object instanceof MailTemplateEntity)) {
return false; public void setTemplateValue(String templateValue) {
} this.templateValue = templateValue;
MailTemplateEntity other = (MailTemplateEntity) object; }
if ((this.templateName == null && other.templateName != null) || (this.templateName != null && !this.templateName.equals(other.templateName))) {
return false; @Override
} public int hashCode() {
return true; int hash = 0;
} hash += (templateName != null ? templateName.hashCode() : 0);
return hash;
@Override }
public String toString() {
return "de.muehlencord.shared.account.entity.MailTemplate[ templateName=" + templateName + " ]"; @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 MailTemplateEntity)) {
return false;
}
MailTemplateEntity other = (MailTemplateEntity) object;
if ((this.templateName == null && other.templateName != null) || (this.templateName != null && !this.templateName.equals(other.templateName))) {
return false;
}
return true;
}
@Override
public String toString() {
return "de.muehlencord.shared.account.entity.MailTemplate[ templateName=" + templateName + " ]";
}
}

View File

@ -1,37 +1,52 @@
package de.muehlencord.shared.account.business.mail.entity; /*
* Copyright 2018 joern.muehlencord.
/** *
* * Licensed under the Apache License, Version 2.0 (the "License");
* @author jomu * you may not use this file except in compliance with the License.
*/ * You may obtain a copy of the License at
public class MailTemplateException extends Exception { *
* http://www.apache.org/licenses/LICENSE-2.0
/** *
* Creates a new instance of <code>MailTemplateException</code> without * Unless required by applicable law or agreed to in writing, software
* detail message. * distributed under the License is distributed on an "AS IS" BASIS,
*/ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
public MailTemplateException() { * See the License for the specific language governing permissions and
} * limitations under the License.
*/
/** package de.muehlencord.shared.account.business.mail.entity;
* Constructs an instance of <code>MailTemplateException</code> with the
* specified detail message. /**
* *
* @param msg the detail message. * @author jomu
*/ */
public MailTemplateException(String msg) { public class MailTemplateException extends Exception {
super(msg);
} /**
* Creates a new instance of <code>MailTemplateException</code> without
/** * detail message.
* Constructs an instance of <code>MailTemplateException</code> with the */
* specified detail message. public MailTemplateException() {
* }
* @param msg the detail message.
* @param th the root cause /**
*/ * Constructs an instance of <code>MailTemplateException</code> with the
public MailTemplateException(String msg, Throwable th) { * specified detail message.
super(msg, th); *
} * @param msg the detail message.
*/
} public MailTemplateException(String msg) {
super(msg);
}
/**
* Constructs an instance of <code>MailTemplateException</code> with the
* specified detail message.
*
* @param msg the detail message.
* @param th the root cause
*/
public MailTemplateException(String msg, Throwable th) {
super(msg, th);
}
}

View File

@ -1,185 +1,200 @@
package de.muehlencord.shared.account.presentation; /*
* Copyright 2018 joern.muehlencord.
import de.muehlencord.shared.account.business.account.control.AccountControl; *
import de.muehlencord.shared.account.business.account.entity.AccountEntity; * Licensed under the Apache License, Version 2.0 (the "License");
import de.muehlencord.shared.jeeutil.FacesUtil; * you may not use this file except in compliance with the License.
import java.io.IOException; * You may obtain a copy of the License at
import java.io.Serializable; *
import javax.ejb.EJB; * http://www.apache.org/licenses/LICENSE-2.0
import javax.faces.context.ExternalContext; *
import javax.faces.context.FacesContext; * Unless required by applicable law or agreed to in writing, software
import javax.faces.view.ViewScoped; * distributed under the License is distributed on an "AS IS" BASIS,
import javax.inject.Named; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.naming.NamingException; * See the License for the specific language governing permissions and
* limitations under the License.
import javax.servlet.ServletRequest; */
import javax.servlet.ServletResponse; package de.muehlencord.shared.account.presentation;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.SecurityUtils; import de.muehlencord.shared.account.business.account.control.AccountControl;
import org.apache.shiro.authc.AuthenticationException; import de.muehlencord.shared.account.business.account.entity.AccountEntity;
import org.apache.shiro.authc.UsernamePasswordToken; import de.muehlencord.shared.jeeutil.FacesUtil;
import org.apache.shiro.web.util.WebUtils; import java.io.IOException;
import org.slf4j.Logger; import java.io.Serializable;
import org.slf4j.LoggerFactory; import javax.ejb.EJB;
import javax.faces.context.ExternalContext;
/** import javax.faces.context.FacesContext;
* import javax.faces.view.ViewScoped;
* @author joern.muehlencord import javax.inject.Named;
*/ import javax.naming.NamingException;
@Named(value = "loginView")
@ViewScoped import javax.servlet.ServletRequest;
public class LoginView implements Serializable { import javax.servlet.ServletResponse;
import org.apache.shiro.subject.Subject;
private static final long serialVersionUID = -1164860380769648432L; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
@EJB import org.apache.shiro.authc.UsernamePasswordToken;
private AccountControl accountService; import org.apache.shiro.web.util.WebUtils;
import org.slf4j.Logger;
private String username = null; import org.slf4j.LoggerFactory;
private String password = null;
private boolean rememberMe = false; /**
*
private String resetPasswordToken = null; * @author joern.muehlencord
*/
private static final Logger LOGGER = LoggerFactory.getLogger(LoginView.class.getName()); @Named(value = "loginView")
@ViewScoped
public void authenticate() { public class LoginView implements Serializable {
// Example using most common scenario of username/password pair: private static final long serialVersionUID = -1164860380769648432L;
UsernamePasswordToken token = new UsernamePasswordToken(getUsername(), getPassword());
@EJB
// "Remember Me" built-in: private AccountControl accountService;
token.setRememberMe(rememberMe);
Subject currentUser = SecurityUtils.getSubject(); private String username = null;
LOGGER.info("Trying to login user {}", username); private String password = null;
private boolean rememberMe = false;
try {
currentUser.login(token); private String resetPasswordToken = null;
LOGGER.info("User {} logged in", username);
// user logged in, update account entity private static final Logger LOGGER = LoggerFactory.getLogger(LoginView.class.getName());
AccountEntity account = accountService.getAccountEntity(username, true);
accountService.updateLogin(account); public void authenticate() {
// redirect to home // Example using most common scenario of username/password pair:
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext(); UsernamePasswordToken token = new UsernamePasswordToken(getUsername(), getPassword());
ServletResponse servletResponse = (ServletResponse) ec.getResponse();
String fallbackUrl = "/web/index.xhtml"; // TODO make configurable // "Remember Me" built-in:
// ec.redirect(url); token.setRememberMe(rememberMe);
if (LOGGER.isTraceEnabled()) { Subject currentUser = SecurityUtils.getSubject();
LOGGER.trace("redirecting to {}, fallbackUrl={}", servletResponse.toString(), fallbackUrl); LOGGER.info("Trying to login user {}", username);
}
try {
WebUtils.redirectToSavedRequest((ServletRequest) ec.getRequest(), servletResponse, fallbackUrl); currentUser.login(token);
} catch (IOException | AuthenticationException ex) { LOGGER.info("User {} logged in", username);
// Could catch a subclass of AuthenticationException if you like // user logged in, update account entity
String hint = "Error while authenticating user " + username; AccountEntity account = accountService.getAccountEntity(username, true);
if (LOGGER.isDebugEnabled()) { accountService.updateLogin(account);
LOGGER.debug(hint, ex);
} // redirect to home
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
if (ex.getMessage() != null) { ServletResponse servletResponse = (ServletResponse) ec.getResponse();
hint += "Reason: " + ex.getMessage(); String fallbackUrl = "/web/index.xhtml"; // TODO make configurable
} else { // ec.redirect(url);
hint += "Reason: " + ex.toString(); if (LOGGER.isTraceEnabled()) {
} LOGGER.trace("redirecting to {}, fallbackUrl={}", servletResponse.toString(), fallbackUrl);
if ((ex.getCause() != null) && (ex.getCause().getMessage() != null)) { }
hint += "Rootcause: " + ex.getMessage();
WebUtils.redirectToSavedRequest((ServletRequest) ec.getRequest(), servletResponse, fallbackUrl);
LOGGER.error(hint); } catch (IOException | AuthenticationException ex) {
} // Could catch a subclass of AuthenticationException if you like
FacesUtil.addGlobalErrorMessage("Login failed", hint); String hint = "Error while authenticating user " + username;
if (LOGGER.isDebugEnabled()) {
AccountEntity account = accountService.getAccountEntity(username, false); LOGGER.debug(hint, ex);
if (account != null) { }
accountService.addLoginError(account);
} if (ex.getMessage() != null) {
} finally { hint += "Reason: " + ex.getMessage();
token.clear(); } else {
} hint += "Reason: " + ex.toString();
} }
if ((ex.getCause() != null) && (ex.getCause().getMessage() != null)) {
public void logout() { hint += "Rootcause: " + ex.getMessage();
Subject currentUser = SecurityUtils.getSubject();
try { LOGGER.error(hint);
currentUser.logout(); }
FacesUtil.addGlobalErrorMessage("Login failed", hint);
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
AccountEntity account = accountService.getAccountEntity(username, false);
// check if redirect shall be executed if (account != null) {
// default setting is yes to /login.xhtml accountService.addLoginError(account);
// can be overwritten using parameters }
// de.muehlencord.shared.account.loginview.executeredirect boolean true/false } finally {
// de.muehlencord.shared.account.loginview.redirecttarget path to redirect to (without external context, will be added automatically) token.clear();
String executeRedirectString = ec.getInitParameter("de.muehlencord.shared.account.loginview.executeredirect"); }
boolean executeRedirect = true; }
if (executeRedirectString != null) {
executeRedirect = Boolean.parseBoolean(executeRedirectString); public void logout() {
} Subject currentUser = SecurityUtils.getSubject();
try {
String redirectTarget = ec.getInitParameter("de.muehlencord.shared.account.loginview.redirecttarget"); currentUser.logout();
if ((redirectTarget == null) || (redirectTarget.equals(""))) {
redirectTarget = "/login.xhtml"; ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
}
// check if redirect shall be executed
if (executeRedirect) { // default setting is yes to /login.xhtml
String url = ec.getRequestContextPath() + redirectTarget; // can be overwritten using parameters
ec.redirect(url); // de.muehlencord.shared.account.loginview.executeredirect boolean true/false
} // de.muehlencord.shared.account.loginview.redirecttarget path to redirect to (without external context, will be added automatically)
String executeRedirectString = ec.getInitParameter("de.muehlencord.shared.account.loginview.executeredirect");
} catch (Exception e) { boolean executeRedirect = true;
LOGGER.warn(e.toString()); if (executeRedirectString != null) {
} executeRedirect = Boolean.parseBoolean(executeRedirectString);
} }
public String executePasswordReset() { String redirectTarget = ec.getInitParameter("de.muehlencord.shared.account.loginview.redirecttarget");
boolean passwordResetted = accountService.resetPassword(username, password, resetPasswordToken); if ((redirectTarget == null) || (redirectTarget.equals(""))) {
if (passwordResetted) { redirectTarget = "/login.xhtml";
// TODO add email notification on updated user account }
FacesUtil.addGlobalInfoMessage("Password resetted", null);
return login(); if (executeRedirect) {
} else { String url = ec.getRequestContextPath() + redirectTarget;
// TODO add email notificaton on failed password reset ec.redirect(url);
FacesUtil.addGlobalErrorMessage("Password reset failed", null); }
return login();
} } catch (Exception e) {
} LOGGER.warn(e.toString());
}
/* **** naviation rules **** */ }
public String login() {
return "/login.xhtml"; // TODO make configurable public String executePasswordReset() {
} boolean passwordResetted = accountService.resetPassword(username, password, resetPasswordToken);
if (passwordResetted) {
/* *** getter / setter */ // TODO add email notification on updated user account
public String getUsername() { FacesUtil.addGlobalInfoMessage("Password resetted", null);
return username; return login();
} } else {
// TODO add email notificaton on failed password reset
public void setUsername(String un) { FacesUtil.addGlobalErrorMessage("Password reset failed", null);
this.username = un; return login();
} }
}
public String getPassword() {
return password; /* **** naviation rules **** */
} public String login() {
return "/login.xhtml"; // TODO make configurable
public void setPassword(String pw) { }
this.password = pw;
} /* *** getter / setter */
public String getUsername() {
public boolean isRememberMe() { return username;
return rememberMe; }
}
public void setUsername(String un) {
public void setRememberMe(boolean rememberMe) { this.username = un;
this.rememberMe = rememberMe; }
}
public String getPassword() {
public String getResetPasswordToken() { return password;
return resetPasswordToken; }
}
public void setPassword(String pw) {
public void setResetPasswordToken(String resetPasswordToken) { this.password = pw;
this.resetPasswordToken = resetPasswordToken; }
}
public boolean isRememberMe() {
} return rememberMe;
}
public void setRememberMe(boolean rememberMe) {
this.rememberMe = rememberMe;
}
public String getResetPasswordToken() {
return resetPasswordToken;
}
public void setResetPasswordToken(String resetPasswordToken) {
this.resetPasswordToken = resetPasswordToken;
}
}

View File

@ -1,48 +1,63 @@
package de.muehlencord.shared.account.presentation; /*
* Copyright 2018 joern.muehlencord.
import de.muehlencord.shared.account.business.account.control.AccountControl; *
import de.muehlencord.shared.jeeutil.FacesUtil; * Licensed under the Apache License, Version 2.0 (the "License");
import java.io.Serializable; * you may not use this file except in compliance with the License.
import javax.ejb.EJB; * You may obtain a copy of the License at
import javax.faces.view.ViewScoped; *
import javax.inject.Named; * http://www.apache.org/licenses/LICENSE-2.0
*
/** * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* @author joern@muehlencord.de * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/ * See the License for the specific language governing permissions and
@Named (value = "lostPasswordView") * limitations under the License.
@ViewScoped */
public class LostPasswordView implements Serializable { package de.muehlencord.shared.account.presentation;
private static final long serialVersionUID = -1793445795465830069L; import de.muehlencord.shared.account.business.account.control.AccountControl;
import de.muehlencord.shared.jeeutil.FacesUtil;
@EJB import java.io.Serializable;
private AccountControl accountService; import javax.ejb.EJB;
import javax.faces.view.ViewScoped;
private String userName; import javax.inject.Named;
private boolean passwordResetStarted = false;
/**
public String initPasswordReset() { *
if (accountService.initPasswordReset(userName)) { * @author joern@muehlencord.de
passwordResetStarted = true; */
FacesUtil.addGlobalInfoMessage("Password reset started.", "Please check your email account."); @Named (value = "lostPasswordView")
} else { @ViewScoped
FacesUtil.addGlobalErrorMessage("Error while resetting password.", "Please contact your administrator."); public class LostPasswordView implements Serializable {
}
return "/login.xhtml"; // TODO make configurable, get from LoginView? private static final long serialVersionUID = -1793445795465830069L;
}
@EJB
public String getUserName() { private AccountControl accountService;
return userName;
} private String userName;
private boolean passwordResetStarted = false;
public void setUserName(String userName) {
this.userName = userName; public String initPasswordReset() {
} if (accountService.initPasswordReset(userName)) {
passwordResetStarted = true;
public boolean getPasswordResetStarted() { FacesUtil.addGlobalInfoMessage("Password reset started.", "Please check your email account.");
return passwordResetStarted; } else {
} FacesUtil.addGlobalErrorMessage("Error while resetting password.", "Please contact your administrator.");
}
} return "/login.xhtml"; // TODO make configurable, get from LoginView?
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public boolean getPasswordResetStarted() {
return passwordResetStarted;
}
}

View File

@ -1,7 +1,17 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package de.muehlencord.shared.account.shiro.authc; package de.muehlencord.shared.account.shiro.authc;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2018 joern.muehlencord.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.shiro.filter; package de.muehlencord.shared.account.shiro.filter;
import de.muehlencord.shared.account.business.account.boundary.ApiKeyService; import de.muehlencord.shared.account.business.account.boundary.ApiKeyService;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2018 joern.muehlencord.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.shiro.realm; package de.muehlencord.shared.account.shiro.realm;
import de.muehlencord.shared.account.shiro.authc.JwtMatcher; import de.muehlencord.shared.account.shiro.authc.JwtMatcher;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2018 joern.muehlencord.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.shiro.realm; package de.muehlencord.shared.account.shiro.realm;
import java.util.HashSet; import java.util.HashSet;

View File

@ -1,7 +1,17 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package de.muehlencord.shared.account.shiro.token; package de.muehlencord.shared.account.shiro.token;

View File

@ -1,7 +1,17 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package de.muehlencord.shared.account.util; package de.muehlencord.shared.account.util;

View File

@ -1,44 +1,54 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
*/ * you may not use this file except in compliance with the License.
package de.muehlencord.shared.account.util; * You may obtain a copy of the License at
*
import java.io.Serializable; * http://www.apache.org/licenses/LICENSE-2.0
import java.util.Locale; *
import java.util.ResourceBundle; * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
/** * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* @author Joern Muehlencord <joern at muehlencord.de> * limitations under the License.
*/ */
public class AccountSecurityException extends Exception implements Serializable { package de.muehlencord.shared.account.util;
private static final long serialVersionUID = 8135850463689587815L; import java.io.Serializable;
import java.util.Locale;
private final SecurityError securityError; import java.util.ResourceBundle;
public AccountSecurityException(SecurityError securityError) { /**
this.securityError = securityError; *
} * @author Joern Muehlencord <joern at muehlencord.de>
*/
public String getErrorCode() { public class AccountSecurityException extends Exception implements Serializable {
return securityError.getErrorCode();
} private static final long serialVersionUID = 8135850463689587815L;
public String getMessageKey() { private final SecurityError securityError;
return securityError.getMessageKey();
} public AccountSecurityException(SecurityError securityError) {
this.securityError = securityError;
public String getMessage() { }
ResourceBundle resourceBundle = ResourceBundle.getBundle(securityError.getClass().getName(), Locale.ENGLISH);
return resourceBundle.getString(securityError.getMessageKey()); public String getErrorCode() {
} return securityError.getErrorCode();
}
public String getLocalizedMessage(Locale locale) {
ResourceBundle resourceBundle = ResourceBundle.getBundle(securityError.getClass().getName(), locale); public String getMessageKey() {
return resourceBundle.getString(securityError.getMessageKey()); return securityError.getMessageKey();
} }
} public String getMessage() {
ResourceBundle resourceBundle = ResourceBundle.getBundle(securityError.getClass().getName(), Locale.ENGLISH);
return resourceBundle.getString(securityError.getMessageKey());
}
public String getLocalizedMessage(Locale locale) {
ResourceBundle resourceBundle = ResourceBundle.getBundle(securityError.getClass().getName(), locale);
return resourceBundle.getString(securityError.getMessageKey());
}
}

View File

@ -1,7 +1,17 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package de.muehlencord.shared.account.util; package de.muehlencord.shared.account.util;

View File

@ -1,13 +1,28 @@
package de.muehlencord.shared.account.util; /*
* Copyright 2018 joern.muehlencord.
/** *
* * Licensed under the Apache License, Version 2.0 (the "License");
* @author Joern Muehlencord <joern at muehlencord.de> * you may not use this file except in compliance with the License.
*/ * You may obtain a copy of the License at
public interface Permission { *
* http://www.apache.org/licenses/LICENSE-2.0
String getName(); *
String getDescription(); * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
} * See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.util;
/**
*
* @author Joern Muehlencord <joern at muehlencord.de>
*/
public interface Permission {
String getName();
String getDescription();
}

View File

@ -1,12 +1,27 @@
package de.muehlencord.shared.account.util; /*
* Copyright 2018 joern.muehlencord.
/** *
* * Licensed under the Apache License, Version 2.0 (the "License");
* @author Joern Muehlencord <joern at muehlencord.de> * you may not use this file except in compliance with the License.
*/ * You may obtain a copy of the License at
public interface SecurityError { *
* http://www.apache.org/licenses/LICENSE-2.0
String getErrorCode(); *
String getMessageKey(); * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
} * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.util;
/**
*
* @author Joern Muehlencord <joern at muehlencord.de>
*/
public interface SecurityError {
String getErrorCode();
String getMessageKey();
}

View File

@ -1,3 +1,18 @@
/*
* Copyright 2018 joern.muehlencord.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.util; package de.muehlencord.shared.account.util;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2018 joern.muehlencord.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.util; package de.muehlencord.shared.account.util;
import javax.annotation.Priority; import javax.annotation.Priority;

View File

@ -1,5 +1,16 @@
# To change this license header, choose License Headers in Project Properties. #
# To change this template file, choose Tools | Templates # Copyright 2018 joern.muehlencord.
# and open the template in the editor. #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
listall_denied=You are not allowed to list all applications listall_denied=You are not allowed to list all applications

View File

@ -1,5 +1,16 @@
# To change this license header, choose License Headers in Project Properties. #
# To change this template file, choose Tools | Templates # Copyright 2018 joern.muehlencord.
# and open the template in the editor. #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
listall_denied=Sie haben nicht die n\u00f6tige Rechte alle Applikationen aufzulisten listall_denied=Sie haben nicht die n\u00f6tige Rechte alle Applikationen aufzulisten

View File

@ -1,5 +1,16 @@
# To change this license header, choose License Headers in Project Properties. #
# To change this template file, choose Tools | Templates # Copyright 2018 joern.muehlencord.
# and open the template in the editor. #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
listall_denied=User not allowed to list all applications listall_denied=User not allowed to list all applications

View File

@ -1,62 +1,76 @@
/*
package de.muehlencord.shared.account.business.config.boundary; * Copyright 2018 joern.muehlencord.
*
import de.muehlencord.shared.account.business.account.entity.AccountEntity; * Licensed under the Apache License, Version 2.0 (the "License");
import de.muehlencord.shared.account.business.account.entity.AccountLoginEntity; * you may not use this file except in compliance with the License.
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity; * You may obtain a copy of the License at
import de.muehlencord.shared.account.business.config.entity.ConfigEntity; *
import de.muehlencord.shared.account.business.config.entity.ConfigEntityPK; * http://www.apache.org/licenses/LICENSE-2.0
import java.util.UUID; *
import javax.persistence.EntityManager; * Unless required by applicable law or agreed to in writing, software
import org.junit.Test; * distributed under the License is distributed on an "AS IS" BASIS,
import org.junit.Before; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import org.junit.Ignore; * See the License for the specific language governing permissions and
import org.junit.runner.RunWith; * limitations under the License.
import org.mockito.InjectMocks; */
import org.mockito.Mock; package de.muehlencord.shared.account.business.config.boundary;
import static org.mockito.Mockito.when;
import org.mockito.runners.MockitoJUnitRunner; 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;
* @author joern.muehlencord import de.muehlencord.shared.account.business.config.entity.ConfigEntityPK;
*/ import java.util.UUID;
@RunWith(MockitoJUnitRunner.class) import javax.persistence.EntityManager;
public class ConfigServiceTest { import org.junit.Test;
import org.junit.Before;
@InjectMocks import org.junit.Ignore;
private ConfigService configService; import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@Mock import org.mockito.Mock;
private EntityManager entityManagerMock; import static org.mockito.Mockito.when;
import org.mockito.runners.MockitoJUnitRunner;
@Before
public void init() { /**
ApplicationEntity application = new ApplicationEntity(); *
application.setId(UUID.randomUUID()); * @author joern.muehlencord
application.setApplicationName("Test App"); */
@RunWith(MockitoJUnitRunner.class)
AccountEntity account = new AccountEntity(); public class ConfigServiceTest {
account.setUsername("system");
AccountLoginEntity login = new AccountLoginEntity(); @InjectMocks
login.setAccount (account); private ConfigService configService;
account.setAccountLogin(login);
@Mock
ConfigEntityPK pk = new ConfigEntityPK(application, "account.maxFailedLogins", account); private EntityManager entityManagerMock;
ConfigEntity configEntity = new ConfigEntity (pk);
configEntity.setConfigValue("7"); @Before
when (entityManagerMock.find(ConfigEntity.class, "account.maxFailedLogins")).thenReturn (configEntity); public void init() {
} ApplicationEntity application = new ApplicationEntity();
application.setId(UUID.randomUUID());
@Test application.setApplicationName("Test App");
@Ignore
// TODO move to account test AccountEntity account = new AccountEntity();
public void testGetMaxFailedLogins() { account.setUsername("system");
// configService.init(); AccountLoginEntity login = new AccountLoginEntity();
// assertEquals ("maxFailedLogins", 7, configService.getMaxFailedLogins()); login.setAccount (account);
} 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);
}
@Test
@Ignore
// TODO move to account test
public void testGetMaxFailedLogins() {
// configService.init();
// assertEquals ("maxFailedLogins", 7, configService.getMaxFailedLogins());
}
}

View File

@ -1,3 +1,18 @@
/*
* Copyright 2018 joern.muehlencord.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.account.shiro.realm; package de.muehlencord.shared.account.shiro.realm;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;

View File

@ -1,22 +1,32 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2018 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
*/ * you may not use this file except in compliance with the License.
package de.muehlencord.shared.account.util; * You may obtain a copy of the License at
*
import org.junit.Test; * http://www.apache.org/licenses/LICENSE-2.0
*
/** * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* @author Joern Muehlencord <joern at muehlencord.de> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/ * See the License for the specific language governing permissions and
public class SecurityUtilTest { * limitations under the License.
*/
package de.muehlencord.shared.account.util;
@Test
public void testCreatePassword() { import org.junit.Test;
System.out.println (SecurityUtil.createPassword("secret"));
} /**
*
} * @author Joern Muehlencord <joern at muehlencord.de>
*/
public class SecurityUtilTest {
@Test
public void testCreatePassword() {
System.out.println (SecurityUtil.createPassword("secret"));
}
}