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

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

Issue 1414313002: Allow dynamic updating of authentication policies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix IOS compile problem - attempt 3 Created 5 years 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/android/http_auth_negotiate_android.h" 5 #include "net/android/http_auth_negotiate_android.h"
6 6
7 #include "base/android/jni_string.h" 7 #include "base/android/jni_string.h"
8 #include "base/android/scoped_java_ref.h" 8 #include "base/android/scoped_java_ref.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "jni/HttpNegotiateAuthenticator_jni.h" 13 #include "jni/HttpNegotiateAuthenticator_jni.h"
14 #include "net/base/auth.h" 14 #include "net/base/auth.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/http/http_auth_challenge_tokenizer.h" 16 #include "net/http/http_auth_challenge_tokenizer.h"
17 #include "net/http/http_auth_multi_round_parse.h" 17 #include "net/http/http_auth_multi_round_parse.h"
18 #include "net/http/http_auth_preferences.h"
18 19
19 using base::android::AttachCurrentThread; 20 using base::android::AttachCurrentThread;
20 using base::android::ConvertUTF8ToJavaString; 21 using base::android::ConvertUTF8ToJavaString;
21 using base::android::ConvertJavaStringToUTF8; 22 using base::android::ConvertJavaStringToUTF8;
22 using base::android::ScopedJavaLocalRef; 23 using base::android::ScopedJavaLocalRef;
23 24
24 namespace net { 25 namespace net {
25 namespace android { 26 namespace android {
26 27
27 JavaNegotiateResultWrapper::JavaNegotiateResultWrapper( 28 JavaNegotiateResultWrapper::JavaNegotiateResultWrapper(
(...skipping 18 matching lines...) Expand all
46 // simplifies the logic. In practice the result will only ever come back on 47 // simplifies the logic. In practice the result will only ever come back on
47 // the original thread in an obscure error case. 48 // the original thread in an obscure error case.
48 callback_task_runner_->PostTask( 49 callback_task_runner_->PostTask(
49 FROM_HERE, base::Bind(thread_safe_callback_, result, raw_token)); 50 FROM_HERE, base::Bind(thread_safe_callback_, result, raw_token));
50 // We will always get precisely one call to set result for each call to 51 // We will always get precisely one call to set result for each call to
51 // getNextAuthToken, so we can now delete the callback object, and must 52 // getNextAuthToken, so we can now delete the callback object, and must
52 // do so to avoid a memory leak. 53 // do so to avoid a memory leak.
53 delete this; 54 delete this;
54 } 55 }
55 56
56 HttpAuthNegotiateAndroid::HttpAuthNegotiateAndroid( 57 HttpAuthNegotiateAndroid::HttpAuthNegotiateAndroid(HttpAuthPreferences* prefs)
57 const std::string& account_type) 58 : prefs_(prefs),
58 : account_type_(account_type),
59 can_delegate_(false), 59 can_delegate_(false),
60 first_challenge_(true), 60 first_challenge_(true),
61 auth_token_(nullptr), 61 auth_token_(nullptr),
62 weak_factory_(this) { 62 weak_factory_(this) {
63 DCHECK(!account_type.empty());
64 JNIEnv* env = AttachCurrentThread(); 63 JNIEnv* env = AttachCurrentThread();
65 java_authenticator_.Reset(Java_HttpNegotiateAuthenticator_create( 64 java_authenticator_.Reset(Java_HttpNegotiateAuthenticator_create(
66 env, ConvertUTF8ToJavaString(env, account_type).obj())); 65 env,
66 ConvertUTF8ToJavaString(env, prefs->auth_android_negotiate_account_type())
67 .obj()));
67 } 68 }
68 69
69 HttpAuthNegotiateAndroid::~HttpAuthNegotiateAndroid() { 70 HttpAuthNegotiateAndroid::~HttpAuthNegotiateAndroid() {
70 } 71 }
71 72
72 bool HttpAuthNegotiateAndroid::Register(JNIEnv* env) { 73 bool HttpAuthNegotiateAndroid::Register(JNIEnv* env) {
73 return RegisterNativesImpl(env); 74 return RegisterNativesImpl(env);
74 } 75 }
75 76
76 bool HttpAuthNegotiateAndroid::Init() { 77 bool HttpAuthNegotiateAndroid::Init() {
(...skipping 17 matching lines...) Expand all
94 std::string decoded_auth_token; 95 std::string decoded_auth_token;
95 return net::ParseLaterRoundChallenge("negotiate", tok, &server_auth_token_, 96 return net::ParseLaterRoundChallenge("negotiate", tok, &server_auth_token_,
96 &decoded_auth_token); 97 &decoded_auth_token);
97 } 98 }
98 99
99 int HttpAuthNegotiateAndroid::GenerateAuthToken( 100 int HttpAuthNegotiateAndroid::GenerateAuthToken(
100 const AuthCredentials* credentials, 101 const AuthCredentials* credentials,
101 const std::string& spn, 102 const std::string& spn,
102 std::string* auth_token, 103 std::string* auth_token,
103 const net::CompletionCallback& callback) { 104 const net::CompletionCallback& callback) {
105 if (prefs_->auth_android_negotiate_account_type().empty()) {
106 // This can happen if there is a policy change, removing the account type,
107 // in the middle of a negotiation.
108 return ERR_METHOD_NOT_SUPPORTED;
asanka 2015/11/25 19:00:09 ERR_METHOD_NOT_SUPPORTED is used to indicate that
aberent 2015/11/26 15:58:00 Done.
109 }
104 DCHECK(auth_token); 110 DCHECK(auth_token);
105 DCHECK(completion_callback_.is_null()); 111 DCHECK(completion_callback_.is_null());
106 DCHECK(!callback.is_null()); 112 DCHECK(!callback.is_null());
107 113
108 auth_token_ = auth_token; 114 auth_token_ = auth_token;
109 completion_callback_ = callback; 115 completion_callback_ = callback;
110 scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner = 116 scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner =
111 base::ThreadTaskRunnerHandle::Get(); 117 base::ThreadTaskRunnerHandle::Get();
112 base::Callback<void(int, const std::string&)> thread_safe_callback = 118 base::Callback<void(int, const std::string&)> thread_safe_callback =
113 base::Bind(&HttpAuthNegotiateAndroid::SetResultInternal, 119 base::Bind(&HttpAuthNegotiateAndroid::SetResultInternal,
114 weak_factory_.GetWeakPtr()); 120 weak_factory_.GetWeakPtr());
115 JNIEnv* env = AttachCurrentThread(); 121 JNIEnv* env = AttachCurrentThread();
116 ScopedJavaLocalRef<jstring> java_server_auth_token = 122 ScopedJavaLocalRef<jstring> java_server_auth_token =
117 ConvertUTF8ToJavaString(env, server_auth_token_); 123 ConvertUTF8ToJavaString(env, server_auth_token_);
118 ScopedJavaLocalRef<jstring> java_spn = ConvertUTF8ToJavaString(env, spn); 124 ScopedJavaLocalRef<jstring> java_spn = ConvertUTF8ToJavaString(env, spn);
119 ScopedJavaLocalRef<jstring> java_account_type = 125 ScopedJavaLocalRef<jstring> java_account_type = ConvertUTF8ToJavaString(
120 ConvertUTF8ToJavaString(env, account_type_); 126 env, prefs_->auth_android_negotiate_account_type());
121 127
122 // It is intentional that callback_wrapper is not owned or deleted by the 128 // It is intentional that callback_wrapper is not owned or deleted by the
123 // HttpAuthNegotiateAndroid object. The Java code will call the callback 129 // HttpAuthNegotiateAndroid object. The Java code will call the callback
124 // asynchronously on a different thread, and needs an object to call it on. As 130 // asynchronously on a different thread, and needs an object to call it on. As
125 // such, the callback_wrapper must not be deleted until the callback has been 131 // such, the callback_wrapper must not be deleted until the callback has been
126 // called, whatever happens to the HttpAuthNegotiateAndroid object. 132 // called, whatever happens to the HttpAuthNegotiateAndroid object.
127 // 133 //
128 // Unfortunately we have no automated way of managing C++ objects owned by 134 // Unfortunately we have no automated way of managing C++ objects owned by
129 // Java, so the Java code must simply be written to guarantee that the 135 // Java, so the Java code must simply be written to guarantee that the
130 // callback is, in the end, called. 136 // callback is, in the end, called.
(...skipping 14 matching lines...) Expand all
145 const std::string& raw_token) { 151 const std::string& raw_token) {
146 DCHECK(auth_token_); 152 DCHECK(auth_token_);
147 DCHECK(!completion_callback_.is_null()); 153 DCHECK(!completion_callback_.is_null());
148 if (result == OK) 154 if (result == OK)
149 *auth_token_ = "Negotiate " + raw_token; 155 *auth_token_ = "Negotiate " + raw_token;
150 base::ResetAndReturn(&completion_callback_).Run(result); 156 base::ResetAndReturn(&completion_callback_).Run(result);
151 } 157 }
152 158
153 } // namespace android 159 } // namespace android
154 } // namespace net 160 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698