multilingual-ctap-web/src/main/java/com/ctapweb/web/server/user/UserServiceImpl.java
public UserInfo verifyUserCookies(HttpServletRequest request) 
			throws DatabaseException {
		String serviceName = "verifyUserCookies";
		logger.log(Level.TRACE, LogMarker.CTAP_SERVER_MARKER,
				"Received request for service verifyUserCookies. Verifying user cookies...");

		UserInfo userInfo = null;
		String email = null;
		long id = 0;
		String sessionToken = null;

		//get request cookies
		for(Cookie cookie : request.getCookies()) {
			String cookieName = cookie.getName();
			String cookieValue = cookie.getValue();
			if(SharedProperties.COOKIES_USER_EMAIL.equals(cookieName)) {
				email = cookieValue;
			} else if(SharedProperties.COOKIES_USER_ID.equals(cookieName)) {
				id = Long.parseLong(cookieValue);
			} else if(SharedProperties.COOKIES_USER_SESSIONTOKEN.equals(cookieName)) {
				sessionToken = cookieValue;
			}
		}

		if(email == null || id == 0 || sessionToken == null) {
			logger.log(Level.WARN, LogMarker.CTAP_SERVER_MARKER,
					"No user cookies or cookies incomplete. Verify user failed.");
			//cookies incomplete, return
			return null;
		}

		logger.log(Level.TRACE, LogMarker.CTAP_SERVER_MARKER,
				"Found user cookies: id = " + id + "; email = " + email + "; sessionToken = " + sessionToken + ". "
						+ "Querying database to verify cookie information...");
		String queryStr = ""
				+ "SELECT * FROM user_account "
				+ "WHERE id = ? "
				+ "     AND email = ? "
				+ "     AND session_token = ?";
		try {
			PreparedStatement ps = dbConnection.prepareStatement(queryStr);
			ps.setLong(1, id);
			ps.setString(2, email);
			ps.setString(3, sessionToken);

			ResultSet rs = ps.executeQuery();
			if(rs.isBeforeFirst()) {
				//verified
				userInfo = new UserInfo();
				userInfo.setId(id);
				userInfo.setEmail(email);
				userInfo.setSessionToken(sessionToken);

				logger.log(Level.TRACE, LogMarker.CTAP_SERVER_MARKER,
						"User cookies verified. Returning to client...");
			} else {
				logger.log(Level.TRACE, LogMarker.CTAP_SERVER_MARKER,
						"User cookies could not be verified. Returning to client...");
			}

		} catch (SQLException e) {
			throw logger.throwing(new DatabaseException(e.getMessage()));
		}

		logger.log(Level.TRACE, LogMarker.CTAP_SERVER_MARKER, 
				new ServiceRequestCompletedMessage(serviceName));
		return userInfo;	
	}
/**
	 * This version is used by server side programs.
	 * @param request
	 * @return
	 * @throws DatabaseException
	 */
This version is used by server side programs.
@param request
@return
@throws DatabaseException
This version is used by server side programs . @param request @return @throws DatabaseException
public UserInfo verifyUserCookies(HttpServletRequest request) 
			throws DatabaseException {
		String serviceName = "verifyUserCookies";
		logger.log(Level.TRACE, LogMarker.CTAP_SERVER_MARKER,
				"Received request for service verifyUserCookies. Verifying user cookies...");
		UserInfo userInfo = null;
		String email = null;
		long id = 0;
		String sessionToken = null;
		for(Cookie cookie : request.getCookies()) {
			String cookieName = cookie.getName();
			String cookieValue = cookie.getValue();
			if(SharedProperties.COOKIES_USER_EMAIL.equals(cookieName)) {
				email = cookieValue;
			} else if(SharedProperties.COOKIES_USER_ID.equals(cookieName)) {
				id = Long.parseLong(cookieValue);
			} else if(SharedProperties.COOKIES_USER_SESSIONTOKEN.equals(cookieName)) {
				sessionToken = cookieValue;
			}
		}
		if(email == null || id == 0 || sessionToken == null) {
			logger.log(Level.WARN, LogMarker.CTAP_SERVER_MARKER,
					"No user cookies or cookies incomplete. Verify user failed.");
			return null;
		}
		logger.log(Level.TRACE, LogMarker.CTAP_SERVER_MARKER,
				"Found user cookies: id = " + id + "; email = " + email + "; sessionToken = " + sessionToken + ". "
						+ "Querying database to verify cookie information...");
		String queryStr = ""
				+ "SELECT * FROM user_account "
				+ "WHERE id = ? "
				+ "     AND email = ? "
				+ "     AND session_token = ?";
		try {
			PreparedStatement ps = dbConnection.prepareStatement(queryStr);
			ps.setLong(1, id);
			ps.setString(2, email);
			ps.setString(3, sessionToken);
			ResultSet rs = ps.executeQuery();
			if(rs.isBeforeFirst()) {
				userInfo = new UserInfo();
				userInfo.setId(id);
				userInfo.setEmail(email);
				userInfo.setSessionToken(sessionToken);
				logger.log(Level.TRACE, LogMarker.CTAP_SERVER_MARKER,
						"User cookies verified. Returning to client...");
			} else {
				logger.log(Level.TRACE, LogMarker.CTAP_SERVER_MARKER,
						"User cookies could not be verified. Returning to client...");
			}
		} catch (SQLException e) {
			throw logger.throwing(new DatabaseException(e.getMessage()));
		}
		logger.log(Level.TRACE, LogMarker.CTAP_SERVER_MARKER, 
				new ServiceRequestCompletedMessage(serviceName));
		return userInfo;	
	}
public UserInfo verifyUserCookies ( HttpServletRequest request ) throws DatabaseException { String serviceName = "verifyUserCookies" ; logger . log ( Level . TRACE , LogMarker . CTAP_SERVER_MARKER , "Received request for service verifyUserCookies. Verifying user cookies..." ) ; UserInfo userInfo = null ; String email = null ; long id = 0 ; String sessionToken = null ; for ( Cookie cookie : request . getCookies ( ) ) { String cookieName = cookie . getName ( ) ; String cookieValue = cookie . getValue ( ) ; if ( SharedProperties . COOKIES_USER_EMAIL . equals ( cookieName ) ) { email = cookieValue ; } else if ( SharedProperties . COOKIES_USER_ID . equals ( cookieName ) ) { id = Long . parseLong ( cookieValue ) ; } else if ( SharedProperties . COOKIES_USER_SESSIONTOKEN . equals ( cookieName ) ) { sessionToken = cookieValue ; } } if ( email == null || id == 0 || sessionToken == null ) { logger . log ( Level . WARN , LogMarker . CTAP_SERVER_MARKER , "No user cookies or cookies incomplete. Verify user failed." ) ; return null ; } logger . log ( Level . TRACE , LogMarker . CTAP_SERVER_MARKER , "Found user cookies: id = " + id + "; email = " + email + "; sessionToken = " + sessionToken + ". " + "Querying database to verify cookie information..." ) ; String queryStr = "" + "SELECT * FROM user_account " + "WHERE id = ? " + "     AND email = ? " + "     AND session_token = ?" ; try { PreparedStatement ps = dbConnection . prepareStatement ( queryStr ) ; ps . setLong ( 1 , id ) ; ps . setString ( 2 , email ) ; ps . setString ( 3 , sessionToken ) ; ResultSet rs = ps . executeQuery ( ) ; if ( rs . isBeforeFirst ( ) ) { userInfo = new UserInfo ( ) ; userInfo . setId ( id ) ; userInfo . setEmail ( email ) ; userInfo . setSessionToken ( sessionToken ) ; logger . log ( Level . TRACE , LogMarker . CTAP_SERVER_MARKER , "User cookies verified. Returning to client..." ) ; } else { logger . log ( Level . TRACE , LogMarker . CTAP_SERVER_MARKER , "User cookies could not be verified. Returning to client..." ) ; } } catch ( SQLException e ) { throw logger . throwing ( new DatabaseException ( e . getMessage ( ) ) ) ; } logger . log ( Level . TRACE , LogMarker . CTAP_SERVER_MARKER , new ServiceRequestCompletedMessage ( serviceName ) ) ; return userInfo ; }
This version is used by server side programs.
This version is used by server side programs .
//get request cookies //cookies incomplete, return //verified