diff --git a/main/java/com/livejournal/xtecuan/microprofile/entities/Users.java b/main/java/com/livejournal/xtecuan/microprofile/entities/Users.java deleted file mode 100644 index a41f3b4..0000000 --- a/main/java/com/livejournal/xtecuan/microprofile/entities/Users.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2019 xtecuan. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * xtecuan - initial API and implementation and/or initial documentation - */ -package com.livejournal.xtecuan.microprofile.entities; - -import java.io.Serializable; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.ColumnResult; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.ParameterMode; -import javax.persistence.SqlResultSetMapping; -import javax.persistence.SqlResultSetMappings; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import org.eclipse.persistence.annotations.NamedStoredFunctionQueries; -import org.eclipse.persistence.annotations.NamedStoredFunctionQuery; -import org.eclipse.persistence.annotations.StoredProcedureParameter; - -/** - * - * @author xtecuan - */ -@Entity -@Table(name = "USERS_TABLE") -@SqlResultSetMappings({ - @SqlResultSetMapping( - name = "passHashResult", columns = { - @ColumnResult(name = "MYHASH")} - ) -}) - -@NamedQueries({ - @NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"), - @NamedQuery(name = "Users.findByUserid", query = "SELECT u FROM Users u WHERE u.userid = :userid"), - @NamedQuery(name = "Users.findByEmail", query = "SELECT u FROM Users u WHERE u.email = :email"), - @NamedQuery(name = "Users.findByFirstname", query = "SELECT u FROM Users u WHERE u.firstname = :firstname"), - @NamedQuery(name = "Users.findByMiddlename", query = "SELECT u FROM Users u WHERE u.middlename = :middlename"), - @NamedQuery(name = "Users.findByLastname", query = "SELECT u FROM Users u WHERE u.lastname = :lastname"), - @NamedQuery(name = "Users.findByPassword", query = "SELECT u FROM Users u WHERE u.password = :password"), - @NamedQuery(name = "Users.findByEmailAndPassword", query = "SELECT u FROM Users u WHERE u.email = :email and u.password = :password ")}) -public class Users implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Basic(optional = false) - @Column(name = "USERID") - private Long userid; - // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 150) - @Column(name = "EMAIL") - private String email; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 200) - @Column(name = "FIRSTNAME") - private String firstname; - @Size(max = 200) - @Column(name = "MIDDLENAME") - private String middlename; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 200) - @Column(name = "LASTNAME") - private String lastname; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 500) - @Column(name = "PASSWORD") - private String password; - @NotNull - @Size(min = 1, max = 10) - @Column(name = "WROLE") - private String wrole; - - public Users() { - } - - public Users(Long userid) { - this.userid = userid; - } - - public Users(Long userid, String email, String firstname, String lastname, String password) { - this.userid = userid; - this.email = email; - this.firstname = firstname; - this.lastname = lastname; - this.password = password; - } - - public Long getUserid() { - return userid; - } - - public void setUserid(Long userid) { - this.userid = userid; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getFirstname() { - return firstname; - } - - public void setFirstname(String firstname) { - this.firstname = firstname; - } - - public String getMiddlename() { - return middlename; - } - - public void setMiddlename(String middlename) { - this.middlename = middlename; - } - - public String getLastname() { - return lastname; - } - - public void setLastname(String lastname) { - this.lastname = lastname; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getWrole() { - return wrole; - } - - public void setWrole(String wrole) { - this.wrole = wrole; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (userid != null ? userid.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set - if (!(object instanceof Users)) { - return false; - } - Users other = (Users) object; - if ((this.userid == null && other.userid != null) || (this.userid != null && !this.userid.equals(other.userid))) { - return false; - } - return true; - } - - @Override - public String toString() { - return "Users[email=" + email + "]"; - } - -} diff --git a/main/java/com/livejournal/xtecuan/microprofile/facade/AbstractFacade.java b/main/java/com/livejournal/xtecuan/microprofile/facade/AbstractFacade.java deleted file mode 100644 index 8ade2cb..0000000 --- a/main/java/com/livejournal/xtecuan/microprofile/facade/AbstractFacade.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2019 xtecuan. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * xtecuan - initial API and implementation and/or initial documentation - */ -package com.livejournal.xtecuan.microprofile.facade; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import javax.persistence.EntityManager; -import javax.persistence.Query; -import org.apache.log4j.Logger; - -/** - * - * @author xtecuan - */ -public abstract class AbstractFacade { - - private static final Logger LOGGER = Logger.getLogger(AbstractFacade.class); - private Class entityClass; - - public AbstractFacade(Class entityClass) { - this.entityClass = entityClass; - } - - public static Logger getLogger() { - return LOGGER; - } - - protected abstract EntityManager getEntityManager(); - - public void create(T entity) { - getEntityManager().persist(entity); - } - - public void edit(T entity) { - getEntityManager().merge(entity); - } - - public void remove(T entity) { - getEntityManager().remove(getEntityManager().merge(entity)); - } - - public T find(Object id) { - return getEntityManager().find(entityClass, id); - } - - public List findAll() { - javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); - cq.select(cq.from(entityClass)); - return getEntityManager().createQuery(cq).getResultList(); - } - - public List findRange(int[] range) { - javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); - cq.select(cq.from(entityClass)); - javax.persistence.Query q = getEntityManager().createQuery(cq); - q.setMaxResults(range[1] - range[0] + 1); - q.setFirstResult(range[0]); - return q.getResultList(); - } - - public int count() { - javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); - javax.persistence.criteria.Root rt = cq.from(entityClass); - cq.select(getEntityManager().getCriteriaBuilder().count(rt)); - javax.persistence.Query q = getEntityManager().createQuery(cq); - return ((Long) q.getSingleResult()).intValue(); - } - - public T executeNamedQuerySingleResult(String namedQuery, Map params) { - T entity = null; - try { - Query query = getEntityManager().createNamedQuery(namedQuery); - for (String key : params.keySet()) { - query = query.setParameter(key, params.get(key)); - } - List entities = entities = query.getResultList(); - if (!entities.isEmpty()) { - entity = entities.get(0); - } - } catch (Exception e) { - getLogger().error("Error executing Query: " - + namedQuery + " with Params: " + params, - e); - } - return entity; - } - - public List executeNamedQueryResultList(String namedQuery, Map params) { - List entities = new ArrayList<>(); - try { - Query query = getEntityManager().createNamedQuery(namedQuery); - for (String key : params.keySet()) { - query = query.setParameter(key, params.get(key)); - } - entities = entities = query.getResultList(); - } catch (Exception e) { - getLogger().error("Error executing Query: " - + namedQuery + " with Params: " + params, - e); - } - return entities; - } - -} diff --git a/main/java/com/livejournal/xtecuan/microprofile/facade/UsersFacade.java b/main/java/com/livejournal/xtecuan/microprofile/facade/UsersFacade.java deleted file mode 100644 index b4fa7c0..0000000 --- a/main/java/com/livejournal/xtecuan/microprofile/facade/UsersFacade.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2019 xtecuan. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * xtecuan - initial API and implementation and/or initial documentation - */ -package com.livejournal.xtecuan.microprofile.facade; - -import com.livejournal.xtecuan.microprofile.dto.UsersDTO; -import com.livejournal.xtecuan.microprofile.entities.Users; -import com.livejournal.xtecuan.microprofile.sql.utils.QueryLoader; -import com.livejournal.xtecuan.microprofile.web.constants.WebConstants; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.List; -import javax.annotation.Resource; -import javax.ejb.Stateless; -import javax.inject.Inject; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.sql.DataSource; - -/** - * - * @author xtecuan - */ -@Stateless -public class UsersFacade extends AbstractFacade { - - @PersistenceContext(unitName = "tadeocrudPU") - private EntityManager em; - - @Resource(lookup = "java:app/jdbc/H2SampleDB") - private DataSource dataSource; - - @Inject - private QueryLoader queryLoader; - - @Override - protected EntityManager getEntityManager() { - return em; - } - - public UsersFacade() { - super(Users.class); - } - - public String getPasswordHash(String blankPassword) { - - return (String) getEntityManager() - .createNamedQuery("Users.getPasswordHash") - .setParameter(1, blankPassword) - .getSingleResult(); - } - - public String getMyHashFromH2(String plainPassword) { - String result = null; - try (Connection connection = dataSource.getConnection()) { - String hash = queryLoader.getQueryUsingFilename("hash.sql"); - PreparedStatement psta = connection.prepareStatement(hash); - psta.setString(1, plainPassword); - ResultSet rset = psta.executeQuery(); - while (rset.next()) { - result = rset.getString(1); - } - rset.close(); - connection.close(); - } catch (Exception ex) { - getLogger().error("Error in getMyHashFromH2: ", ex); - } - - return result; - } - - public Users findByEmailAndPass(String email, String password) { - Users user = null; - - List users = getEntityManager() - .createNamedQuery("Users.findByEmailAndPassword") - .setParameter("email", email) - .setParameter("password", getMyHashFromH2(password)) - .getResultList(); - - if (users != null && !users.isEmpty()) { - user = users.get(0); - } - return user; - } - - public String getCompleteName(Users user) { - return user.getFirstname() - + " " - + (user.getMiddlename() != null && user.getMiddlename().length() > 0 ? user.getMiddlename() : "") - + " " - + user.getLastname(); - - } - - public boolean checkIfPlainPasswordWithMark(String plainPasswordWithMark) { - boolean r = false; - - if (plainPasswordWithMark.contains(WebConstants.USER_PASS_PLAIN_MARK)) { - - boolean s = plainPasswordWithMark.indexOf(WebConstants.USER_PASS_PLAIN_MARK) != -1; - boolean e = plainPasswordWithMark.lastIndexOf(WebConstants.USER_PASS_PLAIN_MARK) != -1; - r = s && e; - - } - - return r; - } - - public String getPlainPasswordFromMarked(String plainPasswordWithMark) { - return plainPasswordWithMark.substring(2, plainPasswordWithMark.length() - 2); - } - - public UsersDTO fromEntity2DTO(Users user) { - UsersDTO dto = new UsersDTO(); - if (user.getUserid() != null) { - dto.setUserid(user.getUserid()); - } - dto.setPassword(user.getPassword()); - dto.setFirstname(user.getFirstname()); - dto.setLastname(user.getLastname()); - if (user.getMiddlename() != null && user.getMiddlename().length() > 0) { - dto.setMiddlename(user.getMiddlename()); - } - dto.setEmail(user.getEmail()); - dto.setWrole(user.getWrole()); - return dto; - } - - public Users fromDTO2Entity(UsersDTO dto) { - Users u = new Users(); - if (dto.getUserid() != null) { - u.setUserid(dto.getUserid()); - } - u.setPassword(dto.getPassword()); - u.setFirstname(dto.getFirstname()); - u.setLastname(dto.getLastname()); - if (dto.getMiddlename() != null && dto.getMiddlename().length() > 0) { - u.setMiddlename(dto.getMiddlename()); - } - u.setEmail(dto.getEmail()); - u.setWrole(dto.getWrole()); - return u; - } - - public void saveUser(UsersDTO dto) { - Users u = fromDTO2Entity(dto); - if (u.getUserid() != null) { - edit(u); - } else { - create(u); - } - } - - public void deleteUser(UsersDTO dto){ - Users u = fromDTO2Entity(dto); - remove(u); - } - - public List findAllUsers() { - List users = new ArrayList<>(); - findAll().forEach(u -> users.add(fromEntity2DTO(u))); - return users; - } - -} diff --git a/main/java/com/livejournal/xtecuan/microprofile/h2/database/stored/procedures/SampleStoredProcedure.java b/main/java/com/livejournal/xtecuan/microprofile/h2/database/stored/procedures/SampleStoredProcedure.java deleted file mode 100644 index 2445dc0..0000000 --- a/main/java/com/livejournal/xtecuan/microprofile/h2/database/stored/procedures/SampleStoredProcedure.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2018 xtecuan. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * xtecuan - initial API and implementation and/or initial documentation - */ -package com.livejournal.xtecuan.microprofile.h2.database.stored.procedures; - -/** - * - * @author xtecuan - */ -public class SampleStoredProcedure { - private static final String QUERY_GET_EMAIL=" "; -} diff --git a/main/java/com/livejournal/xtecuan/microprofile/sql/utils/QueryLoader.java b/main/java/com/livejournal/xtecuan/microprofile/sql/utils/QueryLoader.java deleted file mode 100644 index b72a3af..0000000 --- a/main/java/com/livejournal/xtecuan/microprofile/sql/utils/QueryLoader.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2018 xtecuan. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * xtecuan - initial API and implementation and/or initial documentation - */ -package com.livejournal.xtecuan.microprofile.sql.utils; - -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Scanner; -import javax.ejb.Singleton; -import org.apache.commons.io.IOUtils; - -/** - * - * @author xtecuan - */ -@Singleton -public class QueryLoader { - - private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(QueryLoader.class); - private static final String DEFAULT_CHARSET = "UTF-8"; - private static final String DEFAULT_PACKAGE_FROM = "./queries/"; - private static final String DEFAULT_PACKAGE_HTML = "./html/"; - - public String getQueryUsingFilename(String filename) { - String result = null; - try { - result = IOUtils.resourceToString( - DEFAULT_PACKAGE_FROM + filename, - Charset.forName(DEFAULT_CHARSET), - Thread.currentThread().getContextClassLoader()); - } catch (Exception e) { - logger.error("Error loading query from file: " + DEFAULT_PACKAGE_FROM + filename, e); - } - return result; - } - - public List getSQLSentencesUsingFilename(String filename) { - List sql = new ArrayList<>(); - String sqlFull = getQueryUsingFilename(filename); - int i = 0; - Scanner s = new Scanner(sqlFull); - s.useDelimiter(";\n"); - while (s.hasNext()) { - String c = s.next(); - sql.add(c); - } - return sql; - } - - public String getQueryUsingFilename(String packageName, String filename) { - String result = null; - try { - result = IOUtils.resourceToString( - packageName + filename, - Charset.forName(DEFAULT_CHARSET), - Thread.currentThread().getContextClassLoader()); - } catch (Exception e) { - logger.error("Error loading query from file: " + packageName + filename, e); - } - return result; - } - - public String getHtmlTemplate(String filename) { - return getQueryUsingFilename(DEFAULT_PACKAGE_HTML, filename); - } - - public String getFilledHtmlTemplate(Map data, String filename) { - String template = getHtmlTemplate(filename); - - for (String key : data.keySet()) { - template = template.replaceAll("$" + key, data.get(key)); - } - - return template; - } - -} diff --git a/main/java/com/livejournal/xtecuan/microprofile/startup/service/DBStartupService.java b/main/java/com/livejournal/xtecuan/microprofile/startup/service/DBStartupService.java deleted file mode 100644 index 47b8dbe..0000000 --- a/main/java/com/livejournal/xtecuan/microprofile/startup/service/DBStartupService.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2018 xtecuan. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * xtecuan - initial API and implementation and/or initial documentation - */ -package com.livejournal.xtecuan.microprofile.startup.service; - -import com.livejournal.xtecuan.microprofile.sql.utils.QueryLoader; -import static java.lang.System.out; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import javax.annotation.PostConstruct; -import javax.annotation.Resource; -import javax.ejb.Singleton; -import javax.ejb.Startup; -import javax.inject.Inject; -import javax.sql.DataSource; - -/** - * - * @author xtecuan - */ -@Startup -@Singleton -public class DBStartupService { - - private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(DBStartupService.class); - - @Resource(lookup = "java:app/jdbc/H2SampleDB") - private DataSource dataSource; - - @Inject - private QueryLoader queryLoader; - - private int countIfDataExists() { - int result = 0; - try (Connection connection = dataSource.getConnection()) { - String countQuery = queryLoader.getQueryUsingFilename("USERS_COUNT.sql"); - Statement sta = connection.createStatement(); - ResultSet rset = sta.executeQuery(countQuery); - while (rset.next()) { - result = rset.getInt(1); - } - rset.close(); - connection.close(); - } catch (Exception ex) { - logger.error("Error in countIfDataExists: ", ex); - } - - return result; - } - - private void createTable() { - try (Connection connection = dataSource.getConnection()) { - connection.setAutoCommit(true); - String createTable = queryLoader.getQueryUsingFilename("USERS.sql"); - System.out.println(createTable); - PreparedStatement psta = connection.prepareStatement(createTable); - int result = psta.executeUpdate(); - logger.info("result: " + result); - connection.commit(); - psta.close(); - logger.info(connection.getAutoCommit()); - connection.close(); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - private void createSampleData() { - try (Connection connection = dataSource.getConnection()) { - String createData = queryLoader.getQueryUsingFilename("USERS_DATA.sql"); - PreparedStatement psta = connection.prepareStatement(createData); - int result = psta.executeUpdate(); - logger.info("result: " + result); - psta.close(); - connection.close(); - - } catch (Exception e) { - logger.error("Error int createSampleData: ", e); - } - } - - public void tryConnection() { - try (Connection connection = dataSource.getConnection()) { - out.println("METADATA: " - + connection.getMetaData().getDatabaseProductName() + "-" - + connection.getCatalog() - ); - } catch (SQLException e) { - - } - } - - @PostConstruct - public void init() { - try { - tryConnection(); - createTable(); - if (countIfDataExists() == 0) { - createSampleData(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } -} diff --git a/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/IndexBean.java b/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/IndexBean.java deleted file mode 100644 index 2789572..0000000 --- a/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/IndexBean.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2019 xtecuan. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * xtecuan - initial API and implementation and/or initial documentation - */ -package com.livejournal.xtecuan.microprofile.web.beans.utils; - -import java.io.Serializable; -import javax.annotation.PostConstruct; -import javax.faces.view.ViewScoped; -import javax.inject.Named; - -/** - * - * @author xtecuan - */ -@Named -@ViewScoped -public class IndexBean extends XBaseBean implements Serializable { - - @PostConstruct - @Override - public void init() { - - } - - public void console() { - redirectToUrl("/console/"); - } - - -} diff --git a/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/UserSessionBean.java b/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/UserSessionBean.java deleted file mode 100644 index e07c3d9..0000000 --- a/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/UserSessionBean.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2019 xtecuan. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * xtecuan - initial API and implementation and/or initial documentation - */ -package com.livejournal.xtecuan.microprofile.web.beans.utils; - -import com.livejournal.xtecuan.microprofile.entities.Users; -import java.io.Serializable; -import javax.enterprise.context.SessionScoped; -import javax.inject.Named; - -/** - * - * @author xtecuan - */ -@Named -@SessionScoped -public class UserSessionBean implements Serializable { - - private Users user; - - private String passwordChange; - - public Users getUser() { - return user; - } - - public void setUser(Users user) { - this.user = user; - } - - public String getPasswordChange() { - return passwordChange; - } - - public void setPasswordChange(String passwordChange) { - this.passwordChange = passwordChange; - } - -} diff --git a/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/XBaseBean.java b/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/XBaseBean.java deleted file mode 100644 index 21a2eb0..0000000 --- a/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/XBaseBean.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.livejournal.xtecuan.microprofile.web.beans.utils; - -import java.io.IOException; -import java.io.Serializable; -import java.util.Map; -import javax.faces.application.FacesMessage; -import javax.faces.context.ExternalContext; -import javax.faces.context.FacesContext; -import org.apache.log4j.Logger; - -/** - * - * @author xtecuan - */ -public abstract class XBaseBean implements Serializable { - - public static final Integer ENG = 1; - public static final Integer SPA = 2; - public static final String JSF = ".jsf"; - public static final String FACES_REDIRECT = "?faces-redirect=true¶ms=true"; - private static final Logger LOGGER = Logger.getLogger(XBaseBean.class); - - public void addMessage(String summary, String detail) { - - FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, - summary, detail)); - } - - public void addError(String summary, String detail) { - FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, - summary, detail)); - } - - public void setParam(String name, String value) { - FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().put(name, value); - } - - public String getParam(String name) { - return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name); - } - - public Integer getIntegerParam(String name) { - return Integer.valueOf(getParam(name)); - } - - public static Logger getLogger() { - return LOGGER; - } - - public void setSessionAttribute(String name, Object value) { - getSession().put(name, value); - } - - public Object getSessionAttribute(String name) { - return getSession().get(name); - } - - public Map getSession() { - return FacesContext.getCurrentInstance().getExternalContext().getSessionMap(); - } - - public void removeSessionAttribute(String name) { - getSession().remove(name); - } - - /** - * Postconstruct init method - */ - public abstract void init(); - - public void invalidateSession() { - FacesContext.getCurrentInstance().getExternalContext().invalidateSession(); - } - - public void setFlashParam(String name, Object value) { - FacesContext.getCurrentInstance().getExternalContext().getFlash().put(name, value); - } - - public Object getFlashParam(String name) { - return FacesContext.getCurrentInstance().getExternalContext().getFlash().get(name); - } - - public Integer getFlashIntegerParam(String name) { - return (Integer) getFlashParam(name); - } - - public String getFlashStringParam(String name) { - return (String) getFlashParam(name); - } - - public void redirectToUrl(String url) { - FacesContext fc = FacesContext.getCurrentInstance(); - ExternalContext ec = fc.getExternalContext(); - try { - ec.redirect(url); - } catch (IOException ex) { - getLogger().error("Error redirecting to " + url, ex); - } - } -} diff --git a/main/java/com/livejournal/xtecuan/microprofile/web/constants/WebConstants.java b/main/java/com/livejournal/xtecuan/microprofile/web/constants/WebConstants.java deleted file mode 100644 index d6dd217..0000000 --- a/main/java/com/livejournal/xtecuan/microprofile/web/constants/WebConstants.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2019 xtecuan. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * xtecuan - initial API and implementation and/or initial documentation - */ -package com.livejournal.xtecuan.microprofile.web.constants; - -/** - * - * @author xtecuan - */ -public class WebConstants { - - public static final String USER_IN_SESSION = "USER_IN"; - public static final String USER_PASS_PLAIN_MARK = "##"; - public static final String[] ROLES = new String[]{"ADMIN", "USER"}; -} diff --git a/main/java/com/livejournal/xtecuan/microprofile/web/filters/CharacterEncodingFilter.java b/main/java/com/livejournal/xtecuan/microprofile/web/filters/CharacterEncodingFilter.java deleted file mode 100644 index b32d112..0000000 --- a/main/java/com/livejournal/xtecuan/microprofile/web/filters/CharacterEncodingFilter.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2016 xtecuan. - * - * 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 com.livejournal.xtecuan.microprofile.web.filters; - -import java.io.IOException; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -/** - * - * @author xtecuan - */ -public class CharacterEncodingFilter implements Filter { - - @Override - public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { - req.setCharacterEncoding("UTF-8"); - resp.setCharacterEncoding("UTF-8"); - chain.doFilter(req, resp); - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void destroy() { - - } -} diff --git a/main/java/de/rieckpil/blog/LoginBacking.java b/main/java/de/rieckpil/blog/LoginBacking.java deleted file mode 100644 index fbc0b7a..0000000 --- a/main/java/de/rieckpil/blog/LoginBacking.java +++ /dev/null @@ -1,111 +0,0 @@ -package de.rieckpil.blog; - -import com.livejournal.xtecuan.microprofile.facade.UsersFacade; -import com.livejournal.xtecuan.microprofile.web.beans.utils.UserSessionBean; -import com.livejournal.xtecuan.microprofile.web.beans.utils.XBaseBean; -import javax.faces.context.ExternalContext; -import javax.faces.context.FacesContext; -import javax.inject.Inject; -import javax.inject.Named; -import javax.security.enterprise.AuthenticationStatus; -import javax.security.enterprise.SecurityContext; -import javax.security.enterprise.authentication.mechanism.http.AuthenticationParameters; -import javax.security.enterprise.credential.UsernamePasswordCredential; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Size; -import java.io.IOException; -import javax.annotation.PostConstruct; -import javax.faces.application.FacesMessage; -import javax.faces.view.ViewScoped; - -@Named -@ViewScoped -public class LoginBacking extends XBaseBean { - - @NotEmpty - @Size(min = 8, message = "Password must have at least 8 characters") - private String password; - - @NotEmpty - @Email(message = "Please provide a valid e-mail") - private String email; - - @Inject - private SecurityContext securityContext; - - @Inject - private ExternalContext externalContext; - - @Inject - private FacesContext facesContext; - - @Inject - private UsersFacade usersFacade; - - @Inject - private UserSessionBean currentUser; - - public void submit() throws IOException { - - switch (continueAuthentication()) { - case SEND_CONTINUE: - currentUser.setUser(usersFacade.findByEmailAndPass(email, password)); - facesContext.responseComplete(); - break; - case SEND_FAILURE: - facesContext.addMessage(null, - new FacesMessage(FacesMessage.SEVERITY_ERROR, "Login failed", null)); - break; - case SUCCESS: - currentUser.setUser(usersFacade.findByEmailAndPass(email, password)); - facesContext.addMessage(null, - new FacesMessage(FacesMessage.SEVERITY_INFO, "Login succeed", null)); - externalContext.redirect(externalContext.getRequestContextPath() + "/app/main.jsf"); - break; - case NOT_DONE: - } - } - - private AuthenticationStatus continueAuthentication() { - return securityContext.authenticate( - (HttpServletRequest) externalContext.getRequest(), - (HttpServletResponse) externalContext.getResponse(), - AuthenticationParameters.withParams().credential(new UsernamePasswordCredential(email, password)) - ); - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - - @PostConstruct - @Override - public void init() { - - } - - public UserSessionBean getCurrentUser() { - return currentUser; - } - - public void setCurrentUser(UserSessionBean currentUser) { - this.currentUser = currentUser; - } - -} diff --git a/main/java/de/rieckpil/blog/LogoutBacking.java b/main/java/de/rieckpil/blog/LogoutBacking.java deleted file mode 100644 index 50ca5cd..0000000 --- a/main/java/de/rieckpil/blog/LogoutBacking.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.rieckpil.blog; - -import javax.enterprise.context.RequestScoped; -import javax.faces.context.FacesContext; -import javax.inject.Named; - -@Named -@RequestScoped -public class LogoutBacking { - - public String submit() { - FacesContext.getCurrentInstance().getExternalContext().invalidateSession(); - return "/login.jsf?faces-redirect=true"; - } -} \ No newline at end of file diff --git a/main/java/de/rieckpil/blog/security/ApplicationConfig.java b/main/java/de/rieckpil/blog/security/ApplicationConfig.java deleted file mode 100644 index 51bdcfd..0000000 --- a/main/java/de/rieckpil/blog/security/ApplicationConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.rieckpil.blog.security; - -import javax.enterprise.context.ApplicationScoped; -import javax.faces.annotation.FacesConfig; -import javax.security.enterprise.authentication.mechanism.http.CustomFormAuthenticationMechanismDefinition; -import javax.security.enterprise.authentication.mechanism.http.LoginToContinue; - -@CustomFormAuthenticationMechanismDefinition( - loginToContinue = @LoginToContinue( - loginPage = "/login.jsf", - useForwardToLogin = false - ) -) -@FacesConfig -@ApplicationScoped -public class ApplicationConfig { -} - diff --git a/main/java/de/rieckpil/blog/security/CustomInMemoryIdentityStore.java b/main/java/de/rieckpil/blog/security/CustomInMemoryIdentityStore.java deleted file mode 100644 index b57a255..0000000 --- a/main/java/de/rieckpil/blog/security/CustomInMemoryIdentityStore.java +++ /dev/null @@ -1,54 +0,0 @@ -package de.rieckpil.blog.security; - -import com.livejournal.xtecuan.microprofile.entities.Users; -import com.livejournal.xtecuan.microprofile.facade.UsersFacade; -import javax.enterprise.context.ApplicationScoped; -import javax.security.enterprise.credential.Credential; -import javax.security.enterprise.credential.UsernamePasswordCredential; -import javax.security.enterprise.identitystore.CredentialValidationResult; -import javax.security.enterprise.identitystore.IdentityStore; -import java.util.Arrays; -import java.util.HashSet; -import javax.inject.Inject; -import org.apache.log4j.Logger; - -@ApplicationScoped -public class CustomInMemoryIdentityStore implements IdentityStore { - - private static final Logger LOGGER = Logger.getLogger(CustomInMemoryIdentityStore.class); - - @Inject - private UsersFacade usersFacade; - - @Override - public CredentialValidationResult validate(Credential credential) { - - UsernamePasswordCredential login = (UsernamePasswordCredential) credential; - String email = login.getCaller(); - String password = login.getPasswordAsString(); - - getLogger().info("Caller: " + email); - getLogger().info("blankPassword: " + password); - getLogger().info("hashedPassword: " + usersFacade.getMyHashFromH2(password)); - - Users user = usersFacade.findByEmailAndPass(email, password); - - if (user != null) { - return new CredentialValidationResult(user.getEmail(), new HashSet<>(Arrays.asList(user.getWrole()))); - } else { - return CredentialValidationResult.NOT_VALIDATED_RESULT; - } - -// if (login.getCaller().equals("admin@mail.com") && login.getPasswordAsString().equals("ADMIN1234")) { -// return new CredentialValidationResult("admin", new HashSet<>(Arrays.asList("ADMIN"))); -// } else if (login.getCaller().equals("user@mail.com") && login.getPasswordAsString().equals("USER1234")) { -// return new CredentialValidationResult("user", new HashSet<>(Arrays.asList("USER"))); -// } else { -// -// } - } - - public static Logger getLogger() { - return LOGGER; - } -} diff --git a/main/resources/Bundle.properties b/main/resources/Bundle.properties deleted file mode 100644 index e6d1068..0000000 --- a/main/resources/Bundle.properties +++ /dev/null @@ -1,26 +0,0 @@ -index_title=tadeocrud H2 DB Service -index_header=tadeocrud Service -index_link_text=tadeocrud H2 Database Service Console - -app_main_title=Tadeo Crud Application -app_main_header=Welcome to Tadeo CRUD application! -app_main_logged_in=Logged-in as: -app_main_logout=Logout -app_main_dbconsole=DB Console -app_main_id=Id -app_main_email=E-Mail -app_main_fn=Firstname -app_main_mn=Middlename -app_main_ln=Lastname -app_main_rol=Rol -app_main_theader=List of Users -app_main_pass=Password -app_main_ereq=E-Mail is required -app_main_fnreq=Firstname required -app_main_lnreq=Lastname required -app_main_rolreq=Rol required -app_main_passreq=Password required -app_main_selone=Select One -app_main_bsave=Save -app_main_bupd=Update -app_main_bdel=Delete diff --git a/main/resources/META-INF/nativeQueries.xml b/main/resources/META-INF/nativeQueries.xml deleted file mode 100644 index 5f8282f..0000000 --- a/main/resources/META-INF/nativeQueries.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - Native queries for Application - - - - - - - - - - diff --git a/main/resources/META-INF/persistence.xml b/main/resources/META-INF/persistence.xml deleted file mode 100644 index e0dfb03..0000000 --- a/main/resources/META-INF/persistence.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - java:app/jdbc/H2SampleDB - META-INF/nativeQueries.xml - - com.livejournal.xtecuan.microprofile.entities.Users - false - - - diff --git a/main/resources/log4j.properties b/main/resources/log4j.properties deleted file mode 100644 index ad3783a..0000000 --- a/main/resources/log4j.properties +++ /dev/null @@ -1,5 +0,0 @@ -log4j.rootLogger=INFO, loggerId -log4j.appender.loggerId=org.apache.log4j.ConsoleAppender -log4j.appender.loggerId.layout=org.apache.log4j.EnhancedPatternLayout -log4j.appender.loggerId.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss zzz}{GMT-4} %-5p [%t][%c:%M(%L)] %m%n - diff --git a/main/resources/payaramicro.properties b/main/resources/payaramicro.properties deleted file mode 100644 index 557f75b..0000000 --- a/main/resources/payaramicro.properties +++ /dev/null @@ -1,4 +0,0 @@ -#payaramicro.port=7777 -#payaramicro.name=tadeocrud -#payaramicro.instanceGroup=tadeocrud-group - diff --git a/main/resources/properties.config b/main/resources/properties.config deleted file mode 100644 index 447c910..0000000 --- a/main/resources/properties.config +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/main/resources/queries/USERS.sql b/main/resources/queries/USERS.sql deleted file mode 100644 index a84e9d6..0000000 --- a/main/resources/queries/USERS.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE IF NOT EXISTS PUBLIC.USERS_TABLE ( - USERID BIGINT NOT NULL AUTO_INCREMENT, - EMAIL VARCHAR(150) NOT NULL, - FIRSTNAME VARCHAR(200) NOT NULL, - MIDDLENAME VARCHAR(200) DEFAULT '', - LASTNAME VARCHAR(200) NOT NULL, - PASSWORD VARCHAR(500) NOT NULL, - WROLE VARCHAR(10) NOT NULL, - CONSTRAINT USERS_TABLE_PK PRIMARY KEY (USERID), - CONSTRAINT USERS_TABLE_UN UNIQUE KEY (EMAIL) -) diff --git a/main/resources/queries/USERS_COUNT.sql b/main/resources/queries/USERS_COUNT.sql deleted file mode 100644 index 97aab20..0000000 --- a/main/resources/queries/USERS_COUNT.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT COUNT(*) FROM PUBLIC.USERS_TABLE diff --git a/main/resources/queries/USERS_DATA.sql b/main/resources/queries/USERS_DATA.sql deleted file mode 100644 index c65f762..0000000 --- a/main/resources/queries/USERS_DATA.sql +++ /dev/null @@ -1,7 +0,0 @@ -INSERT INTO PUBLIC.USERS_TABLE (EMAIL, FIRSTNAME, MIDDLENAME, LASTNAME,PASSWORD,WROLE) VALUES('xtecuanufo@gmail.com', 'Tadeo', '', 'Rivera-Pineda',HASH('SHA256', STRINGTOUTF8('Welcome123$$$123'),500),'ADMIN'); -INSERT INTO PUBLIC.USERS_TABLE (EMAIL, FIRSTNAME, MIDDLENAME, LASTNAME,PASSWORD,WROLE) VALUES('xtecuan@protonmail.com', 'Julian', '', 'Rivera-Pineda',HASH('SHA256', STRINGTOUTF8('Welcome123$$$124'),500),'ADMIN'); -INSERT INTO PUBLIC.USERS_TABLE (EMAIL, FIRSTNAME, MIDDLENAME, LASTNAME,PASSWORD,WROLE) VALUES('mtorres@sertracen.com', 'Marcelo', '', 'Torres',HASH('SHA256', STRINGTOUTF8('Welcome123$'),500),'ADMIN'); -INSERT INTO PUBLIC.USERS_TABLE (EMAIL, FIRSTNAME, MIDDLENAME, LASTNAME,PASSWORD,WROLE) VALUES('juliux@gmail.com', 'Julio', 'Adalberto', 'Rivera-Pineda',HASH('SHA256', STRINGTOUTF8('HolaHola$$$123'),500),'USER'); -INSERT INTO PUBLIC.USERS_TABLE (EMAIL, FIRSTNAME, MIDDLENAME, LASTNAME,PASSWORD,WROLE) VALUES('kingofkings1982@live.com', 'Jonatan', '', 'Rivera-Pineda',HASH('SHA256', STRINGTOUTF8('Holahola$$$123'),500),'USER'); -INSERT INTO PUBLIC.USERS_TABLE (EMAIL, FIRSTNAME, MIDDLENAME, LASTNAME,PASSWORD,WROLE) VALUES('marvinposada@gmail.com', 'Marvin', 'Ernesto', 'Posada Joaquin',HASH('SHA256', STRINGTOUTF8('Gargamel123$$$123'),500),'USER'); -INSERT INTO PUBLIC.USERS_TABLE (EMAIL, FIRSTNAME, MIDDLENAME, LASTNAME,PASSWORD,WROLE) VALUES('melvynraul@gmail.com', 'Melvyn', 'Raúl', 'Gómez Guevara',HASH('SHA256', STRINGTOUTF8('Bolo123$$$123'),500),'USER'); diff --git a/main/resources/queries/hash.sql b/main/resources/queries/hash.sql deleted file mode 100644 index 09c885b..0000000 --- a/main/resources/queries/hash.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT HASH('SHA256', STRINGTOUTF8(?), 500) diff --git a/main/webapp/WEB-INF/faces-config.xml b/main/webapp/WEB-INF/faces-config.xml deleted file mode 100644 index e902377..0000000 --- a/main/webapp/WEB-INF/faces-config.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - org.primefaces.application.DialogActionListener - org.primefaces.application.DialogNavigationHandler - org.primefaces.application.DialogViewHandler - org.primefaces.mobile.application.MobileNavigationHandler - - en - - org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver - - /Bundle - bundle - - - diff --git a/main/webapp/WEB-INF/glassfish-resources b/main/webapp/WEB-INF/glassfish-resources deleted file mode 100644 index 19f278f..0000000 --- a/main/webapp/WEB-INF/glassfish-resources +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - diff --git a/main/webapp/WEB-INF/jboss-web.xml b/main/webapp/WEB-INF/jboss-web.xml deleted file mode 100644 index 43973a9..0000000 --- a/main/webapp/WEB-INF/jboss-web.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - /h2-database-service - diff --git a/main/webapp/WEB-INF/payara-web.xml b/main/webapp/WEB-INF/payara-web.xml deleted file mode 100644 index 28f2971..0000000 --- a/main/webapp/WEB-INF/payara-web.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - / - - - - Keep a copy of the generated servlet class' java code. - - - diff --git a/main/webapp/WEB-INF/web.xml b/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 22f2ca2..0000000 --- a/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,133 +0,0 @@ - - - H2 Database Service Listener - h2-database-service - - URL For Sample Database - db.url - jdbc:h2:tcp://localhost:50008/~/H2SampleDB;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;DATABASE_TO_UPPER=true;IGNORECASE=TRUE;MVCC=TRUE;LOCK_TIMEOUT=600000 - - - System Administrator for H2 Database - db.user - sa - - - Password for sa User - db.password - Welcome123$$1 - - - Database Listener TCP Port allowing network connections - db.tcpServer - -tcpAllowOthers -tcpPort 50008 - - - File Encoding for the Database - file.encoding - UTF-8 - - - Allow web console for others - webAllowOthers - true - - - - 30 - - - - Database Listener - org.h2.server.web.DbStarter - - - Web Console Servlet - H2Console - org.h2.server.web.WebServlet - - webAllowOthers value - webAllowOthers - true - - 1 - - - H2Console - /console/* - - - /index.jsf - index.html - - - java:app/jdbc/H2SampleDB - org.h2.jdbcx.JdbcDataSource - jdbc:h2:~/H2SampleDB - sa - Welcome123$$1 - - - - Theme selected - primefaces.THEME - omega - - - javax.faces.PROJECT_STAGE - Production - - - primefaces.FONT_AWESOME - true - - - Faces Servlet - javax.faces.webapp.FacesServlet - 1 - - - Faces Servlet - *.jsf - - - - com.livejournal.xtecuan.microprofile.web.filters.CharacterEncodingFilter - CharacterEncodingFilter - com.livejournal.xtecuan.microprofile.web.filters.CharacterEncodingFilter - - - CharacterEncodingFilter - /* - REQUEST - - - - - Application pages - /app/* - - - ADMIN - USER - - - - - - Application pages - /app/admin/* - - - ADMIN - - - - - USER - - - ADMIN - - diff --git a/main/webapp/app/admin/index.xhtml b/main/webapp/app/admin/index.xhtml deleted file mode 100644 index 8cb93ad..0000000 --- a/main/webapp/app/admin/index.xhtml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - h3 { - text-align: center; - } - - #{bundle.index_title} - - - - - - - - - #{bundle.index_link_text} - - - - - - - - \ No newline at end of file diff --git a/main/webapp/index.html b/main/webapp/index.html deleted file mode 100644 index b810baf..0000000 --- a/main/webapp/index.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - TODO supply a title - - - - - -
TODO write content
- - diff --git a/main/webapp/login.xhtml b/main/webapp/login.xhtml deleted file mode 100644 index c458223..0000000 --- a/main/webapp/login.xhtml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - h3 { - text-align: center; - } - - - - -
-
-
-

Login

- - - - - - - - - - - - - - - - - -
-
- - - - diff --git a/main/java/com/livejournal/xtecuan/microprofile/dto/UsersDTO.java b/src/main/java/com/livejournal/xtecuan/microprofile/dto/UsersDTO.java similarity index 100% rename from main/java/com/livejournal/xtecuan/microprofile/dto/UsersDTO.java rename to src/main/java/com/livejournal/xtecuan/microprofile/dto/UsersDTO.java diff --git a/src/main/java/com/livejournal/xtecuan/microprofile/facade/UsersFacade.java b/src/main/java/com/livejournal/xtecuan/microprofile/facade/UsersFacade.java index fcc27cc..b4fa7c0 100644 --- a/src/main/java/com/livejournal/xtecuan/microprofile/facade/UsersFacade.java +++ b/src/main/java/com/livejournal/xtecuan/microprofile/facade/UsersFacade.java @@ -10,11 +10,14 @@ */ package com.livejournal.xtecuan.microprofile.facade; +import com.livejournal.xtecuan.microprofile.dto.UsersDTO; import com.livejournal.xtecuan.microprofile.entities.Users; import com.livejournal.xtecuan.microprofile.sql.utils.QueryLoader; +import com.livejournal.xtecuan.microprofile.web.constants.WebConstants; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import javax.ejb.Stateless; @@ -99,4 +102,74 @@ public String getCompleteName(Users user) { } + public boolean checkIfPlainPasswordWithMark(String plainPasswordWithMark) { + boolean r = false; + + if (plainPasswordWithMark.contains(WebConstants.USER_PASS_PLAIN_MARK)) { + + boolean s = plainPasswordWithMark.indexOf(WebConstants.USER_PASS_PLAIN_MARK) != -1; + boolean e = plainPasswordWithMark.lastIndexOf(WebConstants.USER_PASS_PLAIN_MARK) != -1; + r = s && e; + + } + + return r; + } + + public String getPlainPasswordFromMarked(String plainPasswordWithMark) { + return plainPasswordWithMark.substring(2, plainPasswordWithMark.length() - 2); + } + + public UsersDTO fromEntity2DTO(Users user) { + UsersDTO dto = new UsersDTO(); + if (user.getUserid() != null) { + dto.setUserid(user.getUserid()); + } + dto.setPassword(user.getPassword()); + dto.setFirstname(user.getFirstname()); + dto.setLastname(user.getLastname()); + if (user.getMiddlename() != null && user.getMiddlename().length() > 0) { + dto.setMiddlename(user.getMiddlename()); + } + dto.setEmail(user.getEmail()); + dto.setWrole(user.getWrole()); + return dto; + } + + public Users fromDTO2Entity(UsersDTO dto) { + Users u = new Users(); + if (dto.getUserid() != null) { + u.setUserid(dto.getUserid()); + } + u.setPassword(dto.getPassword()); + u.setFirstname(dto.getFirstname()); + u.setLastname(dto.getLastname()); + if (dto.getMiddlename() != null && dto.getMiddlename().length() > 0) { + u.setMiddlename(dto.getMiddlename()); + } + u.setEmail(dto.getEmail()); + u.setWrole(dto.getWrole()); + return u; + } + + public void saveUser(UsersDTO dto) { + Users u = fromDTO2Entity(dto); + if (u.getUserid() != null) { + edit(u); + } else { + create(u); + } + } + + public void deleteUser(UsersDTO dto){ + Users u = fromDTO2Entity(dto); + remove(u); + } + + public List findAllUsers() { + List users = new ArrayList<>(); + findAll().forEach(u -> users.add(fromEntity2DTO(u))); + return users; + } + } diff --git a/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/MainBean.java b/src/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/MainBean.java similarity index 100% rename from main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/MainBean.java rename to src/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/MainBean.java diff --git a/src/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/UserSessionBean.java b/src/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/UserSessionBean.java index 08724a0..e07c3d9 100644 --- a/src/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/UserSessionBean.java +++ b/src/main/java/com/livejournal/xtecuan/microprofile/web/beans/utils/UserSessionBean.java @@ -25,6 +25,8 @@ public class UserSessionBean implements Serializable { private Users user; + private String passwordChange; + public Users getUser() { return user; } @@ -33,4 +35,12 @@ public void setUser(Users user) { this.user = user; } + public String getPasswordChange() { + return passwordChange; + } + + public void setPasswordChange(String passwordChange) { + this.passwordChange = passwordChange; + } + } diff --git a/src/main/java/com/livejournal/xtecuan/microprofile/web/constants/WebConstants.java b/src/main/java/com/livejournal/xtecuan/microprofile/web/constants/WebConstants.java index 455c657..d6dd217 100644 --- a/src/main/java/com/livejournal/xtecuan/microprofile/web/constants/WebConstants.java +++ b/src/main/java/com/livejournal/xtecuan/microprofile/web/constants/WebConstants.java @@ -17,4 +17,6 @@ public class WebConstants { public static final String USER_IN_SESSION = "USER_IN"; + public static final String USER_PASS_PLAIN_MARK = "##"; + public static final String[] ROLES = new String[]{"ADMIN", "USER"}; } diff --git a/src/main/java/de/rieckpil/blog/LoginBacking.java b/src/main/java/de/rieckpil/blog/LoginBacking.java index 8bee120..fbc0b7a 100644 --- a/src/main/java/de/rieckpil/blog/LoginBacking.java +++ b/src/main/java/de/rieckpil/blog/LoginBacking.java @@ -63,7 +63,7 @@ public void submit() throws IOException { currentUser.setUser(usersFacade.findByEmailAndPass(email, password)); facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Login succeed", null)); - externalContext.redirect(externalContext.getRequestContextPath() + "/app/index.jsf"); + externalContext.redirect(externalContext.getRequestContextPath() + "/app/main.jsf"); break; case NOT_DONE: } @@ -92,16 +92,13 @@ public String getEmail() { public void setEmail(String email) { this.email = email; } - - public String dbconsole() { - return "/app/admin/index.jsf?faces-redirect=true"; - } + @PostConstruct @Override public void init() { - - } + + } public UserSessionBean getCurrentUser() { return currentUser; @@ -109,8 +106,6 @@ public UserSessionBean getCurrentUser() { public void setCurrentUser(UserSessionBean currentUser) { this.currentUser = currentUser; - } - - + } } diff --git a/src/main/resources/Bundle.properties b/src/main/resources/Bundle.properties index 16d2a46..e6d1068 100644 --- a/src/main/resources/Bundle.properties +++ b/src/main/resources/Bundle.properties @@ -2,8 +2,25 @@ index_title=tadeocrud H2 DB Service index_header=tadeocrud Service index_link_text=tadeocrud H2 Database Service Console -app_index_title=Tadeo Crud Application -app_index_header=Welcome to Tadeo CRUD application! -app_index_logged_in=Logged-in as: -app_index_logout=Logout -app_index_dbconsole=DB Console \ No newline at end of file +app_main_title=Tadeo Crud Application +app_main_header=Welcome to Tadeo CRUD application! +app_main_logged_in=Logged-in as: +app_main_logout=Logout +app_main_dbconsole=DB Console +app_main_id=Id +app_main_email=E-Mail +app_main_fn=Firstname +app_main_mn=Middlename +app_main_ln=Lastname +app_main_rol=Rol +app_main_theader=List of Users +app_main_pass=Password +app_main_ereq=E-Mail is required +app_main_fnreq=Firstname required +app_main_lnreq=Lastname required +app_main_rolreq=Rol required +app_main_passreq=Password required +app_main_selone=Select One +app_main_bsave=Save +app_main_bupd=Update +app_main_bdel=Delete diff --git a/main/webapp/app/main.xhtml b/src/main/webapp/app/main.xhtml similarity index 100% rename from main/webapp/app/main.xhtml rename to src/main/webapp/app/main.xhtml