gagamel преди 4 години
родител
ревизия
0411bc636b

+ 2 - 2
src/main/java/com/style24/front/support/config/TsfWebMvcConfig.java

@@ -85,8 +85,8 @@ public class TsfWebMvcConfig implements WebMvcConfigurer {
 			.order(2);
 
 		registry.addInterceptor(aflinkInterceptor)
-			.addPathPatterns("/**/form")
-			.excludePathPatterns(excludePathPatterns)
+			.addPathPatterns(new String[] {"/**/form", "/", "/index", "/siginin"})
+//			.excludePathPatterns(excludePathPatterns)
 			.order(3);
 
 		registry.addInterceptor(rememberMeInterceptor)

+ 92 - 30
src/main/java/com/style24/front/support/interceptor/TsfAflinkInterceptor.java

@@ -5,11 +5,13 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.ModelAndView;
 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 
 import com.style24.front.biz.service.TsfCommonService;
+import com.style24.front.support.env.TsfConstants;
 import com.style24.front.support.security.session.TsfSession;
 import com.style24.persistence.domain.InflowHst;
 
@@ -17,11 +19,15 @@ import lombok.extern.slf4j.Slf4j;
 
 import com.gagaframework.web.parameter.GagaMap;
 import com.gagaframework.web.parameter.GagaParameterUtil;
+import com.gagaframework.web.util.GagaCookieUtil;
 import com.gagaframework.web.util.GagaStringUtil;
 
 /**
  * 제휴링크 Interceptor
- *
+ *		if 제휴링크코드가 있고 세션 값이 다를 경우
+ *		    그리고 쿠키가 존재하고 제휴쿠키가 있지만 세션 처리가 안 되었을 경우 세션을 생성한다.
+ *		else
+ *		    제휴링크코드가 없고 제휴링크 세션도 없으면
  * @author gagamel
  * @since 2020. 9. 11
  */
@@ -32,6 +38,9 @@ public class TsfAflinkInterceptor extends HandlerInterceptorAdapter {
 	@Autowired
 	private TsfCommonService commonService;
 
+	@Value("${has-ssl}")
+	private String hasSsl;
+
 	@Override
 	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
 		// Parameter
@@ -39,45 +48,98 @@ public class TsfAflinkInterceptor extends HandlerInterceptorAdapter {
 
 		// 제휴링크코드
 		String afLinkCd = params.getString("afLinkCd");
-
-		if (StringUtils.isNotBlank(afLinkCd)) {
-			// 유효한 웹제휴채널코드 여부 조회
-			String isAvailAfLinkCdYn = commonService.getAvailableAfLinkYn(afLinkCd);
-			log.info("isAvailAfLinkCdYn: {}", isAvailAfLinkCdYn);
-
-			// 유효한 웹제휴채널코드이면
-			if (isAvailAfLinkCdYn.equals("Y")) {
-				if (!afLinkCd.equals(TsfSession.getAttribute("afLinkCd"))) {
-					TsfSession.setAttribute("afLinkCd", afLinkCd);
-				}
-			} else {
-				afLinkCd = "";
-			}
+		boolean makeAfSession = false;
+		log.info("========================1:{}", TsfSession.getAttribute("afLinkCd"));
+
+		// 제휴링크코드가 있고 세션 값과 다를 경우
+		// 또는
+		// 제휴링크코드 쿠키가 존재하고 세션 값이 없을 경우
+		if ((StringUtils.isNotBlank(afLinkCd) && !afLinkCd.equals(TsfSession.getAttribute("afLinkCd"))) ||
+			(StringUtils.isNotBlank(GagaCookieUtil.getCookie(request, TsfConstants.CK_PREFIX + "_afLinkCd")) && StringUtils.isNotBlank(TsfSession.getAttribute("afLinkCd")))) {
+			makeAfSession = true;
+//			log.info("========================2");
+//			// 파라미터로 들어온 값이 있으면
+//			// 1.유효한 웹제휴채널코드 여부 조회
+//			String isAvailAfLinkCdYn = commonService.getAvailableAfLinkYn(afLinkCd);
+//			log.info("isAvailAfLinkCdYn: {}", isAvailAfLinkCdYn);
+//			log.info("========================3");
+//			// 2.유효한 웹제휴채널코드이고 세션 값과 다르면 다시 설정
+//			//   유효한 웹제휴채널코드가 아니면 공백으로
+//			if (isAvailAfLinkCdYn.equals("Y")) {
+//				log.info("========================4");
+//				if (!afLinkCd.equals(TsfSession.getAttribute("afLinkCd"))) {
+//					log.info("========================5");
+//					TsfSession.setAttribute("afLinkCd", afLinkCd);
+//				}
+//			} else {
+//				log.info("========================6");
+//				if (StringUtils.isNotBlank(TsfSession.getAttribute("afLinkCd"))) {
+//					afLinkCd = TsfSession.getAttribute("afLinkCd");
+//				} else {
+//					afLinkCd = "";
+//				}
+//			}
 		} else {
-			if (TsfSession.getAttribute("isApp").equals("true")) { // 앱이면
-				if (TsfSession.getAttribute("osType").equals("A")) {
-					afLinkCd = "AF016"; // AOS앱
-				} else if (TsfSession.getAttribute("osType").equals("I")) {
-					afLinkCd = "AF017"; // IOS앱
-				}
-			} else { // 웹이면
-				if (TsfSession.getFrontGb().equals("P")) {
-					afLinkCd = "AF006"; // PC웹
-				} else if (TsfSession.getFrontGb().equals("M")) {
-					afLinkCd = "AF015"; // 모바일웹
+			log.info("========================7");
+			// 파라미터로 들어온 값이 없을 때
+			// 2.1.세션에 담긴 값이 없으면 앱과 웹에 따라 OS에 따라 설정
+//			if (StringUtils.isBlank(TsfSession.getAttribute("afLinkCd")) &&
+//				StringUtils.isBlank(GagaCookieUtil.getCookie(request, TsfConstants.CK_PREFIX + "_afLinkCd"))) {
+			if (StringUtils.isBlank(TsfSession.getAttribute("afLinkCd")) && StringUtils.isBlank(GagaCookieUtil.getCookie(request, TsfConstants.CK_PREFIX + "_afLinkCd"))) {
+				log.info("========================8");
+				if (TsfSession.getAttribute("isApp").equals("true")) { // 앱이면
+					log.info("========================9");
+					if (TsfSession.getAttribute("osType").equals("A")) {
+						log.info("========================10");
+						afLinkCd = "AF016"; // AOS앱
+					} else if (TsfSession.getAttribute("osType").equals("I")) {
+						log.info("========================11");
+						afLinkCd = "AF017"; // IOS앱
+					}
+					log.info("========================12");
+				} else { // 웹이면
+					log.info("========================13");
+					if (TsfSession.getFrontGb().equals("P")) {
+						log.info("========================14");
+						afLinkCd = "AF006"; // PC웹
+					} else if (TsfSession.getFrontGb().equals("M")) {
+						log.info("========================15");
+						afLinkCd = "AF015"; // 모바일웹
+					}
+					log.info("========================16");
 				}
+				log.info("========================17");
 			}
+			log.info("========================18");
 
 			TsfSession.setAttribute("afLinkCd", afLinkCd);
-		}
 
-		String queryString = GagaStringUtil.convertParameterToQueryString(request.getParameterMap());
-		if (StringUtils.isNotBlank(queryString)) {
-			queryString = "?" + queryString;
+			// SSL Server
+			boolean isSslServer = Boolean.parseBoolean(hasSsl);
+			log.debug("isSslServer: [{}]", isSslServer);
+
+			if (isSslServer) {
+				GagaCookieUtil.setSecureCookie(response, TsfConstants.CK_PREFIX + "_afLinkCd", afLinkCd, -1);
+			} else {
+				GagaCookieUtil.setCookie(response, TsfConstants.CK_PREFIX + "_afLinkCd", afLinkCd, -1);
+			}
 		}
+		log.info("========================19:{}", TsfSession.getAttribute("afLinkCd"));
 
 		try {
 			if (StringUtils.isNotBlank(afLinkCd)) {
+				String queryString = GagaStringUtil.convertParameterToQueryString(request.getParameterMap());
+				if (StringUtils.isNotBlank(queryString)) {
+					queryString = "?" + queryString;
+					if (StringUtils.isNotBlank(TsfSession.getAttribute("afLinkCd"))) {
+						queryString += "&afLinkCd=" + TsfSession.getAttribute("afLinkCd");
+					}
+				} else {
+					if (StringUtils.isNotBlank(TsfSession.getAttribute("afLinkCd"))) {
+						queryString += "?afLinkCd=" + TsfSession.getAttribute("afLinkCd");
+					}
+				}
+
 				InflowHst inflow = new InflowHst();
 				inflow.setAfLinkCd(afLinkCd);
 				inflow.setPageUrl(request.getRequestURL() + queryString);

+ 8 - 51
src/main/java/com/style24/front/support/interceptor/TsfDefaultInterceptor.java

@@ -9,11 +9,12 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.ModelAndView;
 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 
-import com.gagaframework.web.util.GagaStringUtil;
 import com.style24.front.support.security.session.TsfSession;
 
 import lombok.extern.slf4j.Slf4j;
 
+import com.gagaframework.web.util.GagaStringUtil;
+
 /**
  * 모든 Request에 대한 선처리
  * 
@@ -34,27 +35,12 @@ public class TsfDefaultInterceptor extends HandlerInterceptorAdapter {
 
 	@Override
 	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
-		log.info("request.isSecure(): [{}]", request.isSecure());
-		log.info("request.getServerName(): [{}]", request.getServerName());
-		log.info("request.getRequestURI(): [{}]", request.getRequestURI());
-		log.info("request.getRequestURL(): [{}]", request.getRequestURL());
-		log.info("request.getQueryString(): [{}]", request.getQueryString());
-
-//		// 설정된 HTTPS 페이지 확인 (사이트 전체가 SSL 적용이 되어야 함으로 해당 부분 체크로직 주석 처리)
-//		String requestUrl = request.getRequestURL().toString();
-//		boolean bHttpsPage = this.isHttpsPage(isSslServer, requestUrl, request.getRequestURI());
-//		log.info("bHttpsPage: [{}]", bHttpsPage);
-//		if (bHttpsPage) {
-//			requestUrl = requestUrl.replace("http://", "https://");
-//			log.info("requestUrl: [{}]", requestUrl);
-//			response.sendRedirect(requestUrl);
-//			return false;
-//		}
-//
-//		String queryString = GagaStringUtil.convertParameterToQueryString(request.getParameterMap());
-//		if (StringUtils.isNotBlank(queryString))
-//			queryString = "?" + queryString;
-//		log.info("queryString: [{}]", queryString);
+//		log.info("request.isSecure(): [{}]", request.isSecure());
+//		log.info("request.getServerName(): [{}]", request.getServerName());
+//		log.info("request.getRequestURI(): [{}]", request.getRequestURI());
+//		log.info("request.getRequestURL(): [{}]", request.getRequestURL());
+//		log.info("request.getQueryString(): [{}]", request.getQueryString());
+//		log.info("Session's afLinkCd: {}", TsfSession.getAttribute("afLinkCd"));
 
 		// Set APP Info.
 		this.setAppInfo(request);
@@ -91,35 +77,6 @@ public class TsfDefaultInterceptor extends HandlerInterceptorAdapter {
 		// Do nothing
 	}
 
-	/**
-	 * HTTPS로 적용할 페이지인지 체크
-	 * @param requestUrl - Request URL
-	 * @param requestUri - Request URI
-	 * @return true/false
-	 * @author gagamel
-	 * @since 2020. 2. 3
-	 */
-	private boolean isHttpsPage(boolean isSslServer, String requestUrl, String requestUri) {
-		// https 이어야 하는 화면의 URL 목록
-		final String[] httpsUrls = {"/customer", "/mypage", "/order"};
-
-		// 1.설정된 HTTPS URL 값이 없거나
-		// 2.SSL이 적용되지 않은 서버이거나
-		// 3.https로 시작되었거나
-		// 4.Ajax 호출인 경우
-		if (!isSslServer || requestUrl.startsWith("https://"))
-			return false;
-
-		for (String httpsUrl : httpsUrls) {
-			log.info("requestUri: {}, httpsUrl: {}", requestUri, httpsUrl);
-			if (requestUri.startsWith(httpsUrl)) {
-				return true;
-			}
-		}
-
-		return false;
-	}
-
 	/**
 	 * UserAgent 값을 이용한 APP 설정
 	 * 		APP에서 접속 시 다음과 같이 UserAgent 값이 들어옴.

+ 6 - 3
src/main/java/com/style24/front/support/interceptor/TsfReturnUrlInterceptor.java

@@ -9,13 +9,14 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.ModelAndView;
 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 
-import com.gagaframework.web.util.GagaCookieUtil;
-import com.gagaframework.web.util.GagaStringUtil;
 import com.style24.front.support.env.TsfConstants;
 import com.style24.front.support.security.session.TsfSession;
 
 import lombok.extern.slf4j.Slf4j;
 
+import com.gagaframework.web.util.GagaCookieUtil;
+import com.gagaframework.web.util.GagaStringUtil;
+
 /**
  * Return URL Interceptor
  * 
@@ -34,7 +35,9 @@ public class TsfReturnUrlInterceptor extends HandlerInterceptorAdapter {
 		if (StringUtils.isNotBlank(queryString)) {
 			queryString = "?" + queryString;
 		}
-		log.info("queryString: [{}]", queryString);
+//		if (StringUtils.isNotBlank(TsfSession.getAttribute("afLinkCd"))) {
+//			queryString += (queryString.contains("?") ? "&" : "?") + "afLinkCd=" + TsfSession.getAttribute("afLinkCd");
+//		}
 
 		String returnUrl = request.getRequestURL() + queryString;
 		log.info("returnUrl: [{}]", returnUrl);

+ 5 - 1
src/main/java/com/style24/front/support/security/handler/TsfLoginSuccessHandler.java

@@ -128,7 +128,7 @@ public class TsfLoginSuccessHandler implements AuthenticationSuccessHandler {
 
 		// 회원가입, 아이디찾기, 비밀번호찾기, 회원가입완료 페이지에서 로그인 했으면 메인으로 이동
 		// 그 외는 RETURN URL로 이동
-		if (StringUtils.isNotEmpty(returnUrl)) {
+		if (StringUtils.isNotBlank(returnUrl)) {
 			for (String page : pagesToMain) {
 				if (returnUrl.indexOf(page) > -1) {
 					returnUrl = "/";
@@ -162,6 +162,10 @@ public class TsfLoginSuccessHandler implements AuthenticationSuccessHandler {
 			}
 		}
 
+//		if (StringUtils.isNotBlank(TsfSession.getAttribute("afLinkCd"))) {
+//			returnUrl += (returnUrl.contains("?") ? "&" : "?") + "afLinkCd=" + TsfSession.getAttribute("afLinkCd");
+//		}
+
 		if (isSslServer) {
 			// 로그인 성공 쿠키로 저장 (마케팅 스크립트용)
 			GagaCookieUtil.setSecureCookie(response, TsfConstants.CK_PREFIX + "_login_success", "Y", 1 * 60);