Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1063)

Unified Diff: net/test/android/javatests/src/org/chromium/net/test/DummySpnegoAuthenticator.java

Issue 1128043007: Support Kerberos on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle review comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5cb3858af9fc90f877f0e50146f051869572a9f8
--- /dev/null
+++ b/net/test/android/javatests/src/org/chromium/net/test/DummySpnegoAuthenticator.java
@@ -0,0 +1,118 @@
+// 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 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;
+
+ // This function is needed to satisfy Findbugs
+ private static void incrementAccountNumber() {
+ sAccountNumber++;
+ }
+
+ /**
+ * @param context
+ */
+ public DummySpnegoAuthenticator(final Context context) {
+ super(context);
+ final Thread thread = new Thread() {
+ @Override
+ public void run() {
+ AccountManager am = AccountManager.get(context);
+ String features[] = {"SPNEGO"};
+ try {
+ am.addAccount("org.chromium.test.DummySpnegoAuthenticator", "SPNEGO", features,
+ null, null, null, null).getResult();
+ } catch (OperationCanceledException | AuthenticatorException | IOException e) {
+ // Should never happen. Tests will fail if it does, so safe to ignore.
+ }
+ }
+ };
+ thread.start();
+ }
+
+ @Override
+ public Bundle addAccount(AccountAuthenticatorResponse arg0, String accountType, String arg2,
+ String[] arg3, Bundle arg4) throws NetworkErrorException {
+ Bundle result = new Bundle();
+ result.putString(AccountManager.KEY_ACCOUNT_NAME, "SPNEGO Account" + sAccountNumber);
+ result.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);
+ incrementAccountNumber();
+ 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 if we want to add tests that return
+ // meaningful dummy tokens.
+ 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;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698