From bd00eeb641dcbd5bc3cc359f9553c2980213c5a3 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Thu, 26 Sep 2019 14:19:52 +0200 Subject: [PATCH] Allow broader check on CheckAuth Signed-off-by: tobiasKaminsky --- .../DetectAuthenticationMethodOperation.java | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java b/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java index b1e406f0a8e8..9e43670b9c83 100644 --- a/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java +++ b/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java @@ -1,5 +1,5 @@ /** - * ownCloud Android client application + * ownCloud Android client application * * @author David A. Velasco * Copyright (C) 2015 ownCloud Inc. @@ -46,78 +46,78 @@ * {@link RemoteOperationResult#getData()} a value of {@link AuthenticationMethod}. */ public class DetectAuthenticationMethodOperation extends RemoteOperation { - + private static final String TAG = DetectAuthenticationMethodOperation.class.getSimpleName(); - + public enum AuthenticationMethod { UNKNOWN, NONE, - BASIC_HTTP_AUTH, + BASIC_HTTP_AUTH, SAML_WEB_SSO, BEARER_TOKEN } - + private Context mContext; - + /** * Constructor - * - * @param context Android context of the caller. + * + * @param context Android context of the caller. */ public DetectAuthenticationMethodOperation(Context context) { mContext = context; } - + /** * Performs the operation. - * + * * Triggers a check of existence on the root folder of the server, granting * that the request is not authenticated. - * + * * Analyzes the result of check to find out what authentication method, if * any, is requested by the server. */ - @Override - protected RemoteOperationResult run(OwnCloudClient client) { + @Override + protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; AuthenticationMethod authMethod = AuthenticationMethod.UNKNOWN; - + RemoteOperation operation = new ExistenceCheckRemoteOperation("", mContext, false); client.clearCredentials(); client.setFollowRedirects(false); - + // try to access the root folder, following redirections but not SAML SSO redirections result = operation.execute(client); - String redirectedLocation = result.getRedirectedLocation(); + String redirectedLocation = result.getRedirectedLocation(); while (!TextUtils.isEmpty(redirectedLocation) && !result.isIdPRedirection()) { client.setBaseUri(Uri.parse(result.getRedirectedLocation())); result = operation.execute(client); redirectedLocation = result.getRedirectedLocation(); - } + } - // analyze response - if (result.getHttpCode() == HttpStatus.SC_UNAUTHORIZED) { + // analyze response + if (result.getHttpCode() == HttpStatus.SC_UNAUTHORIZED || result.getHttpCode() == HttpStatus.SC_FORBIDDEN) { ArrayList authHeaders = result.getAuthenticateHeaders(); for (String header : authHeaders) { // currently we only support basic auth - if (header.toLowerCase(Locale.ROOT).startsWith("basic")) { + if (header.toLowerCase(Locale.ROOT).contains("basic")) { authMethod = AuthenticationMethod.BASIC_HTTP_AUTH; break; } } // else - fall back to UNKNOWN - + } else if (result.isSuccess()) { authMethod = AuthenticationMethod.NONE; - + } else if (result.isIdPRedirection()) { authMethod = AuthenticationMethod.SAML_WEB_SSO; } // else - fall back to UNKNOWN Log_OC.d(TAG, "Authentication method found: " + authenticationMethodToString(authMethod)); - + if (authMethod != AuthenticationMethod.UNKNOWN) { result = new RemoteOperationResult(true, result.getHttpCode(), result.getHttpPhrase(), null); } @@ -125,22 +125,22 @@ protected RemoteOperationResult run(OwnCloudClient client) { data.add(authMethod); result.setData(data); return result; // same result instance, so that other errors - // can be handled by the caller transparently - } - - private String authenticationMethodToString(AuthenticationMethod value) { - switch (value){ - case NONE: - return "NONE"; - case BASIC_HTTP_AUTH: - return "BASIC_HTTP_AUTH"; - case BEARER_TOKEN: - return "BEARER_TOKEN"; - case SAML_WEB_SSO: - return "SAML_WEB_SSO"; - default: - return "UNKNOWN"; - } + // can be handled by the caller transparently + } + + private String authenticationMethodToString(AuthenticationMethod value) { + switch (value) { + case NONE: + return "NONE"; + case BASIC_HTTP_AUTH: + return "BASIC_HTTP_AUTH"; + case BEARER_TOKEN: + return "BEARER_TOKEN"; + case SAML_WEB_SSO: + return "SAML_WEB_SSO"; + default: + return "UNKNOWN"; + } } }