Bläddra i källkod

Merge pull request #2689 from nextcloud/fixAuth

Auth: Do not use context on static
Andy Scherzinger 6 år sedan
förälder
incheckning
84776053ff

+ 1 - 1
build.gradle

@@ -14,7 +14,7 @@ buildscript {
         google()
         google()
     }
     }
     dependencies {
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.1.2'
+        classpath 'com.android.tools.build:gradle:3.1.3'
         classpath 'com.google.gms:google-services:3.0.0'
         classpath 'com.google.gms:google-services:3.0.0'
         classpath 'org.codehaus.groovy:groovy-all:2.4.12' 
         classpath 'org.codehaus.groovy:groovy-all:2.4.12' 
         classpath('com.dicedmelon.gradle:jacoco-android:0.1.2') { 
         classpath('com.dicedmelon.gradle:jacoco-android:0.1.2') { 

+ 17 - 14
src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -242,10 +242,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     /// Identifier of operation in progress which result shouldn't be lost 
     /// Identifier of operation in progress which result shouldn't be lost 
     private long mWaitingForOpId = Long.MAX_VALUE;
     private long mWaitingForOpId = Long.MAX_VALUE;
 
 
-    private final String BASIC_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType(this));
-    private final String OAUTH_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType(this));
-    private final String SAML_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(
-            MainApp.getAccountType(this));
+    private String basicTokenType;
+    private String oauthTokenType;
+    private String samlTokenType;
 
 
     private boolean webViewLoginMethod;
     private boolean webViewLoginMethod;
     private String webViewUser;
     private String webViewUser;
@@ -264,6 +263,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         //Log_OC.e(TAG,  "onCreate init");
         //Log_OC.e(TAG,  "onCreate init");
         super.onCreate(savedInstanceState);
         super.onCreate(savedInstanceState);
 
 
+        basicTokenType = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType(this));
+        oauthTokenType = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType(this));
+        samlTokenType = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType(this));
+
         // delete cookies for webView
         // delete cookies for webView
         deleteCookies();
         deleteCookies();
 
 
@@ -561,11 +564,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
 
     private String chooseAuthTokenType(boolean oauth, boolean saml) {
     private String chooseAuthTokenType(boolean oauth, boolean saml) {
         if (saml) {
         if (saml) {
-            return SAML_TOKEN_TYPE;
+            return samlTokenType;
         } else if (oauth) {
         } else if (oauth) {
-            return OAUTH_TOKEN_TYPE;
+            return oauthTokenType;
         } else {
         } else {
-            return BASIC_TOKEN_TYPE;
+            return basicTokenType;
         }
         }
     }
     }
 
 
@@ -911,10 +914,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             String password = savedInstanceState.getString(KEY_PASSWORD);
             String password = savedInstanceState.getString(KEY_PASSWORD);
 
 
             OwnCloudCredentials credentials = null;
             OwnCloudCredentials credentials = null;
-            if (BASIC_TOKEN_TYPE.equals(mAuthTokenType)) {
+            if (basicTokenType.equals(mAuthTokenType)) {
                 credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password);
                 credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password);
 
 
-            } else if (OAUTH_TOKEN_TYPE.equals(mAuthTokenType)) {
+            } else if (oauthTokenType.equals(mAuthTokenType)) {
                 credentials = OwnCloudCredentialsFactory.newBearerCredentials(mAuthToken);
                 credentials = OwnCloudCredentialsFactory.newBearerCredentials(mAuthToken);
 
 
             }
             }
@@ -1475,11 +1478,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
 
 
 
     private boolean authSupported(AuthenticationMethod authMethod) {
     private boolean authSupported(AuthenticationMethod authMethod) {
-        return ((BASIC_TOKEN_TYPE.equals(mAuthTokenType) &&
+        return ((basicTokenType.equals(mAuthTokenType) &&
                 AuthenticationMethod.BASIC_HTTP_AUTH.equals(authMethod)) ||
                 AuthenticationMethod.BASIC_HTTP_AUTH.equals(authMethod)) ||
-                (OAUTH_TOKEN_TYPE.equals(mAuthTokenType) &&
+                (oauthTokenType.equals(mAuthTokenType) &&
                         AuthenticationMethod.BEARER_TOKEN.equals(authMethod)) ||
                         AuthenticationMethod.BEARER_TOKEN.equals(authMethod)) ||
-                (SAML_TOKEN_TYPE.equals(mAuthTokenType) &&
+                (samlTokenType.equals(mAuthTokenType) &&
                         AuthenticationMethod.SAML_WEB_SSO.equals(authMethod))
                         AuthenticationMethod.SAML_WEB_SSO.equals(authMethod))
         );
         );
     }
     }
@@ -2020,9 +2023,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     public void onCheckClick(View view) {
     public void onCheckClick(View view) {
         CheckBox oAuth2Check = (CheckBox) view;
         CheckBox oAuth2Check = (CheckBox) view;
         if (oAuth2Check.isChecked()) {
         if (oAuth2Check.isChecked()) {
-            mAuthTokenType = OAUTH_TOKEN_TYPE;
+            mAuthTokenType = oauthTokenType;
         } else {
         } else {
-            mAuthTokenType = BASIC_TOKEN_TYPE;
+            mAuthTokenType = basicTokenType;
         }
         }
         updateAuthenticationPreFragmentVisibility();
         updateAuthenticationPreFragmentVisibility();
     }
     }