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

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: 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 unified diff | Download patch
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
16 import org.chromium.base.ApplicationStatus;
17 import org.chromium.base.CalledByNative;
18 import org.chromium.base.JNINamespace;
19 import org.chromium.base.ThreadUtils;
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) An
26 * instance of this class is created for each separate negotiation.
27 */
28 @JNINamespace("net::android")
29 public class HttpNegotiateAuthenticator {
30 private static final String KEY_INCOMING_AUTH_TOKEN = "incomingAuthToken";
31 private static final String KEY_SPNEGO_CONTEXT = "spnegoContext";
32 private static final String KEY_CAN_DELEGATE = "canDelegate";
33
34 private static final String SPNEGO_FEATURE = "SPNEGO";
35 private static final String SPNEGO_TOKEN_TYPE_BASE = "SPNEGO:HOSTBASED:";
36
37 private String mSpnegoContext = null;
38 private final long mNativeObject;
39 private final String mAccountType;
40 private AccountManagerFuture<Bundle> mFuture;
41
42 private HttpNegotiateAuthenticator(long nativeObject, String accountType) {
43 assert !android.text.TextUtils.isEmpty(accountType);
44 mNativeObject = nativeObject;
45 mAccountType = accountType;
46 }
47
48 /**
49 * @param nativeObject The corresponding HttpAuthNegotiateAndroid C++ object
50 * @param accountType The Android account type to use.
51 */
52 @VisibleForTesting
53 @CalledByNative
54 static HttpNegotiateAuthenticator create(long nativeObject, String accountTy pe) {
55 return new HttpNegotiateAuthenticator(nativeObject, accountType);
56 }
57
58 /**
59 * @param principal The principal (must be host based).
60 * @param authToken The previous auth token, if any.
61 * @return false for immediate failure, true otherwise.
62 */
63 @VisibleForTesting
64 @CalledByNative
65 boolean getNextAuthToken(String principal, String authToken, boolean canDele gate) {
66 assert principal != null;
67 String authTokenType = SPNEGO_TOKEN_TYPE_BASE + principal;
68 Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
69 if (activity == null) return false;
70 AccountManager am = AccountManager.get(activity);
71 String features[] = {SPNEGO_FEATURE};
72
73 Bundle options = new Bundle();
74
75 if (authToken != null) options.putString(KEY_INCOMING_AUTH_TOKEN, authTo ken);
76 if (mSpnegoContext != null) options.putString(KEY_SPNEGO_CONTEXT, mSpneg oContext);
77 options.putBoolean(KEY_CAN_DELEGATE, canDelegate);
78
79 mFuture = am.getAuthTokenByFeatures(mAccountType, authTokenType, feature s, activity, null,
Ryan Sleevi 2015/06/16 01:07:46 Just to make sure: Can exceptions be thrown by any
aberent 2015/06/19 15:06:24 The only things they can, in theory, throw are exc
80 options, new AccountManagerCallback<Bundle>() {
81
82 @Override
83 public void run(AccountManagerFuture<Bundle> future) {
84 try {
85 Bundle result = future.getResult();
86 mSpnegoContext = result.getString(KEY_SPNEGO_CONTEXT );
87 nativeSetResult(mNativeObject, true,
88 result.getString(AccountManager.KEY_AUTHTOKE N));
89 } catch (OperationCanceledException | AuthenticatorExcep tion
90 | IOException e) {
91 nativeSetResult(mNativeObject, false, null);
92 }
93 }
94
95 }, new Handler(ThreadUtils.getUiThreadLooper()));
96 return true;
97 }
98
99 @VisibleForTesting
100 native void nativeSetResult(
101 long nativeHttpAuthNegotiateAndroid, boolean result, String authToke n);
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698