Commit 2287eae4 authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

Chrome OS: Add management notice

for the SAML password change dialog.

Bug: 930109
Change-Id: I4f2fb367d1b3d47b3e59f293dddc434169f02d67
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1634834Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarA Olsen <olsen@chromium.org>
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664284}
parent 1bda6b01
...@@ -937,6 +937,9 @@ ...@@ -937,6 +937,9 @@
<message name="IDS_LOGIN_SAML_NOTICE" desc="Text message displayed above SAML portal to early indicate that the user is being redirected to another sign-in provider. This is the version of the string used in the GAIA flow."> <message name="IDS_LOGIN_SAML_NOTICE" desc="Text message displayed above SAML portal to early indicate that the user is being redirected to another sign-in provider. This is the version of the string used in the GAIA flow.">
This sign-in service is hosted by <ph name="SAML_DOMAIN">$1<ex>saml.com</ex></ph> This sign-in service is hosted by <ph name="SAML_DOMAIN">$1<ex>saml.com</ex></ph>
</message> </message>
<message name="IDS_LOGIN_SAML_PASSWORD_CHANGE_NOTICE" desc="Text message displayed in the system dialog title. The dialog shows a web-page where the user can change their SAML password while staying in the session">
This authentication service is hosted by <ph name="SAML_DOMAIN">$1<ex>saml.com</ex></ph>
</message>
<message name="IDS_LOGIN_SAML_NOTICE_WITH_VIDEO" desc="Text message displayed above SAML portal to early indicate that the user is being redirected to another sign-in provider which has requested video media access."> <message name="IDS_LOGIN_SAML_NOTICE_WITH_VIDEO" desc="Text message displayed above SAML portal to early indicate that the user is being redirected to another sign-in provider which has requested video media access.">
This sign-in service, hosted by <ph name="SAML_DOMAIN">$1<ex>saml.com</ex></ph>, is accessing your camera. This sign-in service, hosted by <ph name="SAML_DOMAIN">$1<ex>saml.com</ex></ph>, is accessing your camera.
</message> </message>
......
...@@ -78,15 +78,6 @@ const base::NoDestructor<RichNotificationData> kRichNotificationData; ...@@ -78,15 +78,6 @@ const base::NoDestructor<RichNotificationData> kRichNotificationData;
const base::NoDestructor<base::string16> kLineSeparator( const base::NoDestructor<base::string16> kLineSeparator(
base::string16(1, '\n')); base::string16(1, '\n'));
// Callback called when notification is clicked - opens password-change page.
void OnNotificationClicked() {
PasswordChangeDialog::Show();
}
const base::NoDestructor<scoped_refptr<HandleNotificationClickDelegate>>
kClickDelegate(base::MakeRefCounted<HandleNotificationClickDelegate>(
base::BindRepeating(&OnNotificationClicked)));
base::string16 GetTitleText(int less_than_n_days) { base::string16 GetTitleText(int less_than_n_days) {
const bool hasExpired = (less_than_n_days <= 0); const bool hasExpired = (less_than_n_days <= 0);
return hasExpired ? l10n_util::GetStringUTF16(IDS_PASSWORD_HAS_EXPIRED_TITLE) return hasExpired ? l10n_util::GetStringUTF16(IDS_PASSWORD_HAS_EXPIRED_TITLE)
...@@ -293,9 +284,12 @@ void ShowSamlPasswordExpiryNotification(Profile* profile, ...@@ -293,9 +284,12 @@ void ShowSamlPasswordExpiryNotification(Profile* profile,
const base::string16 title = GetTitleText(less_than_n_days); const base::string16 title = GetTitleText(less_than_n_days);
const base::string16 body = GetBodyText(less_than_n_days); const base::string16 body = GetBodyText(less_than_n_days);
auto click_delegate = base::MakeRefCounted<HandleNotificationClickDelegate>(
base::BindRepeating(&PasswordChangeDialog::Show, profile));
std::unique_ptr<Notification> notification = ash::CreateSystemNotification( std::unique_ptr<Notification> notification = ash::CreateSystemNotification(
kNotificationType, kNotificationId, title, body, *kDisplaySource, kNotificationType, kNotificationId, title, body, *kDisplaySource,
*kOriginUrl, *kNotifierId, *kRichNotificationData, *kClickDelegate, kIcon, *kOriginUrl, *kNotifierId, *kRichNotificationData, click_delegate, kIcon,
kWarningLevel); kWarningLevel);
NotificationDisplayServiceFactory::GetForProfile(profile)->Display( NotificationDisplayServiceFactory::GetForProfile(profile)->Display(
......
...@@ -6,49 +6,23 @@ ...@@ -6,49 +6,23 @@
#include <string> #include <string>
#include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h" #include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h"
#include "chrome/browser/chromeos/login/saml/saml_password_expiry_notification.h" #include "chrome/browser/chromeos/login/saml/saml_password_expiry_notification.h"
#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/login/auth/saml_password_attributes.h" #include "chromeos/login/auth/saml_password_attributes.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
namespace chromeos { namespace chromeos {
namespace { InSessionPasswordChangeHandler::InSessionPasswordChangeHandler(
const std::string& password_change_url)
std::string GetPasswordChangeUrl(Profile* profile) { : password_change_url_(password_change_url) {}
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSamlPasswordChangeUrl)) {
return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kSamlPasswordChangeUrl);
}
const policy::UserCloudPolicyManagerChromeOS* user_cloud_policy_manager =
profile->GetUserCloudPolicyManagerChromeOS();
if (user_cloud_policy_manager) {
const enterprise_management::PolicyData* policy =
user_cloud_policy_manager->core()->store()->policy();
if (policy->has_change_password_uri()) {
return policy->change_password_uri();
}
}
return SamlPasswordAttributes::LoadFromPrefs(profile->GetPrefs())
.password_change_url();
}
} // namespace
InSessionPasswordChangeHandler::InSessionPasswordChangeHandler() = default;
InSessionPasswordChangeHandler::~InSessionPasswordChangeHandler() = default; InSessionPasswordChangeHandler::~InSessionPasswordChangeHandler() = default;
void InSessionPasswordChangeHandler::HandleInitialize( void InSessionPasswordChangeHandler::HandleInitialize(
...@@ -59,12 +33,11 @@ void InSessionPasswordChangeHandler::HandleInitialize( ...@@ -59,12 +33,11 @@ void InSessionPasswordChangeHandler::HandleInitialize(
AllowJavascript(); AllowJavascript();
base::Value params(base::Value::Type::DICTIONARY); base::Value params(base::Value::Type::DICTIONARY);
const std::string password_change_url = GetPasswordChangeUrl(profile); if (password_change_url_.empty()) {
if (password_change_url.empty()) {
LOG(ERROR) << "Password change url is empty"; LOG(ERROR) << "Password change url is empty";
return; return;
} }
params.SetKey("passwordChangeUrl", base::Value(password_change_url)); params.SetKey("passwordChangeUrl", base::Value(password_change_url_));
const user_manager::User* user = const user_manager::User* user =
ProfileHelper::Get()->GetUserByProfile(profile); ProfileHelper::Get()->GetUserByProfile(profile);
if (user) if (user)
......
...@@ -16,7 +16,8 @@ namespace chromeos { ...@@ -16,7 +16,8 @@ namespace chromeos {
class InSessionPasswordChangeHandler : public content::WebUIMessageHandler, class InSessionPasswordChangeHandler : public content::WebUIMessageHandler,
AuthStatusConsumer { AuthStatusConsumer {
public: public:
InSessionPasswordChangeHandler(); explicit InSessionPasswordChangeHandler(
const std::string& password_change_url);
~InSessionPasswordChangeHandler() override; ~InSessionPasswordChangeHandler() override;
// content::WebUIMessageHandler: // content::WebUIMessageHandler:
...@@ -30,6 +31,7 @@ class InSessionPasswordChangeHandler : public content::WebUIMessageHandler, ...@@ -30,6 +31,7 @@ class InSessionPasswordChangeHandler : public content::WebUIMessageHandler,
void OnAuthSuccess(const UserContext& user_context) override; void OnAuthSuccess(const UserContext& user_context) override;
private: private:
const std::string password_change_url_;
scoped_refptr<CryptohomeAuthenticator> authenticator_; scoped_refptr<CryptohomeAuthenticator> authenticator_;
base::WeakPtrFactory<InSessionPasswordChangeHandler> weak_factory_{this}; base::WeakPtrFactory<InSessionPasswordChangeHandler> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(InSessionPasswordChangeHandler); DISALLOW_COPY_AND_ASSIGN(InSessionPasswordChangeHandler);
......
...@@ -7,15 +7,22 @@ ...@@ -7,15 +7,22 @@
#include <memory> #include <memory>
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chromeos/insession_password_change_handler_chromeos.h" #include "chrome/browser/ui/webui/chromeos/insession_password_change_handler_chromeos.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
#include "chrome/grit/browser_resources.h" #include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/login/auth/saml_password_attributes.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "net/base/url_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
...@@ -26,6 +33,35 @@ namespace { ...@@ -26,6 +33,35 @@ namespace {
PasswordChangeDialog* g_dialog = nullptr; PasswordChangeDialog* g_dialog = nullptr;
std::string GetPasswordChangeUrl(Profile* profile) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSamlPasswordChangeUrl)) {
return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kSamlPasswordChangeUrl);
}
const policy::UserCloudPolicyManagerChromeOS* user_cloud_policy_manager =
profile->GetUserCloudPolicyManagerChromeOS();
if (user_cloud_policy_manager) {
const enterprise_management::PolicyData* policy =
user_cloud_policy_manager->core()->store()->policy();
if (policy->has_change_password_uri()) {
return policy->change_password_uri();
}
}
return SamlPasswordAttributes::LoadFromPrefs(profile->GetPrefs())
.password_change_url();
}
base::string16 GetManagementNotice(Profile* profile) {
base::string16 host = base::UTF8ToUTF16(
net::GetHostAndOptionalPort(GURL(GetPasswordChangeUrl(profile))));
DCHECK(!host.empty());
return l10n_util::GetStringFUTF16(IDS_LOGIN_SAML_PASSWORD_CHANGE_NOTICE,
host);
}
constexpr int kMaxDialogWidth = 768; constexpr int kMaxDialogWidth = 768;
constexpr int kMaxDialogHeight = 640; constexpr int kMaxDialogHeight = 640;
...@@ -48,9 +84,9 @@ gfx::Size GetPasswordChangeDialogSize() { ...@@ -48,9 +84,9 @@ gfx::Size GetPasswordChangeDialogSize() {
} // namespace } // namespace
PasswordChangeDialog::PasswordChangeDialog() PasswordChangeDialog::PasswordChangeDialog(const base::string16& title)
: SystemWebDialogDelegate(GURL(chrome::kChromeUIPasswordChangeUrl), : SystemWebDialogDelegate(GURL(chrome::kChromeUIPasswordChangeUrl), title) {
base::string16()) {} }
PasswordChangeDialog::~PasswordChangeDialog() { PasswordChangeDialog::~PasswordChangeDialog() {
DCHECK_EQ(this, g_dialog); DCHECK_EQ(this, g_dialog);
...@@ -61,13 +97,13 @@ void PasswordChangeDialog::GetDialogSize(gfx::Size* size) const { ...@@ -61,13 +97,13 @@ void PasswordChangeDialog::GetDialogSize(gfx::Size* size) const {
*size = GetPasswordChangeDialogSize(); *size = GetPasswordChangeDialogSize();
} }
void PasswordChangeDialog::Show() { void PasswordChangeDialog::Show(Profile* profile) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (g_dialog) { if (g_dialog) {
g_dialog->Focus(); g_dialog->Focus();
return; return;
} }
g_dialog = new PasswordChangeDialog(); g_dialog = new PasswordChangeDialog(GetManagementNotice(profile));
g_dialog->ShowSystemDialog(); g_dialog->ShowSystemDialog();
} }
...@@ -79,7 +115,8 @@ InSessionPasswordChangeUI::InSessionPasswordChangeUI(content::WebUI* web_ui) ...@@ -79,7 +115,8 @@ InSessionPasswordChangeUI::InSessionPasswordChangeUI(content::WebUI* web_ui)
content::WebUIDataSource* source = content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIPasswordChangeHost); content::WebUIDataSource::Create(chrome::kChromeUIPasswordChangeHost);
web_ui->AddMessageHandler(std::make_unique<InSessionPasswordChangeHandler>()); web_ui->AddMessageHandler(std::make_unique<InSessionPasswordChangeHandler>(
GetPasswordChangeUrl(profile)));
source->SetJsonPath("strings.js"); source->SetJsonPath("strings.js");
......
...@@ -6,17 +6,20 @@ ...@@ -6,17 +6,20 @@
#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_INSESSION_PASSWORD_CHANGE_UI_H_ #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_INSESSION_PASSWORD_CHANGE_UI_H_
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h"
#include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h" #include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h"
#include "ui/web_dialogs/web_dialog_ui.h" #include "ui/web_dialogs/web_dialog_ui.h"
class Profile;
namespace chromeos { namespace chromeos {
class PasswordChangeDialog : public SystemWebDialogDelegate { class PasswordChangeDialog : public SystemWebDialogDelegate {
public: public:
static void Show(); static void Show(Profile* profile);
protected: protected:
PasswordChangeDialog(); explicit PasswordChangeDialog(const base::string16& title);
~PasswordChangeDialog() override; ~PasswordChangeDialog() override;
// ui::WebDialogDelegate: // ui::WebDialogDelegate:
......
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