Principal Service: Add support for multiple user accounts
This Cl enhances the Mojo Principal Service so that it
supports multiple user identities for each app. It offers
two new methods
- GetUsers to get all the user identities for the app
- SetCurrentUser to set the current user identity for the app
R=ashankar@google.com, gauthamt@google.com, ukode@google.com
Review URL: https://codereview.chromium.org/1418013004 .
diff --git a/examples/bank_app/customer.cc b/examples/bank_app/customer.cc
index 7fb227f..b312d7d 100644
--- a/examples/bank_app/customer.cc
+++ b/examples/bank_app/customer.cc
@@ -15,17 +15,9 @@
class LoginHandler {
public:
- void Run(const vanadium::BlessingPtr& b) const {
- std::string user;
- if (b && b->chain.size() > 0) {
- user = b->chain[0]->extension;
- for (size_t i = 1; i < b->chain.size(); i++) {
- user += vanadium::ChainSeparator;
- user += b->chain[i]->extension;
- }
- }
- if (!user.empty()) {
- MOJO_LOG(INFO) << "Welcome: " << user;
+ void Run(const vanadium::UserPtr& user) const {
+ if (user) {
+ MOJO_LOG(INFO) << "User logged-in as " << user->email;
}
}
};
@@ -33,13 +25,15 @@
class BankCustomer : public mojo::ApplicationDelegate {
public:
void Initialize(mojo::ApplicationImpl* app) override {
- // Get user login credentials
app->ConnectToService("mojo:principal_service", &login_service_);
+
+ // Login to the principal service to get a user identity.
login_service_->Login(LoginHandler());
- // Check and see whether we got a valid user blessing.
+ // Check and see whether we got a valid user id.
if (!login_service_.WaitForIncomingResponse()) {
- MOJO_LOG(INFO) << "Login() to the principal service failed\n";
+ MOJO_LOG(INFO) << "Login() to the principal service failed";
}
+
BankPtr bank;
app->ConnectToService("mojo:bank", &bank);
bank->Deposit(500/*usd*/);