Commit 01014b7c authored by rsorokin's avatar rsorokin Committed by Commit bot

Chromad: Add GetUserStatus call into AuthPolicyClient

Also s/ActiveDirectoryAccountData/ActiveDirectoryAccountInfo

BUG=662400
TBR=xiyuan@chromium.org

Review-Url: https://codereview.chromium.org/2841103002
Cr-Commit-Position: refs/heads/master@{#467967}
parent db08d35e
...@@ -540,15 +540,15 @@ void GaiaScreenHandler::DoAdAuth( ...@@ -540,15 +540,15 @@ void GaiaScreenHandler::DoAdAuth(
const std::string& username, const std::string& username,
const Key& key, const Key& key,
authpolicy::ErrorType error, authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData& account_data) { const authpolicy::ActiveDirectoryAccountInfo& account_info) {
switch (error) { switch (error) {
case authpolicy::ERROR_NONE: { case authpolicy::ERROR_NONE: {
DCHECK(account_data.has_account_id() && DCHECK(account_info.has_account_id() &&
!account_data.account_id().empty()); !account_info.account_id().empty());
const AccountId account_id(GetAccountId( const AccountId account_id(GetAccountId(
username, account_data.account_id(), AccountType::ACTIVE_DIRECTORY)); username, account_info.account_id(), AccountType::ACTIVE_DIRECTORY));
Delegate()->SetDisplayAndGivenName(account_data.display_name(), Delegate()->SetDisplayAndGivenName(account_info.display_name(),
account_data.given_name()); account_info.given_name());
UserContext user_context(account_id); UserContext user_context(account_id);
user_context.SetKey(key); user_context.SetKey(key);
user_context.SetAuthFlow(UserContext::AUTH_FLOW_ACTIVE_DIRECTORY); user_context.SetAuthFlow(UserContext::AUTH_FLOW_ACTIVE_DIRECTORY);
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
class AccountId; class AccountId;
namespace authpolicy { namespace authpolicy {
class ActiveDirectoryAccountData; class ActiveDirectoryAccountInfo;
} }
namespace chromeos { namespace chromeos {
...@@ -147,7 +147,7 @@ class GaiaScreenHandler : public BaseScreenHandler, ...@@ -147,7 +147,7 @@ class GaiaScreenHandler : public BaseScreenHandler,
void DoAdAuth(const std::string& username, void DoAdAuth(const std::string& username,
const Key& key, const Key& key,
authpolicy::ErrorType error, authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData& account_data); const authpolicy::ActiveDirectoryAccountInfo& account_info);
// Callback for writing password into pipe. // Callback for writing password into pipe.
void OnPasswordPipeReady(const std::string& username, void OnPasswordPipeReady(const std::string& username,
......
...@@ -747,7 +747,7 @@ proto_library("cryptohome_signkey_proto") { ...@@ -747,7 +747,7 @@ proto_library("cryptohome_signkey_proto") {
proto_library("authpolicy_proto") { proto_library("authpolicy_proto") {
sources = [ sources = [
"//third_party/cros_system_api/dbus/authpolicy/active_directory_account_data.proto", "//third_party/cros_system_api/dbus/authpolicy/active_directory_info.proto",
] ]
proto_out_dir = "chromeos/dbus/authpolicy" proto_out_dir = "chromeos/dbus/authpolicy"
......
...@@ -33,6 +33,26 @@ authpolicy::ErrorType GetErrorFromReader(dbus::MessageReader* reader) { ...@@ -33,6 +33,26 @@ authpolicy::ErrorType GetErrorFromReader(dbus::MessageReader* reader) {
return static_cast<authpolicy::ErrorType>(int_error); return static_cast<authpolicy::ErrorType>(int_error);
} }
authpolicy::ErrorType GetErrorAndProto(
dbus::Response* response,
google::protobuf::MessageLite* protobuf) {
if (!response) {
DLOG(ERROR) << "Auth: Failed to call to authpolicy";
return authpolicy::ERROR_DBUS_FAILURE;
}
dbus::MessageReader reader(response);
const authpolicy::ErrorType error(GetErrorFromReader(&reader));
if (error != authpolicy::ERROR_NONE)
return error;
if (!reader.PopArrayOfBytesAsProto(protobuf)) {
DLOG(ERROR) << "Failed to parse protobuf.";
return authpolicy::ERROR_DBUS_FAILURE;
}
return authpolicy::ERROR_NONE;
}
class AuthPolicyClientImpl : public AuthPolicyClient { class AuthPolicyClientImpl : public AuthPolicyClient {
public: public:
AuthPolicyClientImpl() : weak_ptr_factory_(this) {} AuthPolicyClientImpl() : weak_ptr_factory_(this) {}
...@@ -72,6 +92,18 @@ class AuthPolicyClientImpl : public AuthPolicyClient { ...@@ -72,6 +92,18 @@ class AuthPolicyClientImpl : public AuthPolicyClient {
weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback))); weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback)));
} }
void GetUserStatus(const std::string& object_guid,
GetUserStatusCallback callback) override {
dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface,
authpolicy::kAuthPolicyGetUserStatus);
dbus::MessageWriter writer(&method_call);
writer.AppendString(object_guid);
proxy_->CallMethod(
&method_call, kSlowDbusTimeoutMilliseconds,
base::Bind(&AuthPolicyClientImpl::HandleGetUserStatusCallback,
weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback)));
}
void RefreshDevicePolicy(RefreshPolicyCallback callback) override { void RefreshDevicePolicy(RefreshPolicyCallback callback) override {
dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface, dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface,
authpolicy::kAuthPolicyRefreshDevicePolicy); authpolicy::kAuthPolicyRefreshDevicePolicy);
...@@ -127,21 +159,16 @@ class AuthPolicyClientImpl : public AuthPolicyClient { ...@@ -127,21 +159,16 @@ class AuthPolicyClientImpl : public AuthPolicyClient {
} }
void HandleAuthCallback(AuthCallback callback, dbus::Response* response) { void HandleAuthCallback(AuthCallback callback, dbus::Response* response) {
authpolicy::ActiveDirectoryAccountData account_data; authpolicy::ActiveDirectoryAccountInfo account_info;
if (!response) { authpolicy::ErrorType error(GetErrorAndProto(response, &account_info));
DLOG(ERROR) << "Auth: Failed to call to authpolicy"; std::move(callback).Run(error, account_info);
std::move(callback).Run(authpolicy::ERROR_DBUS_FAILURE, account_data);
return;
} }
dbus::MessageReader reader(response);
const authpolicy::ErrorType error(GetErrorFromReader(&reader)); void HandleGetUserStatusCallback(GetUserStatusCallback callback,
if (!reader.PopArrayOfBytesAsProto(&account_data)) { dbus::Response* response) {
DLOG(ERROR) << "Failed to parse protobuf."; authpolicy::ActiveDirectoryUserStatus user_status;
std::move(callback).Run(authpolicy::ErrorType::ERROR_DBUS_FAILURE, authpolicy::ErrorType error(GetErrorAndProto(response, &user_status));
account_data); std::move(callback).Run(error, user_status);
return;
}
std::move(callback).Run(error, account_data);
} }
dbus::Bus* bus_ = nullptr; dbus::Bus* bus_ = nullptr;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "chromeos/chromeos_export.h" #include "chromeos/chromeos_export.h"
#include "chromeos/dbus/authpolicy/active_directory_account_data.pb.h" #include "chromeos/dbus/authpolicy/active_directory_info.pb.h"
#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
...@@ -22,11 +22,12 @@ namespace chromeos { ...@@ -22,11 +22,12 @@ namespace chromeos {
// initializes the DBusThreadManager instance. // initializes the DBusThreadManager instance.
class CHROMEOS_EXPORT AuthPolicyClient : public DBusClient { class CHROMEOS_EXPORT AuthPolicyClient : public DBusClient {
public: public:
// |user_id| is a unique id for the users. Using objectGUID from Active
// Directory server.
using AuthCallback = base::OnceCallback<void( using AuthCallback = base::OnceCallback<void(
authpolicy::ErrorType error, authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData& account_data)>; const authpolicy::ActiveDirectoryAccountInfo& account_info)>;
using GetUserStatusCallback = base::OnceCallback<void(
authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryUserStatus& user_status)>;
using JoinCallback = base::OnceCallback<void(authpolicy::ErrorType error)>; using JoinCallback = base::OnceCallback<void(authpolicy::ErrorType error)>;
using RefreshPolicyCallback = base::OnceCallback<void(bool success)>; using RefreshPolicyCallback = base::OnceCallback<void(bool success)>;
...@@ -59,6 +60,12 @@ class CHROMEOS_EXPORT AuthPolicyClient : public DBusClient { ...@@ -59,6 +60,12 @@ class CHROMEOS_EXPORT AuthPolicyClient : public DBusClient {
int password_fd, int password_fd,
AuthCallback callback) = 0; AuthCallback callback) = 0;
// Calls GetUserStatus. If Active Directory server is online it fetches
// ActiveDirectoryUserStatus for the user specified by |object_guid|.
// |callback| is called after getting (or failing to get) D-Bus response.
virtual void GetUserStatus(const std::string& object_guid,
GetUserStatusCallback callback) = 0;
// Calls RefreshDevicePolicy - handle policy for the device. // Calls RefreshDevicePolicy - handle policy for the device.
// Fetch GPO files from Active directory server, parse it, encode it into // Fetch GPO files from Active directory server, parse it, encode it into
// protobuf and send to SessionManager. Callback is called after that. // protobuf and send to SessionManager. Callback is called after that.
......
...@@ -109,20 +109,28 @@ void FakeAuthPolicyClient::AuthenticateUser( ...@@ -109,20 +109,28 @@ void FakeAuthPolicyClient::AuthenticateUser(
int password_fd, int password_fd,
AuthCallback callback) { AuthCallback callback) {
authpolicy::ErrorType error = authpolicy::ERROR_NONE; authpolicy::ErrorType error = authpolicy::ERROR_NONE;
authpolicy::ActiveDirectoryAccountData account_data; authpolicy::ActiveDirectoryAccountInfo account_info;
if (!started_) { if (!started_) {
LOG(ERROR) << "authpolicyd not started"; LOG(ERROR) << "authpolicyd not started";
error = authpolicy::ERROR_DBUS_FAILURE; error = authpolicy::ERROR_DBUS_FAILURE;
} else { } else {
if (auth_error_ == authpolicy::ERROR_NONE) { if (auth_error_ == authpolicy::ERROR_NONE) {
if (object_guid.empty()) if (object_guid.empty())
account_data.set_account_id(base::MD5String(user_principal_name)); account_info.set_account_id(base::MD5String(user_principal_name));
else else
account_data.set_account_id(object_guid); account_info.set_account_id(object_guid);
} }
error = auth_error_; error = auth_error_;
} }
PostDelayedClosure(base::BindOnce(std::move(callback), error, account_data)); PostDelayedClosure(base::BindOnce(std::move(callback), error, account_info));
}
void FakeAuthPolicyClient::GetUserStatus(const std::string& object_guid,
GetUserStatusCallback callback) {
authpolicy::ActiveDirectoryUserStatus user_status;
user_status.mutable_account_info()->set_account_id(object_guid);
PostDelayedClosure(
base::BindOnce(std::move(callback), authpolicy::ERROR_NONE, user_status));
} }
void FakeAuthPolicyClient::RefreshDevicePolicy(RefreshPolicyCallback callback) { void FakeAuthPolicyClient::RefreshDevicePolicy(RefreshPolicyCallback callback) {
......
...@@ -31,6 +31,8 @@ class CHROMEOS_EXPORT FakeAuthPolicyClient : public AuthPolicyClient { ...@@ -31,6 +31,8 @@ class CHROMEOS_EXPORT FakeAuthPolicyClient : public AuthPolicyClient {
const std::string& object_guid, const std::string& object_guid,
int password_fd, int password_fd,
AuthCallback callback) override; AuthCallback callback) override;
void GetUserStatus(const std::string& object_guid,
GetUserStatusCallback callback) override;
void RefreshDevicePolicy(RefreshPolicyCallback calllback) override; void RefreshDevicePolicy(RefreshPolicyCallback calllback) override;
void RefreshUserPolicy(const AccountId& account_id, void RefreshUserPolicy(const AccountId& account_id,
RefreshPolicyCallback callback) override; RefreshPolicyCallback callback) override;
......
...@@ -110,9 +110,9 @@ TEST_F(FakeAuthPolicyClientTest, AuthenticateUser_ByObjectGUID) { ...@@ -110,9 +110,9 @@ TEST_F(FakeAuthPolicyClientTest, AuthenticateUser_ByObjectGUID) {
kCorrectUserName, kObjectGUID, /* password_fd */ -1, kCorrectUserName, kObjectGUID, /* password_fd */ -1,
base::Bind( base::Bind(
[](authpolicy::ErrorType error, [](authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData& account_data) { const authpolicy::ActiveDirectoryAccountInfo& account_info) {
EXPECT_EQ(authpolicy::ERROR_NONE, error); EXPECT_EQ(authpolicy::ERROR_NONE, error);
EXPECT_EQ(kObjectGUID, account_data.account_id()); EXPECT_EQ(kObjectGUID, account_info.account_id());
})); }));
} }
...@@ -126,7 +126,7 @@ TEST_F(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) { ...@@ -126,7 +126,7 @@ TEST_F(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) {
authpolicy_client()->AuthenticateUser( authpolicy_client()->AuthenticateUser(
kCorrectUserName, std::string() /* object_guid */, /* password_fd */ -1, kCorrectUserName, std::string() /* object_guid */, /* password_fd */ -1,
base::Bind([](authpolicy::ErrorType error, base::Bind([](authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData&) { const authpolicy::ActiveDirectoryAccountInfo&) {
EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error); EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error);
})); }));
authpolicy_client()->RefreshDevicePolicy( authpolicy_client()->RefreshDevicePolicy(
......
...@@ -32,7 +32,7 @@ base::ScopedFD GetDataReadPipe(const std::string& data) { ...@@ -32,7 +32,7 @@ base::ScopedFD GetDataReadPipe(const std::string& data) {
void AuthCallbackDoNothing( void AuthCallbackDoNothing(
authpolicy::ErrorType /* error */, authpolicy::ErrorType /* error */,
const authpolicy::ActiveDirectoryAccountData& /* account_data */) { const authpolicy::ActiveDirectoryAccountInfo& /* account_info */) {
// Do nothing. // Do nothing.
} }
...@@ -85,8 +85,8 @@ void AuthPolicyLoginHelper::OnJoinCallback(JoinCallback callback, ...@@ -85,8 +85,8 @@ void AuthPolicyLoginHelper::OnJoinCallback(JoinCallback callback,
void AuthPolicyLoginHelper::OnAuthCallback( void AuthPolicyLoginHelper::OnAuthCallback(
AuthCallback callback, AuthCallback callback,
authpolicy::ErrorType error, authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData& account_data) { const authpolicy::ActiveDirectoryAccountInfo& account_info) {
std::move(callback).Run(error, account_data); std::move(callback).Run(error, account_info);
} }
AuthPolicyLoginHelper::~AuthPolicyLoginHelper() {} AuthPolicyLoginHelper::~AuthPolicyLoginHelper() {}
......
...@@ -56,7 +56,7 @@ class CHROMEOS_EXPORT AuthPolicyLoginHelper { ...@@ -56,7 +56,7 @@ class CHROMEOS_EXPORT AuthPolicyLoginHelper {
void OnAuthCallback( void OnAuthCallback(
AuthCallback callback, AuthCallback callback,
authpolicy::ErrorType error, authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData& account_data); const authpolicy::ActiveDirectoryAccountInfo& account_info);
base::WeakPtrFactory<AuthPolicyLoginHelper> weak_factory_; base::WeakPtrFactory<AuthPolicyLoginHelper> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AuthPolicyLoginHelper); DISALLOW_COPY_AND_ASSIGN(AuthPolicyLoginHelper);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment