Index: net/test/android/javatests/src/org/chromium/net/test/DummySpnegoAuthenticator.java |
diff --git a/net/test/android/javatests/src/org/chromium/net/test/DummySpnegoAuthenticator.java b/net/test/android/javatests/src/org/chromium/net/test/DummySpnegoAuthenticator.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..773b3c12b138fffd5f65c636e6b4eb416918ff00 |
--- /dev/null |
+++ b/net/test/android/javatests/src/org/chromium/net/test/DummySpnegoAuthenticator.java |
@@ -0,0 +1,127 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.net.test; |
+ |
+import android.accounts.AbstractAccountAuthenticator; |
+ |
+import android.accounts.Account; |
+import android.accounts.AccountAuthenticatorResponse; |
+import android.accounts.AccountManager; |
+import android.accounts.AuthenticatorException; |
+import android.accounts.NetworkErrorException; |
+import android.accounts.OperationCanceledException; |
+import android.content.Context; |
+import android.os.Bundle; |
+ |
+import org.chromium.base.Log; |
+ |
+import java.io.IOException; |
+ |
+/** |
+ * Dummy Android authenticator, to test SPNEGO/Keberos support on Android. This is |
+ * deliberately minimal, and is not intended as an example of how to write a |
+ * real SPNEGO Authenticator. |
+ */ |
+public class DummySpnegoAuthenticator extends AbstractAccountAuthenticator { |
+ private static final String SPNEGO_FEATURE = "SPNEGO"; |
+ |
+ private static int sAccountNumber = 0; |
+ |
+ private static final String TAG = "cr.net.test"; |
+ /** |
+ * @param context |
+ */ |
+ public DummySpnegoAuthenticator(final Context context) { |
+ super(context); |
+ Log.i(TAG, "Constructor"); |
Bernhard Bauer
2015/06/10 17:11:03
Remove these logging statements?
aberent
2015/06/15 15:52:20
Done.
|
+ final Thread thread = new Thread() { |
+ @Override |
+ public void run() { |
+ AccountManager am = AccountManager.get(context); |
+ String features[] = {"SPNEGO"}; |
+ try { |
+ Bundle accountBundle = |
+ am.addAccount("org.chromium.test.DummySpnegoAuthenticator", "SPNEGO", |
+ features, null, null, null, null).getResult(); |
+ String accountName = accountBundle.getString(AccountManager.KEY_ACCOUNT_NAME); |
+ Log.i(TAG, "Account name = " + accountName); |
+ } catch (OperationCanceledException | AuthenticatorException | IOException e) { |
+ // TODO(aberent): Auto-generated catch block |
Bernhard Bauer
2015/06/10 17:11:03
:)
aberent
2015/06/15 15:52:20
Done.
|
+ e.printStackTrace(); |
+ } |
+ } |
+ }; |
+ thread.start(); |
+ } |
+ |
+ @Override |
+ public Bundle addAccount(AccountAuthenticatorResponse arg0, String accountType, String arg2, |
+ String[] arg3, Bundle arg4) throws NetworkErrorException { |
+ Log.i(TAG, "addAccount"); |
+ Bundle result = new Bundle(); |
+ result.putString(AccountManager.KEY_ACCOUNT_NAME, "SPNEGO Account" + sAccountNumber); |
+ result.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType); |
+ sAccountNumber++; |
+ return result; |
+ } |
+ |
+ @Override |
+ public Bundle confirmCredentials(AccountAuthenticatorResponse arg0, Account arg1, Bundle arg2) |
+ throws NetworkErrorException { |
+ Log.i(TAG, "confirmCredentials"); |
+ Bundle result = new Bundle(); |
+ result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true); |
+ return result; |
+ } |
+ |
+ @Override |
+ public Bundle editProperties(AccountAuthenticatorResponse arg0, String arg1) { |
+ Log.i(TAG, "editProperties"); |
+ return new Bundle(); |
+ } |
+ |
+ @Override |
+ public Bundle getAuthToken(AccountAuthenticatorResponse arg0, Account account, String arg2, |
+ Bundle arg3) throws NetworkErrorException { |
+ Log.i(TAG, "getAuthToken, Account name = " + account.name); |
+ // TODO(aberent): This will need modification as the tests are created. |
+ Bundle result = new Bundle(); |
+ result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); |
+ result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); |
+ result.putString(AccountManager.KEY_AUTHTOKEN, "DummyToken"); |
+ return result; |
+ } |
+ |
+ @Override |
+ public String getAuthTokenLabel(String arg0) { |
+ Log.i(TAG, "getAuthTokenLabel"); |
+ return "Spnego " + arg0; |
+ } |
+ |
+ @Override |
+ public Bundle hasFeatures(AccountAuthenticatorResponse arg0, Account arg1, String[] features) |
+ throws NetworkErrorException { |
+ Log.i(TAG, "hasFeatures"); |
+ Bundle result = new Bundle(); |
+ for (String feature : features) { |
+ if (!feature.equals(SPNEGO_FEATURE)) { |
+ result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false); |
+ return result; |
+ } |
+ } |
+ result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true); |
+ return result; |
+ } |
+ |
+ @Override |
+ public Bundle updateCredentials(AccountAuthenticatorResponse arg0, Account arg1, String arg2, |
+ Bundle arg3) throws NetworkErrorException { |
+ Log.i(TAG, "updateCredentials"); |
+ Bundle result = new Bundle(); |
+ result.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_BAD_REQUEST); |
+ result.putString(AccountManager.KEY_ERROR_MESSAGE, "Can't add new SPNEGO accounts"); |
+ return result; |
+ } |
+} |