// Path: acmeair-customer-common/src/main/java/com/acmeair/entities/CustomerSession.java
// public interface CustomerSession {
// 
// 	String SESSIONID_COOKIE_NAME = "sessionid";
// 
// 	String getId();
// 
// 
// 	String getCustomerid();
// 
// 
// 	Date getLastAccessedTime();
// 	
// 
// 	Date getTimeoutTime();
// 
// 	
// }
// 
// Path: acmeair-services/src/main/java/com/acmeair/service/AuthenticationService.java
// public interface AuthenticationService {
//     CustomerSession validateCustomerSession(String sessionId);
// }


import com.acmeair.entities.CustomerSession;
import com.acmeair.service.AuthenticationService;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import java.io.IOException;
import java.util.Arrays;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
		String path = request.getContextPath() + request.getServletPath();
		if (request.getPathInfo() != null) {
			path = path + request.getPathInfo();
		}
		logger.debug("Get the request path {}", path);
		
		
		if (path.endsWith(LOGIN_PATH) || path.endsWith(LOGOUT_PATH) || path.endsWith(LOADDB_PATH) ||
				path.contains(CONFIG_PATH) || path.contains(LOADER_PATH)) {
			// if logging in, logging out, lookup configuration, or loading the database , let the request flow
			return;
		}
		
		Cookie cookies[] = request.getCookies();
		Cookie sessionCookie = null;
		if (cookies != null) {
			for (Cookie c : cookies) {
				if (c.getName().equals(CustomerSession.SESSIONID_COOKIE_NAME)) {
					sessionCookie = c;
				}
				if (sessionCookie!=null)
					break;
			}
			String sessionId = "";
			if (sessionCookie!=null) // We need both cookie to work
				sessionId= sessionCookie.getValue().trim();
			// did this check as the logout currently sets the cookie value to "" instead of aging it out
			// see comment in LogingREST.java
			if (sessionId.equals("")) {
				logger.warn("Session id is empty");
// Path: acmeair-customer-common/src/main/java/com/acmeair/entities/CustomerSession.java
// public interface CustomerSession {
// 
// 	String SESSIONID_COOKIE_NAME = "sessionid";
// 
// 	String getId();
// 
// 
// 	String getCustomerid();
// 
// 
// 	Date getLastAccessedTime();
// 	
// 
// 	Date getTimeoutTime();
// 
// 	
// }
// 
// Path: acmeair-services/src/main/java/com/acmeair/service/AuthenticationService.java
// public interface AuthenticationService {
//     CustomerSession validateCustomerSession(String sessionId);
// }


// Path: acmeair-webapp/src/main/java/com/acmeair/web/RESTCookieSessionFilter.java
import com.acmeair.entities.CustomerSession;
import com.acmeair.service.AuthenticationService;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import java.io.IOException;
import java.util.Arrays;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

		String path = request.getContextPath() + request.getServletPath();
		if (request.getPathInfo() != null) {
			path = path + request.getPathInfo();
		}
		logger.debug("Get the request path {}", path);
		
		
		if (path.endsWith(LOGIN_PATH) || path.endsWith(LOGOUT_PATH) || path.endsWith(LOADDB_PATH) ||
				path.contains(CONFIG_PATH) || path.contains(LOADER_PATH)) {
			// if logging in, logging out, lookup configuration, or loading the database , let the request flow
			return;
		}
		
		Cookie cookies[] = request.getCookies();
		Cookie sessionCookie = null;
		if (cookies != null) {
			for (Cookie c : cookies) {
				if (c.getName().equals(CustomerSession.SESSIONID_COOKIE_NAME)) {
					sessionCookie = c;
				}
				if (sessionCookie!=null)
					break;
			}
			String sessionId = "";
			if (sessionCookie!=null) // We need both cookie to work
				sessionId= sessionCookie.getValue().trim();
			// did this check as the logout currently sets the cookie value to "" instead of aging it out
			// see comment in LogingREST.java
			if (sessionId.equals("")) {
				logger.warn("Session id is empty");
				setFailedRequest(HttpServletResponse.SC_FORBIDDEN);