/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
PolicyManager::Instance().activate(admin, state);
}
+bool API::Admin::IsActivated()
+{
+ return PolicyManager::Instance().isActivated();
+}
+
std::unordered_map<std::string, int> API::Admin::GetAll()
{
return PolicyManager::Instance().getAdmins();
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
static void Disenroll(const std::string& admin);
static void Activate(const std::string& admin, bool state = true);
+ static bool IsActivated();
static std::unordered_map<std::string, int> GetAll();
};
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
this->storage.activate(admin, state);
}
+bool PolicyManager::isActivated()
+{
+ return this->storage.isActivated();
+}
+
void PolicyManager::set(const std::string& policy,
const PolicyValue& value,
const std::string& admin)
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void disenroll(const std::string& admin);
void activate(const std::string& admin, bool state);
+ bool isActivated();
void set(const std::string& policy,
const PolicyValue& value,
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return this->admins[admin].activated;
}
+bool PolicyStorage::isActivated()
+{
+ for (const auto& admin : this->admins)
+ if (admin.second.activated)
+ return true;
+
+ return false;
+}
+
void PolicyStorage::update(const std::string& admin,
const std::string& policy,
const PolicyValue& value)
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void disenroll(const std::string& admin);
void activate(const std::string& admin, bool state = true);
bool isActivated(const std::string& admin);
+ /// Check that none of admins are activated.
+ bool isActivated();
void define(const std::string& policy, const PolicyValue& ivalue);
void update(const std::string& admin,
manager.disenroll("testAdmin");
}
+TEST(PolicyCoreTests, is_activated) {
+ auto& manager = PolicyManager::Instance();
+ manager.enroll("testAdmin1");
+ manager.enroll("testAdmin2");
+
+ EXPECT_FALSE(manager.isActivated());
+
+ manager.activate("testAdmin1", true);
+ EXPECT_TRUE(manager.isActivated());
+
+ manager.activate("testAdmin2", true);
+ EXPECT_TRUE(manager.isActivated());
+
+ manager.activate("testAdmin1", false);
+ EXPECT_TRUE(manager.isActivated());
+
+ manager.activate("testAdmin2", false);
+ EXPECT_FALSE(manager.isActivated());
+
+ manager.disenroll("testAdmin1");
+ manager.disenroll("testAdmin2");
+}
+
} // namespace policy
} // namespace vist