2 * Copyright (C) 2016 Cho-Time GmbH
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.
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.
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/>.
17 package org.mxchange.jusercore.model.user.password_history;
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;
27 * A user password history EJB
29 * @author Roland Haeder<rhaeder@cho-time.de>
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 {
37 private static final long serialVersionUID = 395_767_546_195_014L;
42 public LandingUserPasswordHistorySessionBean () {
46 @SuppressWarnings ("unchecked")
47 public List<PasswordHistory> getUserPasswordHistory (final User user) {
49 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
51 // user should not be null
54 throw new NullPointerException("user is null"); //NOI18N
55 } else if (user.getUserId() == null) {
57 throw new NullPointerException("user.userId is null"); //NOI18N
58 } else if (user.getUserId() < 1) {
60 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not allowed.", user.getUserId())); //NOI18N
64 Query query = this.getEntityManager().createNamedQuery("AllUsersHistoryEntries", UserPasswordHistory.class); //NOI18N
67 query.setParameter("user", user); //NOI18N
70 List<PasswordHistory> history = query.getResultList();
73 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): history.size()={1} - EXIT !", this.getClass().getSimpleName(), history.size())); //NOI18N