// Path: src/main/java/org/owasp/oneliner/exceptions/NoSuchUserException.java
// public class NoSuchUserException extends Exception {
//     public static final NoSuchUserException NO_SUCH_USER = new NoSuchUserException("No such user");
// 
//     public NoSuchUserException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/org/owasp/oneliner/user/User.java
// @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
// @XmlRootElement
// public class User {
//     public final String userName;
//     public final String nickName;
//     private HashedPassword hashedPassword;
//     private SessionId sessionId;
// 
//     // Package default to give access to factory class only
//     User(String userName, String nickName, HashedPassword hashedPassword) {
//         this.userName = userName;
//         this.nickName = nickName;
//         this.hashedPassword = hashedPassword;
//     }
// 
//     @Override
//     public String toString() {
//         return userName + ":" + nickName;
//     }
// 
//     public String getUserName() {
//         return userName;
//     }
// 
//     public String getNickName() {
//         return nickName;
//     }
// 
//     public HashedPassword getHashedPassword() {
//         return hashedPassword;
//     }
// 
//     public SessionId getSessionId() {
//         return sessionId;
//     }
// 
//     public void setSessionId(SessionId sessionId) {
//         this.sessionId = sessionId;
//     }
// 
//     public boolean hasActiveSession() {
//         Date now = new Date();
//         return now.before(sessionId.expires()) && now.after(sessionId.starts());
//     }
// 
//     // Here for JAXB
//     public User() {
//         this.userName = null;
//         this.nickName = null;
//     }
// }


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.owasp.oneliner.exceptions.NoSuchUserException;
import org.owasp.oneliner.user.User;
import java.util.HashSet;
import java.util.Set;
package org.owasp.oneliner.authentication;



/**
 * Author: @johnwilander
 * Date: 2010-nov-06
 */
public class UserDataBase {
    private static final Log logger = LogFactory.getLog(UserDataBase.class);
    private final Set<User> userSet = new HashSet<User>();

    public UserDataBase() {}

    public UserDataBase(Set<User> initialUsers) {
        userSet.addAll(initialUsers);
    }

    public boolean addUser(User user) {
        boolean wasAdded;
        synchronized (userSet) {
            wasAdded = userSet.add(user);
        }
        if (!wasAdded) {
            logger.info("User " + user + " was already present in the database.");
        }
        return wasAdded;
    }

// Path: src/main/java/org/owasp/oneliner/exceptions/NoSuchUserException.java
// public class NoSuchUserException extends Exception {
//     public static final NoSuchUserException NO_SUCH_USER = new NoSuchUserException("No such user");
// 
//     public NoSuchUserException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/org/owasp/oneliner/user/User.java
// @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
// @XmlRootElement
// public class User {
//     public final String userName;
//     public final String nickName;
//     private HashedPassword hashedPassword;
//     private SessionId sessionId;
// 
//     // Package default to give access to factory class only
//     User(String userName, String nickName, HashedPassword hashedPassword) {
//         this.userName = userName;
//         this.nickName = nickName;
//         this.hashedPassword = hashedPassword;
//     }
// 
//     @Override
//     public String toString() {
//         return userName + ":" + nickName;
//     }
// 
//     public String getUserName() {
//         return userName;
//     }
// 
//     public String getNickName() {
//         return nickName;
//     }
// 
//     public HashedPassword getHashedPassword() {
//         return hashedPassword;
//     }
// 
//     public SessionId getSessionId() {
//         return sessionId;
//     }
// 
//     public void setSessionId(SessionId sessionId) {
//         this.sessionId = sessionId;
//     }
// 
//     public boolean hasActiveSession() {
//         Date now = new Date();
//         return now.before(sessionId.expires()) && now.after(sessionId.starts());
//     }
// 
//     // Here for JAXB
//     public User() {
//         this.userName = null;
//         this.nickName = null;
//     }
// }


// Path: src/main/java/org/owasp/oneliner/authentication/UserDataBase.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.owasp.oneliner.exceptions.NoSuchUserException;
import org.owasp.oneliner.user.User;
import java.util.HashSet;
import java.util.Set;

package org.owasp.oneliner.authentication;



/**
 * Author: @johnwilander
 * Date: 2010-nov-06
 */
public class UserDataBase {
    private static final Log logger = LogFactory.getLog(UserDataBase.class);
    private final Set<User> userSet = new HashSet<User>();

    public UserDataBase() {}

    public UserDataBase(Set<User> initialUsers) {
        userSet.addAll(initialUsers);
    }

    public boolean addUser(User user) {
        boolean wasAdded;
        synchronized (userSet) {
            wasAdded = userSet.add(user);
        }
        if (!wasAdded) {
            logger.info("User " + user + " was already present in the database.");
        }
        return wasAdded;
    }

    public User getUserByUserName(String userName) throws NoSuchUserException {