public function setUp()
 {
     parent::setUp();
     Config::getInstance()->LoginLdap = array();
     $this->setSitesManagerApiMock();
     $this->userAccessMapper = new UserAccessMapper();
     $attributeParser = new UserAccessAttributeParser();
     $attributeParser->setThisPiwikInstanceName('thisPiwik');
     $this->userAccessMapper->setUserAccessAttributeParser($attributeParser);
 }
 public function test_getSuperUserAccessFromSuperUserAttribute_ReturnsCorrectResult_WhenCustomDelimetersAreUsed()
 {
     $this->userAccessAttributeParser->setThisPiwikInstanceName('myPiwik');
     $this->userAccessAttributeParser->setServerSpecificationDelimiter('#');
     $this->userAccessAttributeParser->setServerIdsSeparator('|');
     $hasSuperUserAccess = $this->userAccessAttributeParser->getSuperUserAccessFromSuperUserAttribute("anoth | myPiwik | whatever");
     $this->assertTrue($hasSuperUserAccess);
     $hasSuperUserAccess = $this->userAccessAttributeParser->getSuperUserAccessFromSuperUserAttribute("a # myPiwik # c");
     $this->assertTrue($hasSuperUserAccess);
 }
 /**
  * Returns a configured UserAccessMapper instance. The instance is configured
  * using INI config option values.
  *
  * @return UserAccessMapper
  */
 public static function makeConfigured()
 {
     $result = new UserAccessMapper();
     $result->setUserAccessAttributeParser(UserAccessAttributeParser::makeConfigured());
     $viewAttributeName = Config::getLdapViewAccessField();
     if (!empty($viewAttributeName)) {
         $result->setViewAttributeName($viewAttributeName);
     }
     $adminAttributeName = Config::getLdapAdminAccessField();
     if (!empty($adminAttributeName)) {
         $result->setAdminAttributeName($adminAttributeName);
     }
     $superuserAttributeName = Config::getSuperUserAccessField();
     if (!empty($superuserAttributeName)) {
         $result->setSuperuserAttributeName($superuserAttributeName);
     }
     return $result;
 }
 /**
  * Creates a UserAccessAttributeParser instance using INI configuration.
  *
  * @return UserAccessAttributeParser
  */
 public static function makeConfigured()
 {
     $result = new UserAccessAttributeParser();
     $serverSpecificationDelimiter = Config::getUserAccessAttributeServerSpecificationDelimiter();
     if (!empty($serverSpecificationDelimiter)) {
         $result->setServerSpecificationDelimiter($serverSpecificationDelimiter);
     }
     $serverListSeparator = Config::getUserAccessAttributeServerSiteListSeparator();
     if (!empty($serverListSeparator)) {
         $result->setServerIdsSeparator($serverListSeparator);
     }
     $thisPiwikInstanceName = Config::getDesignatedPiwikInstanceName();
     if (!empty($thisPiwikInstanceName)) {
         $result->setThisPiwikInstanceName($thisPiwikInstanceName);
     } else {
         if ($result->getServerIdsSeparator() == ':') {
             // TODO: remove this warning and move it to the settings page.
             /** @var LoggerInterface $logger */
             $logger = StaticContainer::get('Psr\\Log\\LoggerInterface');
             $logger->info("UserAttributesParser::{func}: Configured with no instance name so matching by URL, but server/site IDs" . " separator set to special ':' character. This character may show up in URLs in LDAP, which will " . "cause problems. We recommend you use a character not often found in URLs, such as '|'.", array('func' => __FUNCTION__));
         }
     }
     return $result;
 }
 /**
  * Creates a UserAccessAttributeParser instance using INI configuration.
  *
  * @return UserAccessAttributeParser
  */
 public static function makeConfigured()
 {
     $result = new UserAccessAttributeParser();
     $serverSpecificationDelimiter = Config::getUserAccessAttributeServerSpecificationDelimiter();
     if (!empty($serverSpecificationDelimiter)) {
         $result->setServerSpecificationDelimiter($serverSpecificationDelimiter);
     }
     $serverListSeparator = Config::getUserAccessAttributeServerSiteListSeparator();
     if (!empty($serverListSeparator)) {
         $result->setServerIdsSeparator($serverListSeparator);
     }
     $thisPiwikInstanceName = Config::getDesignatedPiwikInstanceName();
     if (!empty($thisPiwikInstanceName)) {
         $result->setThisPiwikInstanceName($thisPiwikInstanceName);
     } else {
         if ($result->getServerIdsSeparator() == ':') {
             Log::info("UserAttributesParser::%s: Configured with no instance name so matching by URL, but server/site IDs" . " separator set to special ':' character. This character may show up in URLs in LDAP, which will " . "cause problems. We recommend you use a character not often found in URLs, such as '|'.", __FUNCTION__);
         }
     }
     Log::debug("UserAccessAttributeParser::%s: configuring with serverSpecificationDelimiter = %s, serverSiteIdListSeparator = %s, " . "thisPiwikInstanceName = %s", __FUNCTION__, $serverSpecificationDelimiter, $serverListSeparator, $thisPiwikInstanceName);
     return $result;
 }
예제 #6
0
 /**
  * Returns a configured UserAccessMapper instance. The instance is configured
  * using INI config option values.
  *
  * @return UserAccessMapper
  */
 public static function makeConfigured()
 {
     $result = new UserAccessMapper();
     $result->setUserAccessAttributeParser(UserAccessAttributeParser::makeConfigured());
     $viewAttributeName = Config::getLdapViewAccessField();
     if (!empty($viewAttributeName)) {
         $result->setViewAttributeName($viewAttributeName);
     }
     $adminAttributeName = Config::getLdapAdminAccessField();
     if (!empty($adminAttributeName)) {
         $result->setAdminAttributeName($adminAttributeName);
     }
     $superuserAttributeName = Config::getSuperUserAccessField();
     if (!empty($superuserAttributeName)) {
         $result->setSuperuserAttributeName($superuserAttributeName);
     }
     Log::debug("UserAccessMapper::%s: configuring with viewAttributeName = '%s', adminAttributeName = '%s', superuserAttributeName = '%s'", __FUNCTION__, $viewAttributeName, $adminAttributeName, $superuserAttributeName);
     return $result;
 }