本文整理汇总了C++中RoleNameIterator::get方法的典型用法代码示例。如果您正苦于以下问题:C++ RoleNameIterator::get方法的具体用法?C++ RoleNameIterator::get怎么用?C++ RoleNameIterator::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RoleNameIterator
的用法示例。
在下文中一共展示了RoleNameIterator::get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getRoleDescriptionsForDB
Status AuthzManagerExternalStateLocal::getRoleDescriptionsForDB(const std::string dbname,
bool showPrivileges,
bool showBuiltinRoles,
vector<BSONObj>* result) {
boost::lock_guard<boost::mutex> lk(_roleGraphMutex);
for (RoleNameIterator it = _roleGraph.getRolesForDatabase(dbname);
it.more(); it.next()) {
if (!showBuiltinRoles && _roleGraph.isBuiltinRole(it.get())) {
continue;
}
BSONObj roleDoc;
Status status = _getRoleDescription_inlock(it.get(), showPrivileges, &roleDoc);
if (!status.isOK()) {
return status;
}
result->push_back(roleDoc);
}
return Status::OK();
}
示例2: getUserDescription
Status AuthzManagerExternalStateMock::getUserDescription(
const UserName& userName, BSONObj* result) {
BSONObj privDoc;
Status status = getPrivilegeDocument(userName, 2, &privDoc);
if (!status.isOK())
return status;
unordered_set<RoleName> indirectRoles;
PrivilegeVector allPrivileges;
for (BSONObjIterator iter(privDoc["roles"].Obj()); iter.more(); iter.next()) {
if (!(*iter)["hasRole"].trueValue())
continue;
RoleName roleName((*iter)[AuthorizationManager::ROLE_NAME_FIELD_NAME].str(),
(*iter)[AuthorizationManager::ROLE_SOURCE_FIELD_NAME].str());
indirectRoles.insert(roleName);
for (RoleNameIterator subordinates = _roleGraph.getIndirectSubordinates(
roleName);
subordinates.more();
subordinates.next()) {
indirectRoles.insert(subordinates.get());
}
const PrivilegeVector& rolePrivileges(_roleGraph.getAllPrivileges(roleName));
for (PrivilegeVector::const_iterator priv = rolePrivileges.begin(),
end = rolePrivileges.end();
priv != end;
++priv) {
Privilege::addPrivilegeToPrivilegeVector(&allPrivileges, *priv);
}
}
mutablebson::Document userDoc(privDoc, mutablebson::Document::kInPlaceDisabled);
mutablebson::Element indirectRolesElement = userDoc.makeElementArray("indirectRoles");
mutablebson::Element privilegesElement = userDoc.makeElementArray("privileges");
mutablebson::Element warningsElement = userDoc.makeElementArray("warnings");
fassert(17180, userDoc.root().pushBack(privilegesElement));
fassert(17181, userDoc.root().pushBack(indirectRolesElement));
addRoleNameObjectsToArrayElement(indirectRolesElement,
makeRoleNameIteratorForContainer(indirectRoles));
addPrivilegeObjectsOrWarningsToArrayElement(
privilegesElement, warningsElement, allPrivileges);
if (warningsElement.hasChildren()) {
fassert(17182, userDoc.root().pushBack(warningsElement));
}
*result = userDoc.getObject();
return Status::OK();
}
示例3: _resolveUserRoles
void AuthzManagerExternalStateLocal::_resolveUserRoles(mutablebson::Document* userDoc,
const std::vector<RoleName>& directRoles) {
unordered_set<RoleName> indirectRoles;
PrivilegeVector allPrivileges;
bool isRoleGraphInconsistent;
{
stdx::lock_guard<stdx::mutex> lk(_roleGraphMutex);
isRoleGraphInconsistent = _roleGraphState == roleGraphStateConsistent;
for (size_t i = 0; i < directRoles.size(); ++i) {
const RoleName& role(directRoles[i]);
indirectRoles.insert(role);
if (isRoleGraphInconsistent) {
for (RoleNameIterator subordinates = _roleGraph.getIndirectSubordinates(role);
subordinates.more();
subordinates.next()) {
indirectRoles.insert(subordinates.get());
}
}
const PrivilegeVector& rolePrivileges(isRoleGraphInconsistent
? _roleGraph.getAllPrivileges(role)
: _roleGraph.getDirectPrivileges(role));
for (PrivilegeVector::const_iterator priv = rolePrivileges.begin(),
end = rolePrivileges.end();
priv != end;
++priv) {
Privilege::addPrivilegeToPrivilegeVector(&allPrivileges, *priv);
}
}
}
mutablebson::Element inheritedRolesElement = userDoc->makeElementArray("inheritedRoles");
mutablebson::Element privilegesElement = userDoc->makeElementArray("inheritedPrivileges");
mutablebson::Element warningsElement = userDoc->makeElementArray("warnings");
fassert(17159, userDoc->root().pushBack(inheritedRolesElement));
fassert(17158, userDoc->root().pushBack(privilegesElement));
if (!isRoleGraphInconsistent) {
fassert(17160,
warningsElement.appendString(
"", "Role graph inconsistent, only direct privileges available."));
}
addRoleNameObjectsToArrayElement(inheritedRolesElement,
makeRoleNameIteratorForContainer(indirectRoles));
addPrivilegeObjectsOrWarningsToArrayElement(privilegesElement, warningsElement, allPrivileges);
if (warningsElement.hasChildren()) {
fassert(17161, userDoc->root().pushBack(warningsElement));
}
}
示例4: getBSONForRole
Status AuthorizationManager::getBSONForRole(RoleGraph* graph,
const RoleName& roleName,
mutablebson::Element result) {
if (!graph->roleExists(roleName)) {
return Status(ErrorCodes::RoleNotFound,
mongoutils::str::stream() << roleName.getFullName() <<
"does not name an existing role");
}
std::string id = mongoutils::str::stream() << roleName.getDB() << "." << roleName.getRole();
result.appendString("_id", id);
result.appendString(ROLE_NAME_FIELD_NAME, roleName.getRole());
result.appendString(ROLE_SOURCE_FIELD_NAME, roleName.getDB());
// Build privileges array
mutablebson::Element privilegesArrayElement =
result.getDocument().makeElementArray("privileges");
result.pushBack(privilegesArrayElement);
const PrivilegeVector& privileges = graph->getDirectPrivileges(roleName);
Status status = getBSONForPrivileges(privileges, privilegesArrayElement);
if (!status.isOK()) {
return status;
}
// Build roles array
mutablebson::Element rolesArrayElement = result.getDocument().makeElementArray("roles");
result.pushBack(rolesArrayElement);
for (RoleNameIterator roles = graph->getDirectSubordinates(roleName);
roles.more();
roles.next()) {
const RoleName& subRole = roles.get();
mutablebson::Element roleObj = result.getDocument().makeElementObject("");
roleObj.appendString(ROLE_NAME_FIELD_NAME, subRole.getRole());
roleObj.appendString(ROLE_SOURCE_FIELD_NAME, subRole.getDB());
rolesArrayElement.pushBack(roleObj);
}
return Status::OK();
}
示例5: getUserDescription
Status AuthzManagerExternalStateLocal::getUserDescription(
const UserName& userName,
BSONObj* result) {
BSONObj userDoc;
Status status = _getUserDocument(userName, &userDoc);
if (!status.isOK())
return status;
BSONElement directRolesElement;
status = bsonExtractTypedField(userDoc, "roles", Array, &directRolesElement);
if (!status.isOK())
return status;
std::vector<RoleName> directRoles;
status = V2UserDocumentParser::parseRoleVector(BSONArray(directRolesElement.Obj()),
&directRoles);
if (!status.isOK())
return status;
unordered_set<RoleName> indirectRoles;
PrivilegeVector allPrivileges;
bool isRoleGraphInconsistent;
{
boost::lock_guard<boost::mutex> lk(_roleGraphMutex);
isRoleGraphInconsistent = _roleGraphState == roleGraphStateConsistent;
for (size_t i = 0; i < directRoles.size(); ++i) {
const RoleName& role(directRoles[i]);
indirectRoles.insert(role);
if (isRoleGraphInconsistent) {
for (RoleNameIterator subordinates = _roleGraph.getIndirectSubordinates(role);
subordinates.more();
subordinates.next()) {
indirectRoles.insert(subordinates.get());
}
}
const PrivilegeVector& rolePrivileges(
isRoleGraphInconsistent ?
_roleGraph.getAllPrivileges(role) :
_roleGraph.getDirectPrivileges(role));
for (PrivilegeVector::const_iterator priv = rolePrivileges.begin(),
end = rolePrivileges.end();
priv != end;
++priv) {
Privilege::addPrivilegeToPrivilegeVector(&allPrivileges, *priv);
}
}
}
mutablebson::Document resultDoc(userDoc, mutablebson::Document::kInPlaceDisabled);
mutablebson::Element inheritedRolesElement = resultDoc.makeElementArray("inheritedRoles");
mutablebson::Element privilegesElement = resultDoc.makeElementArray("inheritedPrivileges");
mutablebson::Element warningsElement = resultDoc.makeElementArray("warnings");
fassert(17159, resultDoc.root().pushBack(inheritedRolesElement));
fassert(17158, resultDoc.root().pushBack(privilegesElement));
if (!isRoleGraphInconsistent) {
fassert(17160, warningsElement.appendString(
"", "Role graph inconsistent, only direct privileges available."));
}
addRoleNameObjectsToArrayElement(inheritedRolesElement,
makeRoleNameIteratorForContainer(indirectRoles));
addPrivilegeObjectsOrWarningsToArrayElement(
privilegesElement, warningsElement, allPrivileges);
if (warningsElement.hasChildren()) {
fassert(17161, resultDoc.root().pushBack(warningsElement));
}
*result = resultDoc.getObject();
return Status::OK();
}