本文整理汇总了C++中UserManager::setAuthorization方法的典型用法代码示例。如果您正苦于以下问题:C++ UserManager::setAuthorization方法的具体用法?C++ UserManager::setAuthorization怎么用?C++ UserManager::setAuthorization使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserManager
的用法示例。
在下文中一共展示了UserManager::setAuthorization方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//
// main
//
int main(int argc, char** argv)
{
verbose = (getenv ("PEGASUS_TEST_VERBOSE")) ? true : false;
if (verbose) cout << argv[0] << ": started" << endl;
CIMNamespaceName nameSpace;
String testUser = System::getEffectiveUserName();
// Create a test repository
const char* tmpDir = getenv ("PEGASUS_TMP");
String repositoryPath;
if (tmpDir == NULL)
{
repositoryPath = ".";
}
else
{
repositoryPath = tmpDir;
}
repositoryPath.append("/repository");
FileSystem::removeDirectoryHier(repositoryPath);
CIMRepository* repository = new CIMRepository(repositoryPath);
// -- Create a UserManager object:
UserManager* userManager = UserManager::getInstance(repository);
//
// Test authorization
//
try
{
nameSpace = BAD_NAMESPACE;
PEGASUS_TEST_ASSERT(!userManager->verifyNamespace(nameSpace));
nameSpace = GOOD_NAMESPACE;
PEGASUS_TEST_ASSERT(!userManager->verifyNamespace(nameSpace));
userManager->setAuthorization(testUser, nameSpace, "rw");
userManager->setAuthorization("root", nameSpace, "w");
String temp = userManager->getAuthorization(testUser, nameSpace);
if (testUser != "root")
PEGASUS_TEST_ASSERT(
String::equal(temp, "rw") || String::equal(temp, "wr"));
temp = userManager->getAuthorization("root", nameSpace);
PEGASUS_TEST_ASSERT(String::equal(temp, "w"));
userManager->removeAuthorization("root", nameSpace);
temp.clear();
try
{
temp = userManager->getAuthorization("root", nameSpace);
PEGASUS_TEST_ASSERT(temp.size() == 0);
}catch(const Exception&) { }
userManager->setAuthorization("root", nameSpace, "w");
if (testUser != "root")
PEGASUS_TEST_ASSERT(userManager->verifyAuthorization(
testUser, nameSpace, CIMName("GetInstance")));
PEGASUS_TEST_ASSERT(!userManager->verifyAuthorization(
"root", nameSpace, CIMName("GetInstance")));
userManager->setAuthorization("root", nameSpace, "r");
PEGASUS_TEST_ASSERT(!userManager->verifyAuthorization(
"root", nameSpace, CIMName("SetProperty")));
userManager->removeAuthorization("root", nameSpace);
if (testUser != "root")
userManager->removeAuthorization(testUser, nameSpace);
}
catch(Exception& e)
{
cout << argv[0] << " Exception: " << e.getMessage() << endl;
PEGASUS_TEST_ASSERT(0);
}
UserManager::destroy();
delete repository;
FileSystem::removeDirectoryHier(repositoryPath);
cout << argv[0] << " +++++ passed all tests" << endl;
return 0;
}