// Path: src/main/java/org/owasp/oneliner/authentication/UserDataBase.java
// 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 {
//         for (User user : userSet) {
//             if (user.getUserName().equals(userName)) {
//                 return user;
//             }
//         }
//         throw NoSuchUserException.NO_SUCH_USER;
//     }
// }
// 
// 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/user/UserFactory.java
// public class UserFactory {
//     @Resource
//     HashedPasswordFactory hashedPasswordFactory;
// 
//     public User createUser(String userName, String nickName, String password) {
//         return createUser(userName, nickName, hashedPasswordFactory.createHashedPassword(password));
//     }
// 
//     public User createUser(String userName, String nickName, HashedPassword hashedPassword) {
//         return new User(userName, nickName, hashedPassword);
//     }
// }


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.owasp.oneliner.authentication.UserDataBase;
import org.owasp.oneliner.exceptions.NoSuchUserException;
import org.owasp.oneliner.user.User;
import org.owasp.oneliner.user.UserFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
package org.owasp.oneliner.rest;



/**
 * Author: @johnwilander
 * Date: 2010-nov-06
 */
@Path("/user")
@Component
public class UserResource {
	private static final Log logger = LogFactory.getLog(UserResource.class);

    @Resource
    private UserDataBase userDataBase;
    @Resource
    private UserFactory userFactory;

    @GET
    @Path("/{userName}")
    @Produces({MediaType.APPLICATION_JSON})
    public Response getUser(@PathParam("userName") String userName) throws NoSuchUserException {
// Path: src/main/java/org/owasp/oneliner/authentication/UserDataBase.java
// 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 {
//         for (User user : userSet) {
//             if (user.getUserName().equals(userName)) {
//                 return user;
//             }
//         }
//         throw NoSuchUserException.NO_SUCH_USER;
//     }
// }
// 
// 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/user/UserFactory.java
// public class UserFactory {
//     @Resource
//     HashedPasswordFactory hashedPasswordFactory;
// 
//     public User createUser(String userName, String nickName, String password) {
//         return createUser(userName, nickName, hashedPasswordFactory.createHashedPassword(password));
//     }
// 
//     public User createUser(String userName, String nickName, HashedPassword hashedPassword) {
//         return new User(userName, nickName, hashedPassword);
//     }
// }


// Path: src/main/java/org/owasp/oneliner/rest/UserResource.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.owasp.oneliner.authentication.UserDataBase;
import org.owasp.oneliner.exceptions.NoSuchUserException;
import org.owasp.oneliner.user.User;
import org.owasp.oneliner.user.UserFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

package org.owasp.oneliner.rest;



/**
 * Author: @johnwilander
 * Date: 2010-nov-06
 */
@Path("/user")
@Component
public class UserResource {
	private static final Log logger = LogFactory.getLog(UserResource.class);

    @Resource
    private UserDataBase userDataBase;
    @Resource
    private UserFactory userFactory;

    @GET
    @Path("/{userName}")
    @Produces({MediaType.APPLICATION_JSON})
    public Response getUser(@PathParam("userName") String userName) throws NoSuchUserException {
        User user = userDataBase.getUserByUserName(userName);