+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.container.login;
-
-import java.io.Serializable;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * A container for login data
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface LoginContainer extends Serializable {
-
- /**
- * Getter for user instance
- * <p>
- * @return User instance
- */
- User getUser ();
-
- /**
- * Setter for user instance
- * <p>
- * @param user User instance
- */
- void setUser (final User user);
-
- /**
- * Getter for user password
- * <p>
- * @return User password
- */
- String getUserPassword ();
-
- /**
- * Setter for user password
- * <p>
- * @param userPassword User password
- */
- void setUserPassword (final String userPassword);
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.container.login;
-
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * A user login container
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class UserLoginContainer implements LoginContainer {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 158_768_718_689_760_186L;
-
- /**
- * User instance
- */
- private User user;
-
- /**
- * Clear-text password
- */
- private String userPassword;
-
- /**
- * Constructor with user instance and clear-text password
- * <p>
- * @param user User instance
- * @param userPassword Clear-text password
- */
- public UserLoginContainer (final User user, final String userPassword) {
- // Is both set?
- if (null == user) {
- // Throw NPE
- throw new NullPointerException("user is null"); //NOI18N
- } else if (null == userPassword) {
- // Throw NPE again
- throw new NullPointerException("userPassword is null"); //NOI18N
- } else if (userPassword.isEmpty()) {
- // Empty password
- throw new IllegalArgumentException("user password is empty."); //NOI18N
- }
-
- // Set both
- this.user = user;
- this.userPassword = userPassword;
- }
-
- @Override
- public User getUser () {
- return this.user;
- }
-
- @Override
- public void setUser (final User user) {
- this.user = user;
- }
-
- @Override
- public String getUserPassword () {
- return this.userPassword;
- }
-
- @Override
- public void setUserPassword (final String userPassword) {
- this.userPassword = userPassword;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.events.confirmation;
-
-import java.io.Serializable;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An event interface, fired if a new user has registered
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface ObservableUserConfirmedAccountEvent extends Serializable {
-
- /**
- * Getter for user instance
- * <p>
- * @return User instance
- */
- User getConfirmedUser ();
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.events.confirmation;
-
-import java.text.MessageFormat;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An event, fired if a new confirmedUser has confirmed
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class UserConfirmedAccountEvent implements ObservableUserConfirmedAccountEvent {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 575_412_375_267_190L;
-
- /**
- * Newly confirmed user
- */
- private final User confirmedUser;
-
- /**
- * Constructor with newly confirmed confirmedUser
- * <p>
- * @param confirmedUser Newly confirmed confirmedUser
- */
- public UserConfirmedAccountEvent (final User confirmedUser) {
- // Is the confirmed user instance valid?
- if (null == confirmedUser) {
- // Throw NPE
- throw new NullPointerException("confirmedUser is null"); //NOI18N
- } else if (confirmedUser.getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("confirmedUser.userId is null"); //NOI18N
- } else if (confirmedUser.getUserId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("confirmedUser.userId={0} is invalid.", confirmedUser.getUserId())); //NOI18N
- }
-
- // Set it here
- this.confirmedUser = confirmedUser;
- }
-
- @Override
- public User getConfirmedUser () {
- return this.confirmedUser;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.events.login;
-
-import java.io.Serializable;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An interface for events after the user has logged in
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface ObservableUserLoggedInEvent extends Serializable {
-
- /**
- * Getter for user instance
- * <p>
- * @return User instance
- */
- User getLoggedInUser ();
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.events.login;
-
-import java.text.MessageFormat;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * This event is fired when the loggedInUser has logged in
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class UserLoggedInEvent implements ObservableUserLoggedInEvent {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 163_294_958_817_560L;
-
- /**
- * User instance
- */
- private final User loggedInUser;
-
- /**
- * Constructor with updated user instance
- * <p>
- * @param loggedInUser Updated user instance
- */
- public UserLoggedInEvent (final User loggedInUser) {
- // Is the logged-in user instance valid?
- if (null == loggedInUser) {
- // Throw NPE
- throw new NullPointerException("loggedInUser is null"); //NOI18N
- } else if (loggedInUser.getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("loggedInUser.userId is null"); //NOI18N
- } else if (loggedInUser.getUserId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("loggedInUser.userId={0} is invalid.", loggedInUser.getUserId())); //NOI18N
- }
-
- // Set loggedInUser
- this.loggedInUser = loggedInUser;
- }
-
- @Override
- public User getLoggedInUser () {
- return this.loggedInUser;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.events.logout;
-
-import java.io.Serializable;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An interface for events after the user has logged in
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface ObservableUserLogoutEvent extends Serializable {
-
- /**
- * Getter for user instance
- * <p>
- * @return User instance
- */
- User getLoggedOutUser ();
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.events.logout;
-
-import java.text.MessageFormat;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * This event is fired when the loggedOutUser has logged in
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class UserLogoutEvent implements ObservableUserLogoutEvent {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 58_617_641_290_620L;
-
- /**
- * User instance
- */
- private final User loggedOutUser;
-
- /**
- * Constructor with updated loggedOutUser instance
- * <p>
- * @param loggedOutUser Updated loggedOutUser instance
- */
- public UserLogoutEvent (final User loggedOutUser) {
- // Is the logged-in user instance valid?
- if (null == loggedOutUser) {
- // Throw NPE
- throw new NullPointerException("loggedOutUser is null"); //NOI18N
- } else if (loggedOutUser.getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("loggedOutUser.userId is null"); //NOI18N
- } else if (loggedOutUser.getUserId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("loggedOutUser.userId={0} is invalid.", loggedOutUser.getUserId())); //NOI18N
- }
-
- // Set loggedOutUser
- this.loggedOutUser = loggedOutUser;
- }
-
- @Override
- public User getLoggedOutUser () {
- return this.loggedOutUser;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.events.registration;
-
-import java.io.Serializable;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An event interface, fired if a new user has registered
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface ObservableUserRegisteredEvent extends Serializable {
-
- /**
- * Getter for user instance
- * <p>
- * @return User instance
- */
- User getRegisteredUser ();
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.events.registration;
-
-import java.text.MessageFormat;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An event, fired if a new registeredUser has registered
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class UserRegisteredEvent implements ObservableUserRegisteredEvent {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 186_956_974_127_691L;
-
- /**
- * Newly registered registeredUser;
- */
- private final User registeredUser;
-
- /**
- * Constructor with newly registered registeredUser
- * <p>
- * @param registeredUser Newly registered registeredUser
- */
- public UserRegisteredEvent (final User registeredUser) {
- // Is the registered user instance valid?
- if (null == registeredUser) {
- // Throw NPE
- throw new NullPointerException("registeredUser is null"); //NOI18N
- } else if (registeredUser.getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("registeredUser.userId is null"); //NOI18N
- } else if (registeredUser.getUserId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("registeredUser.userId={0} is invalid.", registeredUser.getUserId())); //NOI18N
- }
-
- // Set it here
- this.registeredUser = registeredUser;
- }
-
- /**
- * Getter for registeredUser instance
- * <p>
- * @return User instance
- */
- @Override
- public User getRegisteredUser () {
- return this.registeredUser;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.events.resendlink;
-
-import java.io.Serializable;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An event interface, fired if a user has resend confirmation link
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface ObservableUserResendLinkAccountEvent extends Serializable {
-
- /**
- * Getter for user instance
- * <p>
- * @return User instance
- */
- User getResendLinkUser ();
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.events.resendlink;
-
-import java.text.MessageFormat;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An event, fired if a user has resend confirmation link
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class UserResendLinkAccountEvent implements ObservableUserResendLinkAccountEvent {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 575_412_375_267_190L;
-
- /**
- * user resend confirmation link
- */
- private final User resendLinkUser;
-
- /**
- * Constructor with user resend confirmation link
- * <p>
- * @param resendLinkUser User resend confirmation link
- */
- public UserResendLinkAccountEvent (final User resendLinkUser) {
- // Is the confirmed user instance valid?
- if (null == resendLinkUser) {
- // Throw NPE
- throw new NullPointerException("resendLinkUser is null"); //NOI18N
- } else if (resendLinkUser.getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("resendLinkUser.userId is null"); //NOI18N
- } else if (resendLinkUser.getUserId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("resendLinkUser.userId={0} is invalid.", resendLinkUser.getUserId())); //NOI18N
- }
-
- // Set it here
- this.resendLinkUser = resendLinkUser;
- }
-
- @Override
- public User getResendLinkUser () {
- return this.resendLinkUser;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.events.user.password_change;
-
-import java.io.Serializable;
-import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
-
-/**
- * An interface for events being fired when a user updates personal data.
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface ObservableUpdatedUserPasswordEvent extends Serializable {
-
- /**
- * Getter for password history entry
- * <p>
- * @return Password history entry
- */
- PasswordHistory getPasswordHistory ();
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.events.user.password_change;
-
-import java.text.MessageFormat;
-import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
-
-/**
- * An event being fired when the user has updated personal data
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class UpdatedUserPasswordEvent implements ObservableUpdatedUserPasswordEvent {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 14_785_787_174_676_290L;
-
- /**
- * Updated user instance
- */
- private final PasswordHistory passwordHistory;
-
- /**
- * Constructor with updated user instance
- * <p>
- * @param passwordHistory Updated user instance
- */
- public UpdatedUserPasswordEvent (final PasswordHistory passwordHistory) {
- // Is the user instance valid?
- if (null == passwordHistory) {
- // Throw NPE
- throw new NullPointerException("passwordHistory is null"); //NOI18N
- } else if (passwordHistory.getUserPasswordHistoryUser() == null) {
- // Throw NPE again
- throw new NullPointerException("passwordHistory.userPasswordHistoryUser is null"); //NOI18N
- } else if (passwordHistory.getUserPasswordHistoryUser().getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("passwordHistory.userPasswordHistoryUser.userId is null"); //NOI18N
- } else if (passwordHistory.getUserPasswordHistoryUser().getUserId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("passwordHistory.userPasswordHistoryUser.userId={0} is invalid.", passwordHistory.getUserPasswordHistoryUser().getUserId())); //NOI18N
- }
-
- // Set it here
- this.passwordHistory = passwordHistory;
- }
-
- @Override
- public PasswordHistory getPasswordHistory () {
- return this.passwordHistory;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.exceptions;
-
-import java.text.MessageFormat;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An exception thrown when the entered password did not match the stored
- * password.
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class UserPasswordMismatchException extends Exception {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 97_283_567_871_569_401L;
-
- /**
- * Creates an exception with given user instance
- * <p>
- * @param user User instance
- */
- public UserPasswordMismatchException (final User user) {
- super(MessageFormat.format("Password for user {0} does not match stored password.", user));
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.exceptions;
-
-import java.text.MessageFormat;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An exception thrown when the entered password did not match the stored
- * password.
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class UserPasswordRepeatMismatchException extends Exception {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 51_782_450_671_256_594L;
-
- /**
- * Creates an exception with given user instance
- * <p>
- * @param user User instance
- */
- public UserPasswordRepeatMismatchException (final User user) {
- super(MessageFormat.format("Passwords don't match, userId={0}", user.getUserId()));
- }
-
-}
import java.util.Calendar;
import java.util.Properties;
import java.util.Random;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.commons.codec.digest.Crypt;
-import org.apache.commons.codec.digest.DigestUtils;
import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.contact.ContactUtils;
-import org.mxchange.jusercore.container.login.LoginContainer;
/**
* An utilities class for users
UserUtils.PASSWORD_ALPHABET_PARTS[3];
}
- /**
- * Calculates entropy value for given password, higher means better. This
- * method is based on
- * http://stackoverflow.com/questions/14591701/how-to-check-password-strength-in-vaadin
- * <p>
- * @param password Clear text password
- * <p>
- * @return Entropy factor
- */
- public static double calculateEntropyFactor (final String password) {
- // Should not be null
- if (null == password) {
- // Throw NPE
- throw new NullPointerException("password is null"); //NOI18N
- }
-
- // Calculate it
- double entropyFactor = password.length() * Math.log10(PASSWORD_ALPHABET.length()) / Math.log10(2);
-
- // Return it
- return entropyFactor;
- }
-
- /**
- * Determines given password's strength: 0 = worst, 100 = best. This method
- * is based on
- * http://stackoverflow.com/questions/1614811/how-do-i-measure-the-strength-of-a-password
- * <p>
- * @param password Clear-text password
- * <p>
- * @return Strength of password
- */
- public static double calculatePasswordScore (final String password) {
- // Should not be null
- if (null == password) {
- // Throw NPE
- throw new NullPointerException("password is null"); //NOI18N
- } else if (password.isEmpty()) {
- // Is empty
- return 0.0f;
- }
-
- // Init score
- double score = 0.0f;
-
- // Password length
- score += password.length() * calculateEntropyFactor(password) / 100;
-
- // Password has 3 numbers
- if (ifRegExFoundInString("(.*[0-9].*[0-9].*[0-9].*)+", password)) { //NOI18N
- score += 5;
- }
-
- // Password has 2 symbols
- if (ifRegExFoundInString("(.*[!,@,#,$,%,^,&,*,/,?,_,~,=,.,-,;,:].*[!,@,#,$,%,^,&,*,/,?,_,~,=,.,-,;,:].*)+", password)) { //NOI18N
- score += 5;
- }
-
- // Password has Upper and Lower chars
- if (ifRegExFoundInString("(.*[a-z].*[A-Z])|([A-Z].*[a-z].*)+", password)) { //NOI18N
- score += 10;
- }
-
- // Password has number and chars
- if (ifRegExFoundInString("(.*[a-zA-Z].*)+", password) && ifRegExFoundInString("(.*[0-9].*)+", password)) { //NOI18N
- score += 15;
- }
-
- // Password has number and symbol
- if (ifRegExFoundInString("(.*[!,@,#,$,%,^,&,*,/,?,_,~,=,.,-,;,:].*)+", password) && ifRegExFoundInString("(.*[0-9].*)+", password)) { //NOI18N
- score += 15;
- }
-
- // Password has char and symbol
- if (ifRegExFoundInString("(.*[!,@,#,$,%,^,&,*,/,?,_,~,=,.,-,;,:].*)+", password) && ifRegExFoundInString("(.*[a-zA-Z].*)+", password)) { //NOI18N
- score += 15;
- }
-
- // Password is just numbers or chars
- if (ifRegExFoundInString("^[a-zA-Z]+$", password) || ifRegExFoundInString("^[0-9]+$", password)) { //NOI18N
- score -= 10;
- }
-
- // Larger than 100 is not allowed
- score = Math.max(Math.min(score, 100.0f), 0.0f);
-
- // Return it
- return score;
- }
-
/**
* Copies all attributes from other user object to target
* <p>
targetUser.setUserMustChangePassword(sourceUser.getUserMustChangePassword());
}
- /**
- * Creates a pseudo-random password with given length
- * <p>
- * @param length Length of the password
- * <p>
- * @return Pseudo-random password
- */
- public static String createRandomPassword (final Integer length) {
- // Parameter should be valid
- if (null == length) {
- // Throw NPE
- throw new NullPointerException("length is null"); //NOI18N
- } else if (length < PASSWORD_MINIMUM_LENGTH) {
- // To weak passwords
- throw new IllegalArgumentException(MessageFormat.format("Password length {0} is to short, minimum: {1}", length, PASSWORD_MINIMUM_LENGTH)); //NOI18N
- }
-
- // Init variable
- StringBuilder password = new StringBuilder(length);
-
- // Start creating it
- for (int i = 0; i < length; i++) {
- // Take random part
- String alphabet = PASSWORD_ALPHABET_PARTS[RANDOM_NUMBER_GENERATOR.nextInt(PASSWORD_ALPHABET_PARTS.length)];
-
- // Generate random number
- int pos = RANDOM_NUMBER_GENERATOR.nextInt(alphabet.length());
-
- // Get char at this position and add it to the final password
- password.append(String.valueOf(alphabet.charAt(pos)));
- }
-
- // Should have the wanted length
- assert (password.length() == length) : MessageFormat.format("Password length {0} doesn't match requested: {1}", password.length(), length); //NOI18N
-
- // Return it
- return password.toString();
- }
-
- /**
- * Hashes given user password and adds a salt to it
- * <p>
- * @param userPassword User password to be hashed
- * <p>
- * @return Hashed user password
- */
- public static String encryptPassword (final String userPassword) {
- // Is it null or empty?
- if (null == userPassword) {
- // Throw NPE
- throw new NullPointerException("userPassword is null"); //NOI18N
- } else if (userPassword.isEmpty()) {
- // Empty passwords are hardcoded not allowed due to security risks
- throw new IllegalArgumentException("userPassword is empty"); //NOI18N
- }
-
- // Generate large number
- String number = Long.toString(RANDOM_NUMBER_GENERATOR.nextLong() * 10_000_000_000L);
-
- // Generate salt
- String salt = Crypt.crypt(number);
-
- // First encrypt password
- String encryptedPassword = Crypt.crypt(userPassword, salt);
-
- // Return it
- return encryptedPassword;
- }
-
/**
* Generates a pseudo-random user name
* <p>
return userName;
}
- /**
- * Generate a key suitable for confirmation. This is basicly a large and
- * strong hash with a lop entropy.
- * <p>
- * @param user User instance to use as additional entropy source
- * <p>
- * @return Generated key
- */
- public static String generatedConfirmationKey (final User user) {
- /**
- * Generates random string by creating a random, encrypted password
- * which gives nice entropy to start with.
- */
- StringBuilder key = new StringBuilder(encryptPassword(generateRandomUserName()));
-
- // Is user set?
- if (user instanceof User) {
- // Add it's name, too
- key.append(":").append(user); //NOI18N
-
- // Is user name set?
- if (user.getUserName() instanceof String) {
- // Add it
- key.append(":").append(user.getUserName()); //NOI18N
- }
-
- // Is password set?
- if (user.getUserEncryptedPassword() instanceof String) {
- // Add it, too
- key.append(":").append(user.getUserEncryptedPassword()); //NOI18N
- }
-
- // Get contact instance
- Contact contact = user.getUserContact();
-
- // Is contact set?
- if (contact instanceof Contact) {
- // Add it, too
- key.append(":").append(contact); //NOI18N
-
- // Is email address set?
- if (contact.getContactEmailAddress() instanceof String) {
- // Add it, too
- key.append(":").append(contact.getContactEmailAddress()); //NOI18N
- }
- }
- }
-
- // Hash key
- String hash = DigestUtils.sha256Hex(key.toString());
-
- // Return it
- return hash;
- }
-
/**
* Returns a Properties object from given user instance.
* <p>
return dateTime;
}
- /**
- * Checks if password from container matches the updatedUser's password
- * <p>
- * @param container Container holding user instance and clear-text
- * password
- * @param updatedUser Updated user instance from database
- * <p>
- * @return Whether the password matches
- */
- public static boolean ifPasswordMatches (final LoginContainer container, final User updatedUser) {
- // Validate parameters
- if (null == container) {
- // Throw NPE
- throw new NullPointerException("container is null"); //NOI18N
- } else if (null == updatedUser) {
- // And again NPE ...
- throw new NullPointerException("updatedUser is null"); //NOI18N
- } else if (container.getUser() == null) {
- // NPE for user in container
- throw new NullPointerException("container.user is null"); //NOI18N
- } else if (container.getUserPassword() == null) {
- // NPE for user password in container
- throw new NullPointerException("container.userPassword is null"); //NOI18N
- } else if (container.getUserPassword().isEmpty()) {
- // Empty password in container
- throw new IllegalArgumentException("container.userPassword is empty"); //NOI18N
- }
-
- // Call below method
- return ifPasswordMatches(container.getUserPassword(), updatedUser);
- }
-
- /**
- * Checks if direct password the updatedUser's password
- * <p>
- * @param clearTextPassword Clear-text (direct) password
- * @param updatedUser Updated user instance from database
- * <p>
- * @return Whether the password matches
- */
- public static boolean ifPasswordMatches (final String clearTextPassword, final User updatedUser) {
- // Validate parameters
- if (null == clearTextPassword) {
- // Throw NPE
- throw new NullPointerException("clearTextPassword is null"); //NOI18N
- } else if (clearTextPassword.isEmpty()) {
- // NPE for user in container
- throw new NullPointerException("clearTextPassword is empty."); //NOI18N
- } else if (null == updatedUser) {
- // And again NPE ...
- throw new NullPointerException("updatedUser is null"); //NOI18N
- }
-
- // First encrypt password
- String encryptedPassword = Crypt.crypt(clearTextPassword, updatedUser.getUserEncryptedPassword());
-
- // Is it matching?
- return encryptedPassword.equals(updatedUser.getUserEncryptedPassword());
- }
-
- /**
- * Checks if password from container matches with from user instance.
- * <p>
- * @param container Container holding user instance and clear-text password
- * <p>
- * @return Whether it maches
- */
- public static boolean ifPasswordMatches (final LoginContainer container) {
- // Validate parameters
- if (null == container) {
- // Throw NPE
- throw new NullPointerException("container is null"); //NOI18N
- } else if (container.getUser() == null) {
- // NPE for user in container
- throw new NullPointerException("container.user is null"); //NOI18N
- } else if (container.getUserPassword() == null) {
- // NPE for user password in container
- throw new NullPointerException("container.userPassword is null"); //NOI18N
- } else if (container.getUserPassword().isEmpty()) {
- // Empty password in container
- throw new IllegalArgumentException("container.userPassword is empty"); //NOI18N
- }
-
- // Call other method
- return ifPasswordMatches(container.getUserPassword(), container.getUser());
- }
-
- /**
- * Checks if the regular expression is found in given string
- * <p>
- * @param pattern Regular expression
- * @param str String
- * <p>
- * @return Whether it is found
- */
- private static boolean ifRegExFoundInString (final String pattern, final String str) {
- // Mus be valid parameters
- if (null == pattern) {
- // Throw NPE
- throw new NullPointerException("pattern is null"); //NOI18N
- } else if (pattern.isEmpty()) {
- // Is empty
- throw new IllegalArgumentException("pattern is empty"); //NOI18N
- } else if (null == str) {
- // Throw NPE
- throw new NullPointerException("str is null"); //NOI18N
- }
-
- // Compile pattern
- Pattern r = Pattern.compile(pattern);
-
- // Get matcher
- Matcher m = r.matcher(str);
-
- // Check if it is found
- return m.find();
- }
-
/**
* No instance from this class
*/