summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2014-06-25 17:36:19 +0200
committerArthur Schiwon <blizzz@owncloud.com>2014-08-29 11:14:16 +0200
commit441c600c906a2ec55bdab123840be5d1d63bb679 (patch)
treed6880aa4c343d010e340761a0ba453de1eff06b9 /apps/user_ldap
parentbaa49cd58a670ca7fdd9211cf057b2257d86eff9 (diff)
downloadnextcloud-server-441c600c906a2ec55bdab123840be5d1d63bb679.tar.gz
nextcloud-server-441c600c906a2ec55bdab123840be5d1d63bb679.zip
remove Access as hard dependency, inject it instead
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/ajax/wizard.php19
-rw-r--r--apps/user_ldap/lib/wizard.php42
-rw-r--r--apps/user_ldap/tests/wizard.php17
3 files changed, 41 insertions, 37 deletions
diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php
index ad75a384369..d5759c597a2 100644
--- a/apps/user_ldap/ajax/wizard.php
+++ b/apps/user_ldap/ajax/wizard.php
@@ -39,9 +39,24 @@ if(!isset($_POST['ldap_serverconfig_chooser'])) {
}
$prefix = $_POST['ldap_serverconfig_chooser'];
-$ldapWrapper = new OCA\user_ldap\lib\LDAP();
+$ldapWrapper = new \OCA\user_ldap\lib\LDAP();
$configuration = new \OCA\user_ldap\lib\Configuration($prefix);
-$wizard = new \OCA\user_ldap\lib\Wizard($configuration, $ldapWrapper);
+
+$con = new \OCA\user_ldap\lib\Connection($ldapWrapper, '', null);
+$con->setConfiguration($configuration->getConfiguration());
+$con->ldapConfigurationActive = true;
+$con->setIgnoreValidation(true);
+
+$userManager = new \OCA\user_ldap\lib\user\Manager(
+ \OC::$server->getConfig(),
+ new \OCA\user_ldap\lib\FilesystemHelper(),
+ new \OCA\user_ldap\lib\LogWrapper(),
+ \OC::$server->getAvatarManager(),
+ new \OCP\Image());
+
+$access = new \OCA\user_ldap\lib\Access($con, $ldapWrapper, $userManager);
+
+$wizard = new \OCA\user_ldap\lib\Wizard($configuration, $ldapWrapper, $access);
switch($action) {
case 'guessPortAndTLS':
diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php
index 9a7f7520f56..25dc4598ffb 100644
--- a/apps/user_ldap/lib/wizard.php
+++ b/apps/user_ldap/lib/wizard.php
@@ -25,6 +25,7 @@ namespace OCA\user_ldap\lib;
class Wizard extends LDAPUtility {
static protected $l;
+ protected $access;
protected $cr;
protected $configuration;
protected $result;
@@ -48,12 +49,13 @@ class Wizard extends LDAPUtility {
* @param Configuration $configuration an instance of Configuration
* @param ILDAPWrapper $ldap an instance of ILDAPWrapper
*/
- public function __construct(Configuration $configuration, ILDAPWrapper $ldap) {
+ public function __construct(Configuration $configuration, ILDAPWrapper $ldap, Access $access) {
parent::__construct($ldap);
$this->configuration = $configuration;
if(is_null(Wizard::$l)) {
Wizard::$l = \OC_L10N::get('user_ldap');
}
+ $this->access = $access;
$this->result = new WizardResult;
}
@@ -78,11 +80,10 @@ class Wizard extends LDAPUtility {
throw new \Exception('Requirements not met', 400);
}
- $ldapAccess = $this->getAccess();
if($type === 'groups') {
- $result = $ldapAccess->countGroups($filter);
+ $result = $this->access->countGroups($filter);
} else if($type === 'users') {
- $result = $ldapAccess->countUsers($filter);
+ $result = $this->access->countUsers($filter);
} else {
throw new \Exception('internal error: invald object type', 500);
}
@@ -142,13 +143,12 @@ class Wizard extends LDAPUtility {
return false;
}
- $access = $this->getAccess();
- $filter = $access->combineFilterWithAnd(array(
+ $filter = $this->access->combineFilterWithAnd(array(
$this->configuration->ldapUserFilter,
$attr . '=*'
));
- return $access->countUsers($filter);
+ return $this->access->countUsers($filter);
}
/**
@@ -352,7 +352,6 @@ class Wizard extends LDAPUtility {
*/
public function fetchGroups($dbKey, $confKey) {
$obclasses = array('posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames');
- $ldapAccess = $this->getAccess();
$filterParts = array();
foreach($obclasses as $obclass) {
@@ -361,15 +360,15 @@ class Wizard extends LDAPUtility {
//we filter for everything
//- that looks like a group and
//- has the group display name set
- $filter = $ldapAccess->combineFilterWithOr($filterParts);
- $filter = $ldapAccess->combineFilterWithAnd(array($filter, 'cn=*'));
+ $filter = $this->access->combineFilterWithOr($filterParts);
+ $filter = $this->access->combineFilterWithAnd(array($filter, 'cn=*'));
$groupNames = array();
$groupEntries = array();
$limit = 400;
$offset = 0;
do {
- $result = $ldapAccess->searchGroups($filter, array('cn','dn'), $limit, $offset);
+ $result = $this->access->searchGroups($filter, array('cn'), $limit, $offset);
foreach($result as $item) {
$groupNames[] = $item['cn'];
$groupEntries[] = $item;
@@ -1169,27 +1168,6 @@ class Wizard extends LDAPUtility {
}
/**
- * creates and returns an Access instance
- * @return \OCA\user_ldap\lib\Access
- */
- private function getAccess() {
- $con = new Connection($this->ldap, '', null);
- $con->setConfiguration($this->configuration->getConfiguration());
- $con->ldapConfigurationActive = true;
- $con->setIgnoreValidation(true);
-
- $userManager = new user\Manager(
- \OC::$server->getConfig(),
- new FilesystemHelper(),
- new LogWrapper(),
- \OC::$server->getAvatarManager(),
- new \OCP\Image());
-
- $ldapAccess = new Access($con, $this->ldap, $userManager);
- return $ldapAccess;
- }
-
- /**
* @return bool|mixed
*/
private function getConnection() {
diff --git a/apps/user_ldap/tests/wizard.php b/apps/user_ldap/tests/wizard.php
index 50461432c42..fcf4d71087f 100644
--- a/apps/user_ldap/tests/wizard.php
+++ b/apps/user_ldap/tests/wizard.php
@@ -46,13 +46,24 @@ class Test_Wizard extends \PHPUnit_Framework_TestCase {
static $conMethods;
if(is_null($conMethods)) {
- $conMethods = get_class_methods('\OCA\user_ldap\lib\Configuration');
+ $confMethods = get_class_methods('\OCA\user_ldap\lib\Configuration');
+ $connMethods = get_class_methods('\OCA\user_ldap\lib\Connection');
+ $accMethods = get_class_methods('\OCA\user_ldap\lib\Access');
}
$lw = $this->getMock('\OCA\user_ldap\lib\ILDAPWrapper');
$conf = $this->getMock('\OCA\user_ldap\lib\Configuration',
- $conMethods,
+ $confMethods,
array($lw, null, null));
- return array(new Wizard($conf, $lw), $conf, $lw);
+
+ $connector = $this->getMock('\OCA\user_ldap\lib\Connection',
+ $connMethods, array($lw, null, null));
+ $um = $this->getMockBuilder('\OCA\user_ldap\lib\user\Manager')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $access = $this->getMock('\OCA\user_ldap\lib\Access',
+ $accMethods, array($connector, $lw, $um));
+
+ return array(new Wizard($conf, $lw, $access), $conf, $lw);
}
private function prepareLdapWrapperForConnections(&$ldap) {