mirror of
https://github.com/nextcloud/server.git
synced 2026-06-12 10:10:49 -04:00
remove Access as hard dependency, inject it instead
This commit is contained in:
parent
baa49cd58a
commit
441c600c90
3 changed files with 41 additions and 37 deletions
|
|
@ -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':
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -1168,27 +1167,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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue