| 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..5a6b8543e772f4b79f629b79b94f9a50f008f5fb
|
| --- /dev/null
|
| +++ b/net/test/android/javatests/src/org/chromium/net/test/DummySpnegoAuthenticator.java
|
| @@ -0,0 +1,126 @@
|
| +// 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.app.Activity;
|
| +import android.content.Context;
|
| +import android.os.Bundle;
|
| +
|
| +import org.chromium.base.ApplicationStatus;
|
| +import org.chromium.base.CalledByNative;
|
| +
|
| +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 ACCOUNT_TYPE = "org.chromium.test.DummySpnegoAuthenticator";
|
| + private static final String ACCOUNT_NAME = "DummySpnegoAccount";
|
| + private static final String SPNEGO_FEATURE = "SPNEGO";
|
| +
|
| + /**
|
| + * @param context
|
| + */
|
| + public DummySpnegoAuthenticator(Context context) {
|
| + super(context);
|
| + }
|
| +
|
| + @Override
|
| + public Bundle addAccount(AccountAuthenticatorResponse arg0, String accountType, String arg2,
|
| + String[] arg3, Bundle arg4) throws NetworkErrorException {
|
| + 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;
|
| + }
|
| +
|
| + @Override
|
| + public Bundle confirmCredentials(AccountAuthenticatorResponse arg0, Account arg1, Bundle arg2)
|
| + throws NetworkErrorException {
|
| + Bundle result = new Bundle();
|
| + result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
|
| + return result;
|
| + }
|
| +
|
| + @Override
|
| + public Bundle editProperties(AccountAuthenticatorResponse arg0, String arg1) {
|
| + return new Bundle();
|
| + }
|
| +
|
| + @Override
|
| + public Bundle getAuthToken(AccountAuthenticatorResponse arg0, Account account, String arg2,
|
| + Bundle arg3) throws NetworkErrorException {
|
| + // 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) {
|
| + return "Spnego " + arg0;
|
| + }
|
| +
|
| + @Override
|
| + public Bundle hasFeatures(AccountAuthenticatorResponse arg0, Account arg1, String[] features)
|
| + throws NetworkErrorException {
|
| + 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 {
|
| + 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;
|
| + }
|
| +
|
| + @CalledByNative
|
| + private static void ensureTestAccountExists() {
|
| + Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
|
| + AccountManager am = AccountManager.get(activity);
|
| + Account account = new Account(ACCOUNT_NAME, ACCOUNT_TYPE);
|
| + am.addAccountExplicitly(account, null, null);
|
| + }
|
| +
|
| + @SuppressWarnings("deprecation")
|
| + @CalledByNative
|
| + private static void removeTestAccounts() {
|
| + Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
|
| + AccountManager am = AccountManager.get(activity);
|
| + String features[] = {SPNEGO_FEATURE};
|
| + try {
|
| + Account accounts[] =
|
| + am.getAccountsByTypeAndFeatures(ACCOUNT_TYPE, features, null, null).getResult();
|
| + for (Account account : accounts) {
|
| + // Deprecated, but the replacement not available on Android JB.
|
| + am.removeAccount(account, null, null).getResult();
|
| + }
|
| + } catch (OperationCanceledException | AuthenticatorException | IOException e) {
|
| + // Should never happen. This is tidy-up after the tests. Ignore.
|
| + }
|
| + }
|
| +}
|
|
|