示例#1
0
        void _authorizePrincipal(const std::string& principalName, bool readOnly) {
            Principal* principal = new Principal(PrincipalName(principalName, "local"));
            ActionSet actions = AuthorizationManager::getActionsForOldStyleUser(
                    "admin", readOnly);

            AuthorizationManager* authorizationManager = cc().getAuthorizationManager();
            authorizationManager->addAuthorizedPrincipal(principal);
            Status status = authorizationManager->acquirePrivilege(
                    Privilege(PrivilegeSet::WILDCARD_RESOURCE, actions), principal->getName());
            verify (status == Status::OK());
        }
示例#2
0
 Status authenticateAndAuthorizePrincipal(const std::string& principalName,
                                          const std::string& dbname,
                                          const BSONObj& userObj) {
     AuthorizationManager* authorizationManager =
             ClientBasic::getCurrent()->getAuthorizationManager();
     Principal* principal = new Principal(principalName, dbname);
     authorizationManager->addAuthorizedPrincipal(principal);
     return authorizationManager->acquirePrivilegesFromPrivilegeDocument(dbname,
                                                                         principal,
                                                                         userObj);
 }