private void registerUser(HttpServletRequest request, HttpServletResponse response) {
		String key = request.getParameter(CommunityConstants.BASE64_PUBLIC_KEY);
		String nick = request.getParameter(CommunityConstants.NICKNAME);
		String remote_ip = request.getRemoteAddr();
		
		String username = request.getRemoteUser();
		logger.info("Registration request, username: "+  username + " / nick: " + nick);

		if (key == null) {
			logger.warning("Dropping registration request with null key from " + remote_ip);
			return;
		}

		if (nick == null) {
			logger.warning("Dropping registration request with null nick from " + remote_ip);
			return;
		}
		
		if( username == null) {
			logger.finer("Open server, using admin to register");
			username = "admin";
		}
		
		if (nick.length() > CommunityConstants.MAX_NICK_LENGTH) {
			logger.warning("Truncating lengthy nick: " + nick);
			nick = nick.substring(0, CommunityConstants.MAX_NICK_LENGTH);
		}

		logger.finer("Registration request: key=" + key + " remote_ip=" + remote_ip);

		try {
			BufferedWriter out = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
			try {
				CommunityDAO.get().registerUser(key, nick, remote_ip, username);

				response.setStatus(HttpServletResponse.SC_OK);
				out.append(CommunityConstants.REGISTRATION_SUCCESS);

				logger.finer("Successfully registered " + nick + " from " + request.getRemoteAddr());
			} catch (DuplicateRegistrationException e) {

				logger.finer("Duplicate registration " + nick + " from " + request.getRemoteAddr());
				response.setStatus(HttpServletResponse.SC_CONFLICT);
				out.append(CommunityConstants.REGISTRATION_DUPLICATE);
			} catch( TooManyRegistrationsException e ) {
				
				logger.finer(e.toString() + " / " + remote_ip);
				response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
				out.append(e.toString());
				
			} catch (Exception e) {
				e.printStackTrace();
				logger.warning(e.toString());

				response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
			} finally {
				out.flush();
				out.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}