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

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: Changes for bauerb@'s comments, plus some other minor fixes. 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
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 String mAccountType;
Bernhard Bauer 2015/05/18 15:11:53 Make this final?
aberent 2015/05/18 17:07:30 Done.
40
41 private HttpNegotiateAuthenticator(long nativeObject, String accountType) {
42 mNativeObject = nativeObject;
43 mAccountType = accountType;
44 }
45
46 /**
47 * object creator
Bernhard Bauer 2015/05/18 15:11:53 Nit: Capitalize and add punctuation (or remove it)
aberent 2015/05/18 17:07:30 Removed.
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 mAccountType != null;
Bernhard Bauer 2015/05/18 15:11:53 Assert this in the constructor?
aberent 2015/05/18 17:07:30 Yes, although actually I should be testing for emp
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.putParcelable(KEY_SPNEGO_CONTEXT, mS pnegoContext);
77 options.putBoolean(KEY_CAN_DELEGATE, canDelegate);
78
79 am.getAuthTokenByFeatures(mAccountType, authTokenType, features, activit y, null,
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.getParcelable(KEY_SPNEGO_CON TEXT);
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());
96 return true;
97 }
98
99 private native void nativeSetResult(
100 long nativeAndroidAuthNegotiate, boolean result, String authToken);
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698