EWS: Avoid /owa form request in direct EWS mode

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2229 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2014-02-03 21:45:37 +00:00
parent e9591b72c9
commit ef80812111
1 changed files with 21 additions and 14 deletions

View File

@ -207,7 +207,7 @@ public abstract class ExchangeSession {
// manually follow redirect
HttpMethod method = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, url);
if (!this.isAuthenticated()) {
if (!this.isAuthenticated(method)) {
if (isBasicAuthentication) {
int status = method.getStatusCode();
@ -531,7 +531,7 @@ public abstract class ExchangeSession {
checkFormLoginQueryString(logonMethod);
// workaround for post logon script redirect
if (!isAuthenticated()) {
if (!isAuthenticated(logonMethod)) {
// try to get new method from script based redirection
logonMethod = buildLogonMethod(httpClient, logonMethod);
@ -548,7 +548,7 @@ public abstract class ExchangeSession {
logonMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, logonMethod);
checkFormLoginQueryString(logonMethod);
// also check cookies
if (!isAuthenticated()) {
if (!isAuthenticated(logonMethod)) {
throwAuthenticationFailed();
}
} else {
@ -686,8 +686,14 @@ public abstract class ExchangeSession {
*
* @return true if session cookies are available
*/
protected boolean isAuthenticated() {
protected boolean isAuthenticated(HttpMethod method) {
boolean authenticated = false;
if (method.getStatusCode() == HttpStatus.SC_OK
&& "/ews/services.wsdl".equalsIgnoreCase(method.getPath())) {
// direct EWS access returned wsdl
authenticated = true;
} else {
// check cookies
for (Cookie cookie : httpClient.getState().getCookies()) {
// Exchange 2003 cookies
if (cookie.getName().startsWith("cadata") || "sessionid".equals(cookie.getName())
@ -700,6 +706,7 @@ public abstract class ExchangeSession {
break;
}
}
}
return authenticated;
}