Exemple #1
0
  private MappingEntry webAuthentication(HttpContext httpContext, MappingEntry entry) {
    if (webAuthenticate == null) {
      return entry; // 認証なしモード
    }
    String cookieAuth = getCookieAuthAndFilter(httpContext);

    String uri = httpContext.getRequestUri();
    String orgPath = null;
    if (uri.indexOf(webAuthenticateForm) >= 0) { // 認証画面からのリクエスト
      String user;
      String pass;
      try {
        user = httpContext.getParameter("user");
        pass = httpContext.getParameter("pass");
        orgPath = httpContext.getParameter("orgPath");
      } catch (IOException e) { // 認証失敗と判断
        logger.warn("webAuthenticate fail to getParameter.", e);
        return responseWebAuthenticationForm(httpContext, orgPath);
      }
      String inputAuth = encodeBase64(user + ":" + pass);
      if (webAuthenticate.equals(inputAuth)) { // 認証成功
        httpContext.addResponseHeader(
            "Set-Cookie", webAuthenticateCookieKey + "=" + webAuthenticate + "; path=/");
        String location = "http://" + httpContext.getRequestServer() + orgPath;
        httpContext.addResponseHeader(HttpContext.LOCATION_HEADER, location);
        httpContext.registerResponse("302", "success webAuthenticate");
        httpContext.startResponse();
        return null; // 自分でコンテンツを作ったのでentryなし
      }
    }
    if (cookieAuth != null && webAuthenticate.equals(cookieAuth)) {
      return entry; // 認可成功
    }

    // 認可、認証失敗、認証Formをレスポンスする。webAuthenticateFormからのリクエストでない限りorgPathは,null
    return responseWebAuthenticationForm(httpContext, orgPath);
  }
Exemple #2
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なし
 }