Beispiel #1
0
 private MappingEntry proxyAuthentication(HttpContext httpContext, MappingEntry entry) {
   String paHeader = httpContext.getRequestHeader(HttpContext.PROXY_AUTHORIZATION_HEADER);
   httpContext.removeRequestHeader(HttpContext.PROXY_AUTHORIZATION_HEADER);
   if (proxyAuthenticate == null) { // 認証なしモード
     return entry;
   }
   if (paHeader != null) {
     String[] paParts = paHeader.split(" ");
     if (paParts.length >= 2
         && "Basic".equalsIgnoreCase(paParts[0])
         && proxyAuthenticate.equalsIgnoreCase(paParts[1])) {
       return entry; // 認証成功
     }
   }
   // 認証失敗
   httpContext.addResponseHeader("Proxy-Authenticate", "Basic Realm=\"myProxy\"");
   httpContext.registerResponse("407", "myProxy Proxy-Authenticate");
   httpContext.startResponse();
   return null; // 自分でコンテンツを作ったのでentryなし
 }
Beispiel #2
0
  // Cookie: FujitsuWebsite_common_01=k7.fujitsu.co.jp.63941208497096656; NIN=1; RIYOU=4;
  // OUSU=UgxIaMwUtKwIN3hwh8OiYYcrBNVyVpK3HlrKr15VacKsBFa_bDTDO3x40ronDNDJrMuu1v/uYVZ4n5eAg1in7tJJQhicQHsdDZzU3FB0gWDMyVd0cyW7pQ==; POTO=0
  // Set-Cookie:
  // JSESSIONID=54KAU74VEVVUM8AVE7NJKNIIJ08114SFEH6VTFT3IH12CJU17R7RMRDEIKDG20001G000000.Naru001_001
  private String getCookieAuthAndFilter(HttpContext httpContext) {
    String cookieHeader = httpContext.getRequestHeader(HttpContext.COOKIE_HEADER);
    if (cookieHeader == null) {
      return null;
    }
    Matcher matcher;
    synchronized (webAuthenticatePattern) {
      matcher = webAuthenticatePattern.matcher(cookieHeader);
    }
    if (matcher.find() == false) {
      return null;
    }
    String cookieAuth = matcher.group(1);

    // webAuthenticateCookieKeyがあったなら、抜いたものを設定する。
    httpContext.removeRequestHeader(HttpContext.COOKIE_HEADER);
    String updateCookie = matcher.replaceAll("");
    if (!"".equals(updateCookie)) { // webAuthenticateCookieKeyを抜いた結果何か残れば
      httpContext.setRequestHeader(HttpContext.COOKIE_HEADER, updateCookie);
    }
    // "や'で括られている場合は、削除する
    return stripQuote(cookieAuth);
  }