// WWW-Authenticate: Basic realm="FIND2",Basicはreverseの事を考えると使えない // Authorization: Basic XXXbase64XXX // "Proxy-Authenticate", "Basic Realm=\"myProxy\"",proxyの場合こちらを使う // Proxy-Authorization: Basic XXXbase64XXX // Response Queueに依頼する前にレスポンスを返却したい場合 private void responseDirect(HttpContext httpContext, String statusCode, String text) { httpContext.registerResponse(statusCode, text); httpContext.startResponse(); try { httpContext.responseDirect(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } context.enque(httpContext, Config.QUEUE_CLOSE); }
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なし }
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); }