Esempio n. 1
0
 /**
  * @param string $configPrefix
  */
 private function addAccess($configPrefix)
 {
     static $ocConfig;
     static $fs;
     static $log;
     static $avatarM;
     static $userMap;
     static $groupMap;
     static $db;
     static $userManager;
     if (is_null($fs)) {
         $ocConfig = \OC::$server->getConfig();
         $fs = new FilesystemHelper();
         $log = new LogWrapper();
         $avatarM = \OC::$server->getAvatarManager();
         $db = \OC::$server->getDatabaseConnection();
         $userMap = new UserMapping($db);
         $groupMap = new GroupMapping($db);
         $userManager = \OC::$server->getUserManager();
     }
     $userManager = new user\Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db, $userManager);
     $connector = new Connection($this->ldap, $configPrefix);
     $access = new Access($connector, $this->ldap, $userManager);
     $access->setUserMapper($userMap);
     $access->setGroupMapper($groupMap);
     self::$accesses[$configPrefix] = $access;
 }
Esempio n. 2
0
 public function testEscapeFilterPartEscapeWildcard2()
 {
     list($lw, $con) = $this->getConnecterAndLdapMock();
     $access = new Access($con, $lw);
     $input = 'foo*bar';
     $expected = 'foo\\\\*bar';
     $this->assertTrue($expected === $access->escapeFilterPart($input));
 }
 /**
  * Tests whether a filter for limited groups is effective when more existing
  * groups were passed for validation.
  *
  * @return bool
  */
 private function case3()
 {
     $this->connection->setConfiguration(['ldapGroupFilter' => '(objectclass=groupOfNames)']);
     $dns = ['cn=RedGroup,ou=Groups,' . $this->base, 'cn=PurpleGroup,ou=Groups,' . $this->base, 'cn=SquaredCircleGroup,ou=SpecialGroups,' . $this->base];
     $result = $this->access->groupsMatchFilter($dns);
     $status = count($result) === 2 && in_array('cn=RedGroup,ou=Groups,' . $this->base, $result) && in_array('cn=PurpleGroup,ou=Groups,' . $this->base, $result);
     return $status;
 }
Esempio n. 4
0
 /**
  * reads the user details
  */
 protected function fetchDetails()
 {
     $properties = array('displayName' => 'user_ldap', 'uid' => 'user_ldap', 'homePath' => 'user_ldap', 'email' => 'settings', 'lastLogin' => 'login');
     foreach ($properties as $property => $app) {
         $this->{$property} = $this->preferences->getValue($this->ocName, $app, $property, '');
     }
     $dn = $this->access->ocname2dn($this->ocName, true);
     $this->dn = $dn !== false ? $dn : '';
     $this->determineShares();
 }
	/**
	 * Tests whether a filter for limited groups is effective when more existing
	 * groups were passed for validation.
	 *
	 * @return bool
	 */
	private function case2() {
		$this->connection->setConfiguration(['ldapGroupFilter' => '(|(cn=RedGroup)(cn=PurpleGroup))']);

		$dns = [
			'cn=RedGroup,ou=Groups,' . $this->base,
			'cn=BlueGroup,ou=Groups,' . $this->base,
			'cn=PurpleGroup,ou=Groups,' . $this->base
		];
		$result = $this->access->groupsMatchFilter($dns);

		$status =
			count($result) === 2
			&& in_array('cn=RedGroup,ou=Groups,' . $this->base, $result)
			&& in_array('cn=PurpleGroup,ou=Groups,' . $this->base, $result);

		return $status;
	}
Esempio n. 6
0
 /**
  * Prepares the Access mock for getUsers tests
  * @param \OCA\user_ldap\lib\Access $access mock
  * @return void
  */
 private function prepareAccessForGetUsers(&$access)
 {
     $access->expects($this->once())->method('escapeFilterPart')->will($this->returnCallback(function ($search) {
         return $search;
     }));
     $access->expects($this->any())->method('getFilterPartForUserSearch')->will($this->returnCallback(function ($search) {
         return $search;
     }));
     $access->expects($this->any())->method('combineFilterWithAnd')->will($this->returnCallback(function ($param) {
         return $param[1];
     }));
     $access->expects($this->any())->method('fetchListOfUsers')->will($this->returnCallback(function ($search, $a, $l, $o) {
         $users = array('gunslinger', 'newyorker', 'ladyofshadows');
         if (empty($search)) {
             $result = $users;
         } else {
             $result = array();
             foreach ($users as $user) {
                 if (stripos($user, $search) !== false) {
                     $result[] = $user;
                 }
             }
         }
         if (!is_null($l) || !is_null($o)) {
             $result = array_slice($result, $o, $l);
         }
         return $result;
     }));
     $access->expects($this->any())->method('ownCloudUserNames')->will($this->returnArgument(0));
 }
Esempio n. 7
0
File: jobs.php Progetto: evanjt/core
 /**
  * @return \OCA\user_ldap\GROUP_LDAP|\OCA\user_ldap\Group_Proxy
  */
 private static function getGroupBE()
 {
     if (!is_null(self::$groupBE)) {
         return self::$groupBE;
     }
     $helper = new Helper();
     $configPrefixes = $helper->getServerConfigurationPrefixes(true);
     $ldapWrapper = new LDAP();
     if (count($configPrefixes) === 1) {
         //avoid the proxy when there is only one LDAP server configured
         $dbc = \OC::$server->getDatabaseConnection();
         $userManager = new user\Manager(\OC::$server->getConfig(), new FilesystemHelper(), new LogWrapper(), \OC::$server->getAvatarManager(), new \OCP\Image(), $dbc);
         $connector = new Connection($ldapWrapper, $configPrefixes[0]);
         $ldapAccess = new Access($connector, $ldapWrapper, $userManager);
         $groupMapper = new GroupMapping($dbc);
         $userMapper = new UserMapping($dbc);
         $ldapAccess->setGroupMapper($groupMapper);
         $ldapAccess->setUserMapper($userMapper);
         self::$groupBE = new \OCA\user_ldap\GROUP_LDAP($ldapAccess);
     } else {
         self::$groupBE = new \OCA\user_ldap\Group_Proxy($configPrefixes, $ldapWrapper);
     }
     return self::$groupBE;
 }
Esempio n. 8
0
 public function testStringResemblesDNLDAPmod()
 {
     list($lw, $con, $um) = $this->getConnecterAndLdapMock();
     $lw = new \OCA\user_ldap\lib\LDAP();
     $access = new Access($con, $lw, $um);
     if (!function_exists('ldap_explode_dn')) {
         $this->markTestSkipped('LDAP Module not available');
     }
     $cases = $this->getResemblesDNInputData();
     foreach ($cases as $case) {
         $this->assertSame($case['expectedResult'], $access->stringResemblesDN($case['input']));
     }
 }
Esempio n. 9
0
 /**
  * @dataProvider dNAttributeProvider
  */
 public function testSanitizeDN($attribute)
 {
     list($lw, $con, $um) = $this->getConnectorAndLdapMock();
     $dnFromServer = 'cn=Mixed Cases,ou=Are Sufficient To,ou=Test,dc=example,dc=org';
     $lw->expects($this->any())->method('isResource')->will($this->returnValue(true));
     $lw->expects($this->any())->method('getAttributes')->will($this->returnValue(array($attribute => array('count' => 1, $dnFromServer))));
     $access = new Access($con, $lw, $um);
     $values = $access->readAttribute('uid=whoever,dc=example,dc=org', $attribute);
     $this->assertSame($values[0], strtolower($dnFromServer));
 }
Esempio n. 10
0
 public function testGetDomainDNFromDNError()
 {
     list($lw, $con, $um) = $this->getConnecterAndLdapMock();
     $access = new Access($con, $lw, $um);
     $inputDN = 'foobar';
     $expected = '';
     $lw->expects($this->once())->method('explodeDN')->with($inputDN, 0)->will($this->returnValue(false));
     $this->assertSame($expected, $access->getDomainDNFromDN($inputDN));
 }
Esempio n. 11
0
 public function testBatchApplyUserAttributes()
 {
     list($lw, $con, $um) = $this->getConnectorAndLdapMock();
     $access = new Access($con, $lw, $um);
     $mapperMock = $this->getMockBuilder('\\OCA\\User_LDAP\\Mapping\\UserMapping')->disableOriginalConstructor()->getMock();
     $userMock = $this->getMockBuilder('\\OCA\\user_ldap\\lib\\user\\User')->disableOriginalConstructor()->getMock();
     $access->setUserMapper($mapperMock);
     $data = array(array('dn' => 'foobar', $con->ldapUserDisplayName => 'barfoo'), array('dn' => 'foo', $con->ldapUserDisplayName => 'bar'), array('dn' => 'raboof', $con->ldapUserDisplayName => 'oofrab'));
     $userMock->expects($this->exactly(count($data)))->method('processAttributes');
     $um->expects($this->exactly(count($data)))->method('get')->will($this->returnValue($userMock));
     $access->batchApplyUserAttributes($data);
 }