2 * Copyright (C) 2016 - 2018 Free Software Foundation
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 java.text.MessageFormat;
20 import java.util.List;
21 import javax.ejb.Stateless;
22 import javax.persistence.Query;
23 import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean;
24 import org.mxchange.jusercore.model.user.User;
27 * A user password history EJB
29 * @author Roland Häder<roland@mxchange.org>
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 FinancialsUserPasswordHistorySessionBean extends BaseFinancialsEnterpriseBean implements UserPasswordHistorySessionBeanRemote {
37 private static final long serialVersionUID = 395_767_546_195_014L;
42 public FinancialsUserPasswordHistorySessionBean () {
43 // Call super constructor
48 @SuppressWarnings ("unchecked")
49 public List<PasswordHistory> getUserPasswordHistory (final User user) {
51 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
53 // user should not be null
56 throw new NullPointerException("user is null"); //NOI18N
57 } else if (user.getUserId() == null) {
59 throw new NullPointerException("user.userId is null"); //NOI18N
60 } else if (user.getUserId() < 1) {
62 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not allowed.", user.getUserId())); //NOI18N
66 final Query query = this.getEntityManager().createNamedQuery("AllUsersHistoryEntries", UserPasswordHistory.class); //NOI18N
69 query.setParameter("user", user); //NOI18N
72 final List<PasswordHistory> history = query.getResultList();
75 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): history.size()={1} - EXIT !", this.getClass().getSimpleName(), history.size())); //NOI18N