]> git.mxchange.org Git - addressbook-mailer-ejb.git/commitdiff
Please cherry-pick / fix Copyright:
authorRoland Häder <roland@mxchange.org>
Wed, 3 Aug 2016 08:27:47 +0000 (10:27 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 6 Aug 2016 20:50:48 +0000 (22:50 +0200)
- added EJB for fetching user's full password history
- this EJB implementes the corresponding (newly added) remote interface

src/java/org/mxchange/jusercore/model/user/password_history/LandingUserPasswordHistorySessionBean.java [new file with mode: 0644]

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 (file)
index 0000000..1c78026
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Haeder<rhaeder@cho-time.de>
+ */
+@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<PasswordHistory> 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<PasswordHistory> 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;
+       }
+
+}