예제 #1
0
bool validateUser(const std::string& username,
                  const std::string& requiredGroup,
                  bool groupFailureWarning)
{
   // short circuit if we aren't validating users
   if (!server::options().authValidateUsers())
      return true;
   
   // get the user
   core::system::user::User user;
   Error error = userFromUsername(username, &user);
   if (error)
   {
      // log the error only if it is unexpected
      if (!core::system::isUserNotFoundError(error))
         LOG_ERROR(error);

      // not found either due to non-existence or an unexpected error
      return false;
   }

   // validate user if necessary
   if (!requiredGroup.empty())
   {    
      // see if they are a member of the required group
      bool belongsToGroup ;
      error = core::system::userBelongsToGroup(user,
                                               requiredGroup,
                                               &belongsToGroup);
      if (error)
      {
         // log and return false
         LOG_ERROR(error);
         return false;
      }
      else
      {
         // log a warning whenever a user doesn't belong to a required group
         if (!belongsToGroup && groupFailureWarning)
         {
            LOG_WARNING_MESSAGE(
             "User " + username + " could not be authenticated because they "
             "do not belong to the required group (" + requiredGroup + ")");
         }

         // return belongs status
         return belongsToGroup;
      }
   }
   else
   {
      // not validating (running in some type of dev mode where we
      // don't have a system account for every login)
      return true;
   }
}
예제 #2
0
bool validateUser(const std::string& username)
{
   // short circuit if we aren't validating users
   if (!server::options().authValidateUsers())
      return true;
   
   // get the user
   core::system::user::User user;
   Error error = userFromUsername(username, &user);
   if (error)
   {
      // log the error only if it is unexpected
      if (!core::system::isUserNotFoundError(error))
         LOG_ERROR(error);

      // not found either due to non-existence or an unexpected error
      return false;
   }

   // validate user if necessary
   std::string requiredGroup = server::options().authRequiredUserGroup();
   if (!requiredGroup.empty())
   {    
      // see if they are a member of the "rstudio_users" group
      bool belongsToGroup ;
      error = core::system::userBelongsToGroup(username,
                                               requiredGroup,
                                               &belongsToGroup);
      if (error)
      {
         // log and return false
         LOG_ERROR(error);
         return false;
      }
      else
      {
         // return belongs status
         return belongsToGroup;
      }
   }
   else
   {
      // not validating (running in some type of dev mode where we
      // don't have a system account for every login)
      return true;
   }
}
예제 #3
0
bool exists(const std::string& username)
{
   User user;
   Error error = userFromUsername(username, &user);
   return !error;
}