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

Side by Side Diff: net/android/http_android_auth_negotiate.cc

Issue 1128043007: Support Kerberos on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 #include "net/android/http_android_auth_negotiate.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "base/base64.h"
11 #include "base/strings/string_util.h"
12
13 #include "jni/HttpNegotiateAuthenticator_jni.h"
Bernhard Bauer 2015/05/15 15:06:16 The generated JNI include usually goes at the end.
aberent 2015/05/18 13:45:27 The pre-submit checks complain if I move it.
Bernhard Bauer 2015/05/18 15:11:53 Hm, in that case let's remove the empty lines. Eit
aberent 2015/05/18 17:07:30 Done.
14
15 #include "net/base/net_errors.h"
16 #include "net/http/http_auth.h"
17 #include "net/http/http_auth_challenge_tokenizer.h"
18
19 using base::android::AttachCurrentThread;
20 using base::android::ConvertUTF8ToJavaString;
21 using base::android::ConvertJavaStringToUTF8;
22 using base::android::ScopedJavaLocalRef;
23
24 namespace net {
25 namespace android {
26
27 AndroidAuthNegotiate::AndroidAuthNegotiate(const std::string& account_type,
28 const std::string& scheme)
29 : account_type_(account_type),
Bernhard Bauer 2015/05/15 15:06:16 Would it make sense to pass the account type to th
aberent 2015/05/18 13:45:27 Done.
30 scheme_(scheme),
31 can_delegate_(false),
32 first_challenge_(true),
33 server_auth_token_(""),
Bernhard Bauer 2015/05/15 15:06:16 You don't need an explicit initializer.
aberent 2015/05/18 13:45:27 Done.
34 java_authenticator_(Java_HttpNegotiateAuthenticator_create(
35 AttachCurrentThread(),
36 reinterpret_cast<intptr_t>(this))) {
37 }
38
39 AndroidAuthNegotiate::~AndroidAuthNegotiate() {
40 }
41
42 bool AndroidAuthNegotiate::Init() {
43 return !account_type_.empty();
44 }
45
46 bool AndroidAuthNegotiate::NeedsIdentity() const {
47 return false;
48 }
49
50 bool AndroidAuthNegotiate::AllowsExplicitCredentials() const {
51 return false;
52 }
53
54 HttpAuth::AuthorizationResult AndroidAuthNegotiate::ParseChallenge(
55 net::HttpAuthChallengeTokenizer* tok) {
56 // Verify the challenge's auth-scheme.
57 if (!LowerCaseEqualsASCII(tok->scheme(),
58 base::StringToLowerASCII(scheme_).c_str()))
59 return HttpAuth::AUTHORIZATION_RESULT_INVALID;
60
61 std::string encoded_auth_token = tok->base64_param();
62 if (encoded_auth_token.empty()) {
63 if (!first_challenge_) {
64 return HttpAuth::AUTHORIZATION_RESULT_REJECT;
Bernhard Bauer 2015/05/15 15:06:16 Nit: No braces.
aberent 2015/05/18 13:45:27 Done.
65 }
66 return HttpAuth::AUTHORIZATION_RESULT_ACCEPT;
67 } else {
68 // If a context has not already been established, additional tokens should
69 // not be present in the auth challenge.
70 if (first_challenge_)
71 return HttpAuth::AUTHORIZATION_RESULT_INVALID;
72 }
73 // Make sure the additional token is base64 encoded.
74 std::string decoded_auth_token;
75 bool base64_rv = base::Base64Decode(encoded_auth_token, &decoded_auth_token);
76 if (!base64_rv)
77 return HttpAuth::AUTHORIZATION_RESULT_INVALID;
78 server_auth_token_ = encoded_auth_token;
79 return HttpAuth::AUTHORIZATION_RESULT_ACCEPT;
80 }
81
82 int AndroidAuthNegotiate::GenerateAuthToken(
83 const AuthCredentials* credentials,
84 const std::string& spn,
85 std::string* auth_token,
86 const net::CompletionCallback& callback) {
87 DCHECK(auth_token);
88 auth_token_ = auth_token;
89 completion_callback_ = callback;
90 JNIEnv* env = AttachCurrentThread();
91 ScopedJavaLocalRef<jstring> java_server_auth_token =
92 ConvertUTF8ToJavaString(env, server_auth_token_);
93 ScopedJavaLocalRef<jstring> java_spn = ConvertUTF8ToJavaString(env, spn);
94 ScopedJavaLocalRef<jstring> java_account_type =
95 ConvertUTF8ToJavaString(env, account_type_);
96 bool result = Java_HttpNegotiateAuthenticator_getNextAuthToken(
97 env, java_authenticator_.obj(), java_account_type.obj(), java_spn.obj(),
98 java_server_auth_token.obj());
99 return result ? ERR_IO_PENDING : ERR_INVALID_AUTH_CREDENTIALS;
100 }
101
102 void AndroidAuthNegotiate::Delegate() {
103 can_delegate_ = true;
104 }
105
106 void AndroidAuthNegotiate::SetResult(JNIEnv* env,
107 jobject obj,
108 bool result,
109 jstring token) {
110 if (result)
111 *auth_token_ = ConvertJavaStringToUTF8(env, token);
112 completion_callback_.Run(result);
113 }
114
115 bool RegisterHttpNegotiateAuthenticator(JNIEnv* env) {
116 return RegisterNativesImpl(env);
117 }
118
119 } // namespace android
120 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698