]> git.mxchange.org Git - jfinancials-mailer-ejb.git/blob - src/java/org/mxchange/jusercore/model/user/password_history/LandingUserPasswordHistorySessionBean.java
Please cherry-pick / fix Copyright:
[jfinancials-mailer-ejb.git] / src / java / org / mxchange / jusercore / model / user / password_history / LandingUserPasswordHistorySessionBean.java
1 /*
2  * Copyright (C) 2016 Cho-Time GmbH
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jusercore.model.user.password_history;
18
19 import de.chotime.landingpage.database.BaseLandingDatabaseBean;
20 import java.text.MessageFormat;
21 import java.util.List;
22 import javax.ejb.Stateless;
23 import javax.persistence.Query;
24 import org.mxchange.jusercore.model.user.User;
25
26 /**
27  * A user password history EJB
28  * <p>
29  * @author Roland Haeder<rhaeder@cho-time.de>
30  */
31 @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.")
32 public class LandingUserPasswordHistorySessionBean extends BaseLandingDatabaseBean implements UserPasswordHistorySessionBeanRemote {
33
34         /**
35          * Serial number
36          */
37         private static final long serialVersionUID = 395_767_546_195_014L;
38
39         /**
40          * Default constructor
41          */
42         public LandingUserPasswordHistorySessionBean () {
43         }
44
45         @Override
46         @SuppressWarnings ("unchecked")
47         public List<PasswordHistory> getUserPasswordHistory (final User user) {
48                 // Trace message
49                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
50
51                 // user should not be null
52                 if (null == user) {
53                         // Abort here
54                         throw new NullPointerException("user is null"); //NOI18N
55                 } else if (user.getUserId() != null) {
56                         // Not allowed here
57                         throw new IllegalStateException(MessageFormat.format("user.userId must be null, is: {0}", user.getUserId())); //NOI18N
58                 }
59
60                 // Get named query
61                 Query query = this.getEntityManager().createNamedQuery("AllUsersHistoryEntries", UserPasswordHistory.class); //NOI18N
62
63                 // Set parameter
64                 query.setParameter("user", user); //NOI18N
65
66                 // Get full history
67                 List<PasswordHistory> history = query.getResultList();
68
69                 // Trace message
70                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): history.size()={1} - EXIT !", this.getClass().getSimpleName(), history.size())); //NOI18N
71
72                 // Return it
73                 return history;
74         }
75
76 }