supported single cookie header. fixed error handling.
@@ -32,6 +32,7 @@ | ||
32 | 32 | import org.apache.commons.httpclient.HttpMethod; |
33 | 33 | import org.apache.commons.httpclient.HttpState; |
34 | 34 | import org.apache.commons.httpclient.cookie.CookiePolicy; |
35 | +import org.apache.commons.httpclient.params.HttpMethodParams; | |
35 | 36 | import org.apache.commons.io.FileUtils; |
36 | 37 | import org.apache.commons.io.IOUtils; |
37 | 38 | import org.apache.commons.io.output.DeferredFileOutputStream; |
@@ -66,13 +67,19 @@ | ||
66 | 67 | |
67 | 68 | private int downloadThreshold = 1 * 1024 * 1024; // 1m |
68 | 69 | |
69 | - private HttpClient getHttpClient() { | |
70 | + private HttpClient getHttpClient(HostConfig hostConfig) { | |
70 | 71 | // TODO multi-thread |
71 | 72 | HttpClient httpclient = new HttpClient(); |
73 | + // Connection Timeout | |
72 | 74 | httpclient.getHttpConnectionManager().getParams().setConnectionTimeout( |
73 | - 30000); | |
74 | - httpclient.getParams().setCookiePolicy( | |
75 | - CookiePolicy.BROWSER_COMPATIBILITY); | |
75 | + hostConfig.getConnectionTimeout()); | |
76 | + // Cookie Policy | |
77 | + httpclient.getParams().setCookiePolicy(hostConfig.getCookiePolicy()); | |
78 | + // Single Cookie Header | |
79 | + if (hostConfig.isSingleCookieHeader()) { | |
80 | + httpclient.getParams().setBooleanParameter( | |
81 | + HttpMethodParams.SINGLE_COOKIE_HEADER, true); | |
82 | + } | |
76 | 83 | // httpclient.getParams().setVersion(HttpVersion.HTTP_1_0); // HTTP 1.1 returns a content encoded by gzip. |
77 | 84 | // TODO proxy |
78 | 85 | return httpclient; |
@@ -232,7 +239,7 @@ | ||
232 | 239 | HostConfig hostConfig, String url, String encoding) |
233 | 240 | throws AccessException { |
234 | 241 | |
235 | - HttpClient httpclient = getHttpClient(); | |
242 | + HttpClient httpclient = getHttpClient(hostConfig); | |
236 | 243 | |
237 | 244 | String cookieMapName = SSOProxyConstraints.STORED_COOKIE_LIST |
238 | 245 | + hostConfig.getName(); |
@@ -282,7 +289,7 @@ | ||
282 | 289 | HostConfig hostConfig, AuthConfig authConfig) |
283 | 290 | throws AccessException { |
284 | 291 | |
285 | - HttpClient httpclient = getHttpClient(); | |
292 | + HttpClient httpclient = getHttpClient(hostConfig); | |
286 | 293 | |
287 | 294 | String cookieListName = SSOProxyConstraints.STORED_COOKIE_LIST |
288 | 295 | + hostConfig.getName(); |
@@ -328,7 +335,7 @@ | ||
328 | 335 | HostConfig hostConfig, AuthConfig authConfig) |
329 | 336 | throws AccessException { |
330 | 337 | |
331 | - HttpClient httpclient = getHttpClient(); | |
338 | + HttpClient httpclient = getHttpClient(hostConfig); | |
332 | 339 | |
333 | 340 | String cookieMapName = SSOProxyConstraints.STORED_COOKIE_LIST |
334 | 341 | + hostConfig.getName(); |
@@ -422,16 +429,20 @@ | ||
422 | 429 | props.put(SSOProxyConstraints.PROXY_CONFIG_PARAM, proxyConfig); |
423 | 430 | // props.put(SSOProxyConstraints.REQUEST_PARAM, request); |
424 | 431 | // props.put(SSOProxyConstraints.RESPONSE_PARAM, response); |
432 | + | |
433 | + InputStream inputStream = (InputStream) resultMap | |
434 | + .get(SSOProxyConstraints.RESPONSE_BODY_INPUT_STREAM_PARAM); | |
425 | 435 | try { |
426 | - forwarder.forward(props, (InputStream) resultMap | |
427 | - .get(SSOProxyConstraints.RESPONSE_BODY_INPUT_STREAM_PARAM), | |
428 | - response.getOutputStream()); | |
436 | + if (inputStream != null) { | |
437 | + forwarder.forward(props, inputStream, response | |
438 | + .getOutputStream()); | |
439 | + } | |
429 | 440 | } catch (Exception e) { |
430 | 441 | // } catch (SSOProxyException e) { |
431 | 442 | // } catch (IOException e) { |
432 | 443 | // error |
433 | 444 | throw new AccessException("000019", new Object[] { forwarderName, |
434 | - hostConfigName }); | |
445 | + hostConfigName }, e); | |
435 | 446 | } |
436 | 447 | |
437 | 448 | } |
@@ -184,6 +184,7 @@ | ||
184 | 184 | } catch (Exception e) { |
185 | 185 | // error |
186 | 186 | ErrorHandlingUtil.printLog(e, systemLocale); |
187 | + //TODO error | |
187 | 188 | ErrorHandlingUtil.forwardErrorPage(request, response, e, errorPage); |
188 | 189 | return; |
189 | 190 | } finally { |
@@ -3,6 +3,8 @@ | ||
3 | 3 | import java.util.HashMap; |
4 | 4 | import java.util.Map; |
5 | 5 | |
6 | +import org.apache.commons.httpclient.cookie.CookiePolicy; | |
7 | + | |
6 | 8 | import jp.sf.ssoproxy.config.AuthConfig; |
7 | 9 | import jp.sf.ssoproxy.config.ConfigException; |
8 | 10 | import jp.sf.ssoproxy.config.HostConfig; |
@@ -36,11 +38,20 @@ | ||
36 | 38 | |
37 | 39 | private AuthConfig[] authConfigs; |
38 | 40 | |
41 | + private boolean singleCookieHeader; | |
42 | + | |
43 | + private String cookiePolicy; | |
44 | + | |
45 | + private int connectionTimeout; | |
46 | + | |
39 | 47 | public HostConfigImpl() { |
40 | 48 | scheme = HTTP_SCHEME; |
41 | 49 | encoding = UTF_8; |
42 | 50 | accessManagerName = DEFAULT_ACCESS_MANAGER; |
43 | 51 | forwarderMap = new HashMap<String, String>(); |
52 | + cookiePolicy = CookiePolicy.BROWSER_COMPATIBILITY; | |
53 | + singleCookieHeader = false; | |
54 | + connectionTimeout = 30000; | |
44 | 55 | } |
45 | 56 | |
46 | 57 | public AuthConfig getAuthConfig(String method, String url, |
@@ -137,4 +148,28 @@ | ||
137 | 148 | this.authConfigs = authConfigs; |
138 | 149 | } |
139 | 150 | |
151 | + public boolean isSingleCookieHeader() { | |
152 | + return singleCookieHeader; | |
153 | + } | |
154 | + | |
155 | + public void setSingleCookieHeader(boolean singleCookieHeader) { | |
156 | + this.singleCookieHeader = singleCookieHeader; | |
157 | + } | |
158 | + | |
159 | + public String getCookiePolicy() { | |
160 | + return cookiePolicy; | |
161 | + } | |
162 | + | |
163 | + public void setCookiePolicy(String cookiePolicy) { | |
164 | + this.cookiePolicy = cookiePolicy; | |
165 | + } | |
166 | + | |
167 | + public int getConnectionTimeout() { | |
168 | + return connectionTimeout; | |
169 | + } | |
170 | + | |
171 | + public void setConnectionTimeout(int connectionTimeout) { | |
172 | + this.connectionTimeout = connectionTimeout; | |
173 | + } | |
174 | + | |
140 | 175 | } |
@@ -47,8 +47,22 @@ | ||
47 | 47 | */ |
48 | 48 | public boolean checkLoginPageUrl(String method, String url, |
49 | 49 | Map<String, String[]> params) throws ConfigException { |
50 | - //TODO method and params | |
51 | - if (url != null && url.equals(loginPageUrl)) { | |
50 | + if (url != null && url.equals(loginPageUrl) | |
51 | + && loginPageMethod.equals(method)) { | |
52 | + if (loginPageDataList != null) { | |
53 | + for (Map<String, String> map : loginPageDataList) { | |
54 | + String name = map.get(DATA_NAME); | |
55 | + String value = map.get(DATA_VALUE); | |
56 | + String[] values = params.get(name); | |
57 | + if (value == null || values == null) { | |
58 | + return false; | |
59 | + } else if (values.length == 0) { | |
60 | + return false; | |
61 | + } else if (!value.equals(values[0])) { | |
62 | + return false; | |
63 | + } | |
64 | + } | |
65 | + } | |
52 | 66 | return true; |
53 | 67 | } |
54 | 68 | return false; |
@@ -15,4 +15,10 @@ | ||
15 | 15 | |
16 | 16 | public abstract AuthConfig getAuthConfig(String method, String url, |
17 | 17 | Map<String, String[]> params) throws ConfigException; |
18 | + | |
19 | + public abstract boolean isSingleCookieHeader(); | |
20 | + | |
21 | + public abstract String getCookiePolicy(); | |
22 | + | |
23 | + public abstract int getConnectionTimeout(); | |
18 | 24 | } |
\ No newline at end of file |