709
yesterday 862
visitor 23,497,405
9

https http 세션 공유 필터 방법(쿠키 복사)

조회 수 40501 추천 수 0 2018.09.20 11:26:50

https http 세션 공유가 안된다....

인터넷에 검색된 필터도 적용하는데 안된다...

왜그런지 모르지만 로그인후 세션 생성하기전 request.getSession().invalidate(); 을 실행해주니 정상적으로 필터에서

새로운 쿠키가 적용 되었다...

아래는 필터


import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HttpsFilter implements Filter {

 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
  
  HttpsRequestWrapper httpsRequest = new HttpsRequestWrapper((HttpServletRequest) request);

  httpsRequest.setResponse((HttpServletResponse) response);
  chain.doFilter(httpsRequest, response);
 }

 public void destroy() {
  // TODO Auto-generated method stub
 }

 public void init(FilterConfig arg0) throws ServletException {
  // TODO Auto-generated method stub
 }
}



import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class HttpsRequestWrapper extends HttpServletRequestWrapper {

 private HttpServletResponse response = null;

 public HttpsRequestWrapper(HttpServletRequest request) {
  super(request);
 }

 public void setResponse(HttpServletResponse response) {
  this.response = response;
 }

 public HttpSession getSession() {
  HttpSession session = super.getSession();
  processSessionCookie(session);
  return session;
 }

 public HttpSession getSession(boolean create) {
  HttpSession session = super.getSession(create);
  processSessionCookie(session);
  return session;
 }

 private void processSessionCookie(HttpSession session) {
  if (null == response || null == session)
   return;

  Object cookieOverWritten = getAttribute("COOKIE_OVERWRITTEN_FLAG");

  if (null == cookieOverWritten && isSecure() && isRequestedSessionIdFromCookie() && session.isNew()) {

   Cookie cookie = new Cookie("JSESSIONID", session.getId());
   cookie.setMaxAge(-1);
   String contextPath = getContextPath();

   if ((contextPath != null) && (contextPath.length() > 0)) {
    cookie.setPath(contextPath);
   } else {
    cookie.setPath("/");
   }
   //cookie.setSecure(false);
   response.addCookie(cookie);

   setAttribute("COOKIE_OVERWRITTEN_FLAG", "true");
  }
 }
}


web.xml -> 최상위

 <filter>
  <filter-name>httpsFilter</filter-name>
  <filter-class>com.project.common.filter.HttpsFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>httpsFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>



2일정도 개삽질...

 

 

'헬로마켓'과 함께하는 스마트한 중고 아이템 거래

https://www.hellomarket.com


1
profile

Maria

May 26, 2022
*.204.224.8

Pandora Rings Jordan 1s Nike Mens Shoes Asics Shoes Nike Canada Adidas Canada Pandora Official Site Goyard Handbags Adidas Outlet Store Pandora Jewelry Yeezy 350 Pandora Outlet Pandora Bracelets Pandora Charms Pandora Jewelry Outlet Pandora Charms Pandora Charms Pandora Store Pandora Charms New Nike Shoes Nike Shoes Outlet Outlet Asics Moncler Coat Men Moncler Outlet Moncler Sale Nike Outlet Store Salvatore Ferragamo Best Basketball Shoes Cheap Moncler Coats Air Jordan 1 Pandora Rings Nike Nike Store Nike Shoes Asics Running Shoes Pandora Outlet Jordan 1 Dior Nike Canada Outlet Pandora Jewelry Pandora Jewelry Nike Shoes Women Nike Sneakers Men Nike Outlet Store Nike Air Max 720 Jordan 1 Low Cheap Womens Adidas Shoes Jordan One Balenciaga Sneakers Balenciaga Nike Shoes For Women Balenciaga Shoes Pandora Outlet Pandora Jewelry Official Site Nike Air Jordan 1 Pandora Jewelry Adidas Yeezy Canada Nike Outlet Online Pandora Jewelry Official Site Nike Shoes Men Air Jordans 1 Pandora Jewelry Official Site Wholesale Jordan Asics Gel-Kayano Cheap Jordans Wholesale Adidas Shoes Pandora Adidas Shoes Women Pandora Charms Sale Clearance Pandora Air Jordan 1 Retro Pandora Charms Jordan 1 Asics Shoes Jordan Retro 1 Pandora Charms Outlet Jordan 1 Lows Nike Store Yeezy Pandora Charms Adidas NMD Women Nike Sneakers Ferragamo Shoes Men Air Jordan 1 High Puma Store Adidas Website Pandora Jewelry Official Site Pandora Jewelry Official Site Nike Shoes Men Balenciaga Pandora Bracelet Charms Nike Sneakers Balenciaga Nike Canada Pandora Charms Moncler Jacket Best Nike Running Shoes Nike Shoes Pandora Charms Moncler Jackets Pandora Jewelry Pandora Charms Pandora Jewellery Pandora Charms Adidas Running Shoes Adidas Sneakers Cheap Jordan Shoes Pandora Outlet Pandora Nike Canada Jordan 1 Retro Ferragamo Pandora Charms Pandora Asics Sneakers For Women Pandora Jewelry Moncler Jackets Pandora Jewelry Pandora Jewelry Ferragamo Belt Balenciaga Triple S Balenciaga Shoes Men Pandora Jewelry Adidas Trainers Ferragamo Belt Adidas Clearance Sale Pandora Jewelry Pandora Bracelets Clearance Shoes Adidas Asics Shoes Nike Shoes Moncler Outlet Yeezy New Nike Shoes Adidas Shoes Men Adidas Shoes Pandora Nike Shoes Adidas Shoes Goyard Bags Moncler Jacket Pandora Jewelry Pandora Outlet Pandora Nike Outlet Jordan Wholesale Distributors Pandora Bracelets
문서 첨부 제한 : 0Byte/ 2.00MB
파일 제한 크기 : 2.00MB (허용 확장자 : *.*)
List of Articles
번호 제목 글쓴이 날짜 조회 수
» https http 세션 공유 필터 방법(쿠키 복사) [1] 제리 2018-09-20 40501
8 @Schedule Spring 스프링 스케쥴 설정법 & CronTab [4] 제리 2016-07-21 65282
7 자바 1.7과 1.8의 차이, 스프링 3.0과 4.0의 차이 [1] 제리 2016-06-03 78041
6 java 날짜 format 제리 2013-10-29 45323
5 Java/JSP Tips (웹에디터) 제리 2013-05-13 42159
4 [jsp] 표현언어(EL) ( JSP커스텀 태그와 JSTL (jsp standard Tag Library) [1] 제리 2012-08-06 81103
3 POI 라이브러리를 이용한 Excel 파일 읽기 [3] 제리 2011-10-20 95948
2 JAVA File 객체 다루기 [1] 제리 2011-10-20 64233
1 jsp 직접접근 막기 [3] 제리 2011-10-19 54362

Program Note 로그인 :)