public void onRequestHeader(HeaderParser requestHeader) { /* portal機能の場合path情報にportal機能用の情報が着いている場合がある。 * この情報は削除してproxy対象サーバにリクエスト */ MappingResult mapping = proxyHandler.getRequestMapping(); String path = mapping.getResolvePath(); Matcher matcher = null; synchronized (portalPathInfoPattern) { matcher = portalPathInfoPattern.matcher(path); } StringBuffer sb = null; String portalPathInfo = null; if (matcher.find()) { sb = new StringBuffer(); matcher.appendReplacement(sb, ""); portalPathInfo = matcher.group(1); matcher.appendTail(sb); path = sb.toString(); mapping.setResolvePath(path); requestHeader.setRequestUri(mapping.getResolvePath()); proxyHandler.setRequestAttribute(PORTAL_PATHINFO_KEY, portalPathInfo); } /* * proxyでAuthrizationヘッダを付加する作戦の場合 String basicAuthHeader = getBasicAuthHeader(mapping.isResolvedHttps(),mapping.getResolveServer()); if (basicAuthHeader != null) { requestHeader.addHeader(HeaderParser.WWW_AUTHRIZATION_HEADER, basicAuthHeader); proxyHandler.setRequestAttribute(HeaderParser.WWW_AUTHRIZATION_HEADER, basicAuthHeader); } */ }
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"); } } }