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

Side by Side Diff: net/android/java/src/org/chromium/net/HttpNegotiateAuthenticator.java

Issue 1128043007: Support Kerberos on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix more nits from bauerb@ Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « net/android/http_android_auth_negotiate.cc ('k') | net/android/net_jni_registrar.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.net;
6
7 import android.accounts.AccountManager;
8 import android.accounts.AccountManagerCallback;
9 import android.accounts.AccountManagerFuture;
10 import android.accounts.AuthenticatorException;
11 import android.accounts.OperationCanceledException;
12 import android.app.Activity;
13 import android.os.Bundle;
14 import android.os.Handler;
15 import android.os.Parcelable;
16
17 import org.chromium.base.ApplicationStatus;
18 import org.chromium.base.CalledByNative;
19 import org.chromium.base.JNINamespace;
20 import org.chromium.base.VisibleForTesting;
21
22 import java.io.IOException;
23
24 /**
25 * Class to get Auth Tokens for HTTP Negotiate authentication (typically used fo r Kerberos)
26 * An instance of this class is created for each separate negotiation.
27 */
28 @JNINamespace("net::android")
29 public class HttpNegotiateAuthenticator {
30 static final String KEY_INCOMING_AUTH_TOKEN = "incomingAuthToken";
31 static final String KEY_SPNEGO_CONTEXT = "spnegoContext";
32 static final String KEY_CAN_DELEGATE = "canDelegate";
33
34 static final String SPNEGO_FEATURE = "SPNEGO";
35 static final String SPNEGO_TOKEN_TYPE_BASE = "SPNEGO:HOSTBASED:";
36
37 private Parcelable mSpnegoContext = null;
38 private final long mNativeObject;
39 private final String mAccountType;
40
41 private HttpNegotiateAuthenticator(long nativeObject, String accountType) {
42 assert accountType != null && !accountType.isEmpty();
Bernhard Bauer 2015/06/01 14:51:13 You could combine these two checks with android.te
aberent 2015/06/10 15:48:56 Done.
43 mNativeObject = nativeObject;
44 mAccountType = accountType;
45 }
46
47 /**
48 * @param nativeObject The corresponding AndroidAuthNegotiate C++ object
49 * @param accountType The Android account type to use.
50 */
51 @CalledByNative
52 private static HttpNegotiateAuthenticator create(long nativeObject, String a ccountType) {
53 return new HttpNegotiateAuthenticator(nativeObject, accountType);
54 }
55
56 /**
57 *
58 * @param principal The principal (must be host based).
59 * @param authToken The previous auth token, if any.
60 * @return false for immediate failure, true otherwise.
61 */
62 @VisibleForTesting
63 @CalledByNative
64 boolean getNextAuthToken(String principal, String authToken, boolean canDele gate) {
65 assert principal != null;
66 String authTokenType = SPNEGO_TOKEN_TYPE_BASE + principal;
67 Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
68 if (activity == null) return false;
69 AccountManager am = AccountManager.get(activity);
70 String features[] = {SPNEGO_FEATURE};
71
72 Bundle options = new Bundle();
73
74 if (authToken != null) options.putString(KEY_INCOMING_AUTH_TOKEN, authTo ken);
75 if (mSpnegoContext != null) options.putParcelable(KEY_SPNEGO_CONTEXT, mS pnegoContext);
76 options.putBoolean(KEY_CAN_DELEGATE, canDelegate);
77
78 am.getAuthTokenByFeatures(mAccountType, authTokenType, features, activit y, null,
79 options, new AccountManagerCallback<Bundle>() {
80
81 @Override
82 public void run(AccountManagerFuture<Bundle> future) {
83 try {
84 Bundle result = future.getResult();
85 mSpnegoContext = result.getParcelable(KEY_SPNEGO_CON TEXT);
86 nativeSetResult(mNativeObject, true,
87 result.getString(AccountManager.KEY_AUTHTOKE N));
88 } catch (OperationCanceledException | AuthenticatorExcep tion
89 | IOException e) {
90 nativeSetResult(mNativeObject, false, null);
91 }
92 }
93
94 }, new Handler());
95 return true;
96 }
97
98 private native void nativeSetResult(
99 long nativeAndroidAuthNegotiate, boolean result, String authToken);
100 }
OLDNEW
« no previous file with comments | « net/android/http_android_auth_negotiate.cc ('k') | net/android/net_jni_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698