Ejemplo n.º 1
0
 public long getInjectLength() {
   if (injectContext != null) {
     InjectionHelper helper = config.getInjectionHelper();
     return helper.getInjectContentsLength(injectContext);
   }
   return 0;
 }
Ejemplo n.º 2
0
  public void onResponseHeader(HeaderParser responseHeader) {
    InjectionHelper helper = config.getInjectionHelper();

    MappingResult mapping = proxyHandler.getRequestMapping();
    HeaderParser requestHeader = proxyHandler.getRequestHeader();
    String WebAuthReplaceMark = requestHeader.getHeader(REPLACE_MARK_HEADER);
    String resolveUrl = mapping.getResolveUrl();
    if (WebAuthReplaceMark == null) {
      portalSession.endBasicProcess(resolveUrl);
    }
    String statusCode = responseHeader.getStatusCode();
    if ("401".equals(statusCode) /*&&injectContext==null*/) {
      mapping.getResolveDomain();
      String authentication = responseHeader.getHeader(HeaderParser.WWW_AUTHENTICATE_HEADER);
      if (authentication == null) {
        return;
      }
      Matcher matcher;
      synchronized (authenticationPattern) {
        matcher = authenticationPattern.matcher(authentication);
      }
      if (!matcher.find()) {
        return; // Digestはここでチェックあうと
      }
      String realm = matcher.group(1);

      // 自分の持っている代理ログイン情報で、domain,realmに合致するものはないか?
      String resolveDomain = mapping.getResolveDomain();
      CommissionAuth basicCommissionAuth = portalSession.getBasicAuth(resolveDomain, realm);
      if (WebAuthReplaceMark == null
          && !portalSession.startBasicProcess(resolveUrl, basicCommissionAuth)) {
        return;
      }
      if (basicCommissionAuth == null || basicCommissionAuth.isEnabled()) {
        String authrization = requestHeader.getHeader(HeaderParser.WWW_AUTHORIZATION_HEADER);
        if (WebAuthReplaceMark == null) { // ブラウザから直接出されたリクエスト
          responseHeader.setStatusCode("200");
          proxyHandler.removeResponseHeader(HeaderParser.WWW_AUTHENTICATE_HEADER);
          portalSession.putRealm(resolveUrl, realm);
          proxyHandler.setReplace(true);
          injectContext = helper.getReplaceContext("WebAuthReplace.html");
          proxyHandler.addResponseHeader(
              HeaderParser.CONTENT_TYPE_HEADER, "text/html; charset=utf-8");
          proxyHandler.addResponseHeader("Pragma", "no-cache");
          proxyHandler.addResponseHeader("Cache-Control", "no-cache");
          proxyHandler.addResponseHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
        } else if (authrization != null) { // ajaxからuser/passをつけているのに401が返却された=>認証情報が無効
          responseHeader.setStatusCode("200");
          proxyHandler.removeResponseHeader(HeaderParser.WWW_AUTHENTICATE_HEADER);
          proxyHandler.addResponseHeader("WebAuthRealm", realm);
          proxyHandler.setReplace(true);
          injectContext = helper.getReplaceContext("WebAuthFail.html");
          proxyHandler.addResponseHeader(HeaderParser.CONTENT_TYPE_HEADER, "text/plain");
          proxyHandler.addResponseHeader("Pragma", "no-cache");
          proxyHandler.addResponseHeader("Cache-Control", "no-cache");
          proxyHandler.addResponseHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
        }
      }
    } else if ("200".equals(statusCode) || "404".equals(statusCode)) {
      String contentType = responseHeader.getContentType();
      if (contentType != null && contentType.startsWith("text/html")) {
        injectContext = helper.getInsertContext("PortalInject.txt");
      }
    }
  }
Ejemplo n.º 3
0
 public ByteBuffer[] onResponseBody(ByteBuffer[] body) {
   InjectionHelper helper = config.getInjectionHelper();
   return helper.inject(injectContext, body);
 }