From: Roland Häder Date: Wed, 3 Aug 2016 08:27:47 +0000 (+0200) Subject: Please cherry-pick / fix Copyright: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=29472c2c0abc38f1943364803fdd788120aaab44;p=pizzaservice-mailer-ejb.git Please cherry-pick / fix Copyright: - added EJB for fetching user's full password history - this EJB implementes the corresponding (newly added) remote interface --- diff --git a/src/java/org/mxchange/jusercore/model/user/password_history/LandingUserPasswordHistorySessionBean.java b/src/java/org/mxchange/jusercore/model/user/password_history/LandingUserPasswordHistorySessionBean.java new file mode 100644 index 0000000..1c78026 --- /dev/null +++ b/src/java/org/mxchange/jusercore/model/user/password_history/LandingUserPasswordHistorySessionBean.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2016 Cho-Time GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jusercore.model.user.password_history; + +import de.chotime.landingpage.database.BaseLandingDatabaseBean; +import java.text.MessageFormat; +import java.util.List; +import javax.ejb.Stateless; +import javax.persistence.Query; +import org.mxchange.jusercore.model.user.User; + +/** + * A user password history EJB + *

+ * @author Roland Haeder + */ +@Stateless (name = "userPasswordHistory", description = "A stateless EJB for user's password history. This bean does return the full user's password history and not limited. The application then needs to limit it to it's purpose.") +public class LandingUserPasswordHistorySessionBean extends BaseLandingDatabaseBean implements UserPasswordHistorySessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 395_767_546_195_014L; + + /** + * Default constructor + */ + public LandingUserPasswordHistorySessionBean () { + } + + @Override + @SuppressWarnings ("unchecked") + public List getUserPasswordHistory (final User user) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N + + // user should not be null + if (null == user) { + // Abort here + throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserId() != null) { + // Not allowed here + throw new IllegalStateException(MessageFormat.format("user.userId must be null, is: {0}", user.getUserId())); //NOI18N + } + + // Get named query + Query query = this.getEntityManager().createNamedQuery("AllUsersHistoryEntries", UserPasswordHistory.class); //NOI18N + + // Set parameter + query.setParameter("user", user); //NOI18N + + // Get full history + List history = query.getResultList(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): history.size()={1} - EXIT !", this.getClass().getSimpleName(), history.size())); //NOI18N + + // Return it + return history; + } + +}