@POST
	@Consumes("application/json")
	@Path("authenticate")
	public AuthenticationResult authenticate( AuthenticationRequest request ) {
		// TODO: This is only a basic mock-like implementation. Will require something more solid for real projects.
		
		// Get the record for the given email.
		User foundUser = null ;
		try {
			foundUser = userManagement.txFindUser( request.email );
		} catch (DuplicateUserEmailDetected e) {
			// We'll use the error-level of logging as a flag to ops that there's interventions needed.
			logger.error("We got multiple user accounts with this email, can't continue processing this request.", e);
		}
		
		// failResult will be used if we find a problem.
		AuthenticationResult failResult = new AuthenticationResult();
		failResult.setState(Result.DENIED);
		
		// TODO: Should log something for each fail type.
		
		// Fail check: user doesn't exist.
		if( foundUser == null ) {
			logger.info("User not found.");
			return failResult;
		}
		
		// Fail check: password mismatch.
		boolean match = request.password.equals(foundUser.getPassword());
		// Passwords don't match? No good reason to continue.
		if( !match ) {
			logger.info("Failed password authentication.");
			return failResult ;
		}
		
		// TODO: Review, could we want simultaneous logins? Web/mobile client for example?
		// If there's an old existing (valid) session, we invalidate it. [i.e. logout]
		UserSession oldExistingSession = null ;
		
		try {
			oldExistingSession = txLogoutExistingSession( foundUser.getId() );
		} catch (DuplicateUserEmailDetected e) {
			logger.error("We got multiple user accounts with this email, can't continue processing this request.", e);
		}
		
		if( oldExistingSession != null ) {
			logger.info("Had an old session we invalidated.");
		}
		
		// Build and save new session.
		UserSession newSession = txLogin(foundUser.getId());
		
		AuthenticationResult result = new AuthenticationResult();
		result.setSessionKey(newSession.getSessionKey());
		
		return result ;
	}