@@ -33,39 +33,39 @@ |
||
| 33 | 33 | use Symfony\Component\Console\Output\OutputInterface; |
| 34 | 34 | |
| 35 | 35 | class CreateEmptyConfig extends Command { |
| 36 | - /** @var \OCA\User_LDAP\Helper */ |
|
| 37 | - protected $helper; |
|
| 36 | + /** @var \OCA\User_LDAP\Helper */ |
|
| 37 | + protected $helper; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param Helper $helper |
|
| 41 | - */ |
|
| 42 | - public function __construct(Helper $helper) { |
|
| 43 | - $this->helper = $helper; |
|
| 44 | - parent::__construct(); |
|
| 45 | - } |
|
| 39 | + /** |
|
| 40 | + * @param Helper $helper |
|
| 41 | + */ |
|
| 42 | + public function __construct(Helper $helper) { |
|
| 43 | + $this->helper = $helper; |
|
| 44 | + parent::__construct(); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - protected function configure() { |
|
| 48 | - $this |
|
| 49 | - ->setName('ldap:create-empty-config') |
|
| 50 | - ->setDescription('creates an empty LDAP configuration') |
|
| 51 | - ->addOption( |
|
| 52 | - 'only-print-prefix', |
|
| 53 | - 'p', |
|
| 54 | - InputOption::VALUE_NONE, |
|
| 55 | - 'outputs only the prefix' |
|
| 56 | - ) |
|
| 57 | - ; |
|
| 58 | - } |
|
| 47 | + protected function configure() { |
|
| 48 | + $this |
|
| 49 | + ->setName('ldap:create-empty-config') |
|
| 50 | + ->setDescription('creates an empty LDAP configuration') |
|
| 51 | + ->addOption( |
|
| 52 | + 'only-print-prefix', |
|
| 53 | + 'p', |
|
| 54 | + InputOption::VALUE_NONE, |
|
| 55 | + 'outputs only the prefix' |
|
| 56 | + ) |
|
| 57 | + ; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 61 | - $configPrefix = $this->helper->getNextServerConfigurationPrefix(); |
|
| 62 | - $configHolder = new Configuration($configPrefix); |
|
| 63 | - $configHolder->saveConfiguration(); |
|
| 60 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 61 | + $configPrefix = $this->helper->getNextServerConfigurationPrefix(); |
|
| 62 | + $configHolder = new Configuration($configPrefix); |
|
| 63 | + $configHolder->saveConfiguration(); |
|
| 64 | 64 | |
| 65 | - $prose = ''; |
|
| 66 | - if(!$input->getOption('only-print-prefix')) { |
|
| 67 | - $prose = 'Created new configuration with configID '; |
|
| 68 | - } |
|
| 69 | - $output->writeln($prose . "{$configPrefix}"); |
|
| 70 | - } |
|
| 65 | + $prose = ''; |
|
| 66 | + if(!$input->getOption('only-print-prefix')) { |
|
| 67 | + $prose = 'Created new configuration with configID '; |
|
| 68 | + } |
|
| 69 | + $output->writeln($prose . "{$configPrefix}"); |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -63,9 +63,9 @@ |
||
| 63 | 63 | $configHolder->saveConfiguration(); |
| 64 | 64 | |
| 65 | 65 | $prose = ''; |
| 66 | - if(!$input->getOption('only-print-prefix')) { |
|
| 66 | + if (!$input->getOption('only-print-prefix')) { |
|
| 67 | 67 | $prose = 'Created new configuration with configID '; |
| 68 | 68 | } |
| 69 | - $output->writeln($prose . "{$configPrefix}"); |
|
| 69 | + $output->writeln($prose."{$configPrefix}"); |
|
| 70 | 70 | } |
| 71 | 71 | } |
@@ -35,77 +35,77 @@ |
||
| 35 | 35 | use OCA\User_LDAP\Configuration; |
| 36 | 36 | |
| 37 | 37 | class ShowConfig extends Command { |
| 38 | - /** @var \OCA\User_LDAP\Helper */ |
|
| 39 | - protected $helper; |
|
| 38 | + /** @var \OCA\User_LDAP\Helper */ |
|
| 39 | + protected $helper; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param Helper $helper |
|
| 43 | - */ |
|
| 44 | - public function __construct(Helper $helper) { |
|
| 45 | - $this->helper = $helper; |
|
| 46 | - parent::__construct(); |
|
| 47 | - } |
|
| 41 | + /** |
|
| 42 | + * @param Helper $helper |
|
| 43 | + */ |
|
| 44 | + public function __construct(Helper $helper) { |
|
| 45 | + $this->helper = $helper; |
|
| 46 | + parent::__construct(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - protected function configure() { |
|
| 50 | - $this |
|
| 51 | - ->setName('ldap:show-config') |
|
| 52 | - ->setDescription('shows the LDAP configuration') |
|
| 53 | - ->addArgument( |
|
| 54 | - 'configID', |
|
| 55 | - InputArgument::OPTIONAL, |
|
| 56 | - 'will show the configuration of the specified id' |
|
| 57 | - ) |
|
| 58 | - ->addOption( |
|
| 59 | - 'show-password', |
|
| 60 | - null, |
|
| 61 | - InputOption::VALUE_NONE, |
|
| 62 | - 'show ldap bind password' |
|
| 63 | - ) |
|
| 64 | - ; |
|
| 65 | - } |
|
| 49 | + protected function configure() { |
|
| 50 | + $this |
|
| 51 | + ->setName('ldap:show-config') |
|
| 52 | + ->setDescription('shows the LDAP configuration') |
|
| 53 | + ->addArgument( |
|
| 54 | + 'configID', |
|
| 55 | + InputArgument::OPTIONAL, |
|
| 56 | + 'will show the configuration of the specified id' |
|
| 57 | + ) |
|
| 58 | + ->addOption( |
|
| 59 | + 'show-password', |
|
| 60 | + null, |
|
| 61 | + InputOption::VALUE_NONE, |
|
| 62 | + 'show ldap bind password' |
|
| 63 | + ) |
|
| 64 | + ; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 68 | - $availableConfigs = $this->helper->getServerConfigurationPrefixes(); |
|
| 69 | - $configID = $input->getArgument('configID'); |
|
| 70 | - if(!is_null($configID)) { |
|
| 71 | - $configIDs[] = $configID; |
|
| 72 | - if(!in_array($configIDs[0], $availableConfigs)) { |
|
| 73 | - $output->writeln("Invalid configID"); |
|
| 74 | - return; |
|
| 75 | - } |
|
| 76 | - } else { |
|
| 77 | - $configIDs = $availableConfigs; |
|
| 78 | - } |
|
| 67 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 68 | + $availableConfigs = $this->helper->getServerConfigurationPrefixes(); |
|
| 69 | + $configID = $input->getArgument('configID'); |
|
| 70 | + if(!is_null($configID)) { |
|
| 71 | + $configIDs[] = $configID; |
|
| 72 | + if(!in_array($configIDs[0], $availableConfigs)) { |
|
| 73 | + $output->writeln("Invalid configID"); |
|
| 74 | + return; |
|
| 75 | + } |
|
| 76 | + } else { |
|
| 77 | + $configIDs = $availableConfigs; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - $this->renderConfigs($configIDs, $output, $input->getOption('show-password')); |
|
| 81 | - } |
|
| 80 | + $this->renderConfigs($configIDs, $output, $input->getOption('show-password')); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * prints the LDAP configuration(s) |
|
| 85 | - * @param string[] configID(s) |
|
| 86 | - * @param OutputInterface $output |
|
| 87 | - * @param bool $withPassword Set to TRUE to show plaintext passwords in output |
|
| 88 | - */ |
|
| 89 | - protected function renderConfigs($configIDs, $output, $withPassword) { |
|
| 90 | - foreach($configIDs as $id) { |
|
| 91 | - $configHolder = new Configuration($id); |
|
| 92 | - $configuration = $configHolder->getConfiguration(); |
|
| 93 | - ksort($configuration); |
|
| 83 | + /** |
|
| 84 | + * prints the LDAP configuration(s) |
|
| 85 | + * @param string[] configID(s) |
|
| 86 | + * @param OutputInterface $output |
|
| 87 | + * @param bool $withPassword Set to TRUE to show plaintext passwords in output |
|
| 88 | + */ |
|
| 89 | + protected function renderConfigs($configIDs, $output, $withPassword) { |
|
| 90 | + foreach($configIDs as $id) { |
|
| 91 | + $configHolder = new Configuration($id); |
|
| 92 | + $configuration = $configHolder->getConfiguration(); |
|
| 93 | + ksort($configuration); |
|
| 94 | 94 | |
| 95 | - $table = new Table($output); |
|
| 96 | - $table->setHeaders(array('Configuration', $id)); |
|
| 97 | - $rows = array(); |
|
| 98 | - foreach($configuration as $key => $value) { |
|
| 99 | - if($key === 'ldapAgentPassword' && !$withPassword) { |
|
| 100 | - $value = '***'; |
|
| 101 | - } |
|
| 102 | - if(is_array($value)) { |
|
| 103 | - $value = implode(';', $value); |
|
| 104 | - } |
|
| 105 | - $rows[] = array($key, $value); |
|
| 106 | - } |
|
| 107 | - $table->setRows($rows); |
|
| 108 | - $table->render($output); |
|
| 109 | - } |
|
| 110 | - } |
|
| 95 | + $table = new Table($output); |
|
| 96 | + $table->setHeaders(array('Configuration', $id)); |
|
| 97 | + $rows = array(); |
|
| 98 | + foreach($configuration as $key => $value) { |
|
| 99 | + if($key === 'ldapAgentPassword' && !$withPassword) { |
|
| 100 | + $value = '***'; |
|
| 101 | + } |
|
| 102 | + if(is_array($value)) { |
|
| 103 | + $value = implode(';', $value); |
|
| 104 | + } |
|
| 105 | + $rows[] = array($key, $value); |
|
| 106 | + } |
|
| 107 | + $table->setRows($rows); |
|
| 108 | + $table->render($output); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | 111 | } |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 68 | 68 | $availableConfigs = $this->helper->getServerConfigurationPrefixes(); |
| 69 | 69 | $configID = $input->getArgument('configID'); |
| 70 | - if(!is_null($configID)) { |
|
| 70 | + if (!is_null($configID)) { |
|
| 71 | 71 | $configIDs[] = $configID; |
| 72 | - if(!in_array($configIDs[0], $availableConfigs)) { |
|
| 72 | + if (!in_array($configIDs[0], $availableConfigs)) { |
|
| 73 | 73 | $output->writeln("Invalid configID"); |
| 74 | 74 | return; |
| 75 | 75 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param bool $withPassword Set to TRUE to show plaintext passwords in output |
| 88 | 88 | */ |
| 89 | 89 | protected function renderConfigs($configIDs, $output, $withPassword) { |
| 90 | - foreach($configIDs as $id) { |
|
| 90 | + foreach ($configIDs as $id) { |
|
| 91 | 91 | $configHolder = new Configuration($id); |
| 92 | 92 | $configuration = $configHolder->getConfiguration(); |
| 93 | 93 | ksort($configuration); |
@@ -95,11 +95,11 @@ discard block |
||
| 95 | 95 | $table = new Table($output); |
| 96 | 96 | $table->setHeaders(array('Configuration', $id)); |
| 97 | 97 | $rows = array(); |
| 98 | - foreach($configuration as $key => $value) { |
|
| 99 | - if($key === 'ldapAgentPassword' && !$withPassword) { |
|
| 98 | + foreach ($configuration as $key => $value) { |
|
| 99 | + if ($key === 'ldapAgentPassword' && !$withPassword) { |
|
| 100 | 100 | $value = '***'; |
| 101 | 101 | } |
| 102 | - if(is_array($value)) { |
|
| 102 | + if (is_array($value)) { |
|
| 103 | 103 | $value = implode(';', $value); |
| 104 | 104 | } |
| 105 | 105 | $rows[] = array($key, $value); |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | public function __construct($configPrefix, $autoRead = true) { |
| 103 | 103 | $this->configPrefix = $configPrefix; |
| 104 | - if($autoRead) { |
|
| 104 | + if ($autoRead) { |
|
| 105 | 105 | $this->readConfiguration(); |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @return mixed|null |
| 112 | 112 | */ |
| 113 | 113 | public function __get($name) { |
| 114 | - if(isset($this->config[$name])) { |
|
| 114 | + if (isset($this->config[$name])) { |
|
| 115 | 115 | return $this->config[$name]; |
| 116 | 116 | } |
| 117 | 117 | return null; |
@@ -142,22 +142,22 @@ discard block |
||
| 142 | 142 | * @return false|null |
| 143 | 143 | */ |
| 144 | 144 | public function setConfiguration($config, &$applied = null) { |
| 145 | - if(!is_array($config)) { |
|
| 145 | + if (!is_array($config)) { |
|
| 146 | 146 | return false; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | $cta = $this->getConfigTranslationArray(); |
| 150 | - foreach($config as $inputKey => $val) { |
|
| 151 | - if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
| 150 | + foreach ($config as $inputKey => $val) { |
|
| 151 | + if (strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
| 152 | 152 | $key = $cta[$inputKey]; |
| 153 | - } elseif(array_key_exists($inputKey, $this->config)) { |
|
| 153 | + } elseif (array_key_exists($inputKey, $this->config)) { |
|
| 154 | 154 | $key = $inputKey; |
| 155 | 155 | } else { |
| 156 | 156 | continue; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | $setMethod = 'setValue'; |
| 160 | - switch($key) { |
|
| 160 | + switch ($key) { |
|
| 161 | 161 | case 'ldapAgentPassword': |
| 162 | 162 | $setMethod = 'setRawValue'; |
| 163 | 163 | break; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | break; |
| 182 | 182 | } |
| 183 | 183 | $this->$setMethod($key, $val); |
| 184 | - if(is_array($applied)) { |
|
| 184 | + if (is_array($applied)) { |
|
| 185 | 185 | $applied[] = $inputKey; |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -189,15 +189,15 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | public function readConfiguration() { |
| 192 | - if(!$this->configRead && !is_null($this->configPrefix)) { |
|
| 192 | + if (!$this->configRead && !is_null($this->configPrefix)) { |
|
| 193 | 193 | $cta = array_flip($this->getConfigTranslationArray()); |
| 194 | - foreach($this->config as $key => $val) { |
|
| 195 | - if(!isset($cta[$key])) { |
|
| 194 | + foreach ($this->config as $key => $val) { |
|
| 195 | + if (!isset($cta[$key])) { |
|
| 196 | 196 | //some are determined |
| 197 | 197 | continue; |
| 198 | 198 | } |
| 199 | 199 | $dbKey = $cta[$key]; |
| 200 | - switch($key) { |
|
| 200 | + switch ($key) { |
|
| 201 | 201 | case 'ldapBase': |
| 202 | 202 | case 'ldapBaseUsers': |
| 203 | 203 | case 'ldapBaseGroups': |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | public function saveConfiguration() { |
| 242 | 242 | $cta = array_flip($this->getConfigTranslationArray()); |
| 243 | - foreach($this->config as $key => $value) { |
|
| 243 | + foreach ($this->config as $key => $value) { |
|
| 244 | 244 | switch ($key) { |
| 245 | 245 | case 'ldapAgentPassword': |
| 246 | 246 | $value = base64_encode($value); |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | case 'ldapGroupFilterObjectclass': |
| 256 | 256 | case 'ldapGroupFilterGroups': |
| 257 | 257 | case 'ldapLoginFilterAttributes': |
| 258 | - if(is_array($value)) { |
|
| 258 | + if (is_array($value)) { |
|
| 259 | 259 | $value = implode("\n", $value); |
| 260 | 260 | } |
| 261 | 261 | break; |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | case 'ldapUuidGroupAttribute': |
| 267 | 267 | continue 2; |
| 268 | 268 | } |
| 269 | - if(is_null($value)) { |
|
| 269 | + if (is_null($value)) { |
|
| 270 | 270 | $value = ''; |
| 271 | 271 | } |
| 272 | 272 | $this->saveValue($cta[$key], $value); |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | protected function getMultiLine($varName) { |
| 281 | 281 | $value = $this->getValue($varName); |
| 282 | - if(empty($value)) { |
|
| 282 | + if (empty($value)) { |
|
| 283 | 283 | $value = ''; |
| 284 | 284 | } else { |
| 285 | 285 | $value = preg_split('/\r\n|\r|\n/', $value); |
@@ -295,21 +295,21 @@ discard block |
||
| 295 | 295 | * @param array|string $value to set |
| 296 | 296 | */ |
| 297 | 297 | protected function setMultiLine($varName, $value) { |
| 298 | - if(empty($value)) { |
|
| 298 | + if (empty($value)) { |
|
| 299 | 299 | $value = ''; |
| 300 | 300 | } else if (!is_array($value)) { |
| 301 | 301 | $value = preg_split('/\r\n|\r|\n|;/', $value); |
| 302 | - if($value === false) { |
|
| 302 | + if ($value === false) { |
|
| 303 | 303 | $value = ''; |
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - if(!is_array($value)) { |
|
| 307 | + if (!is_array($value)) { |
|
| 308 | 308 | $finalValue = trim($value); |
| 309 | 309 | } else { |
| 310 | 310 | $finalValue = []; |
| 311 | - foreach($value as $key => $val) { |
|
| 312 | - if(is_string($val)) { |
|
| 311 | + foreach ($value as $key => $val) { |
|
| 312 | + if (is_string($val)) { |
|
| 313 | 313 | $val = trim($val); |
| 314 | 314 | if ($val !== '') { |
| 315 | 315 | //accidental line breaks are not wanted and can cause |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | */ |
| 357 | 357 | protected function getValue($varName) { |
| 358 | 358 | static $defaults; |
| 359 | - if(is_null($defaults)) { |
|
| 359 | + if (is_null($defaults)) { |
|
| 360 | 360 | $defaults = $this->getDefaults(); |
| 361 | 361 | } |
| 362 | 362 | return \OCP\Config::getAppValue('user_ldap', |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | * @param mixed $value to set |
| 372 | 372 | */ |
| 373 | 373 | protected function setValue($varName, $value) { |
| 374 | - if(is_string($value)) { |
|
| 374 | + if (is_string($value)) { |
|
| 375 | 375 | $value = trim($value); |
| 376 | 376 | } |
| 377 | 377 | $this->config[$varName] = $value; |
@@ -36,492 +36,492 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class Configuration { |
| 38 | 38 | |
| 39 | - protected $configPrefix = null; |
|
| 40 | - protected $configRead = false; |
|
| 39 | + protected $configPrefix = null; |
|
| 40 | + protected $configRead = false; |
|
| 41 | 41 | |
| 42 | - //settings |
|
| 43 | - protected $config = array( |
|
| 44 | - 'ldapHost' => null, |
|
| 45 | - 'ldapPort' => null, |
|
| 46 | - 'ldapBackupHost' => null, |
|
| 47 | - 'ldapBackupPort' => null, |
|
| 48 | - 'ldapBase' => null, |
|
| 49 | - 'ldapBaseUsers' => null, |
|
| 50 | - 'ldapBaseGroups' => null, |
|
| 51 | - 'ldapAgentName' => null, |
|
| 52 | - 'ldapAgentPassword' => null, |
|
| 53 | - 'ldapTLS' => null, |
|
| 54 | - 'turnOffCertCheck' => null, |
|
| 55 | - 'ldapIgnoreNamingRules' => null, |
|
| 56 | - 'ldapUserDisplayName' => null, |
|
| 57 | - 'ldapUserDisplayName2' => null, |
|
| 58 | - 'ldapGidNumber' => null, |
|
| 59 | - 'ldapUserFilterObjectclass' => null, |
|
| 60 | - 'ldapUserFilterGroups' => null, |
|
| 61 | - 'ldapUserFilter' => null, |
|
| 62 | - 'ldapUserFilterMode' => null, |
|
| 63 | - 'ldapGroupFilter' => null, |
|
| 64 | - 'ldapGroupFilterMode' => null, |
|
| 65 | - 'ldapGroupFilterObjectclass' => null, |
|
| 66 | - 'ldapGroupFilterGroups' => null, |
|
| 67 | - 'ldapGroupDisplayName' => null, |
|
| 68 | - 'ldapGroupMemberAssocAttr' => null, |
|
| 69 | - 'ldapLoginFilter' => null, |
|
| 70 | - 'ldapLoginFilterMode' => null, |
|
| 71 | - 'ldapLoginFilterEmail' => null, |
|
| 72 | - 'ldapLoginFilterUsername' => null, |
|
| 73 | - 'ldapLoginFilterAttributes' => null, |
|
| 74 | - 'ldapQuotaAttribute' => null, |
|
| 75 | - 'ldapQuotaDefault' => null, |
|
| 76 | - 'ldapEmailAttribute' => null, |
|
| 77 | - 'ldapCacheTTL' => null, |
|
| 78 | - 'ldapUuidUserAttribute' => 'auto', |
|
| 79 | - 'ldapUuidGroupAttribute' => 'auto', |
|
| 80 | - 'ldapOverrideMainServer' => false, |
|
| 81 | - 'ldapConfigurationActive' => false, |
|
| 82 | - 'ldapAttributesForUserSearch' => null, |
|
| 83 | - 'ldapAttributesForGroupSearch' => null, |
|
| 84 | - 'ldapExperiencedAdmin' => false, |
|
| 85 | - 'homeFolderNamingRule' => null, |
|
| 86 | - 'hasPagedResultSupport' => false, |
|
| 87 | - 'hasMemberOfFilterSupport' => false, |
|
| 88 | - 'useMemberOfToDetectMembership' => true, |
|
| 89 | - 'ldapExpertUsernameAttr' => null, |
|
| 90 | - 'ldapExpertUUIDUserAttr' => null, |
|
| 91 | - 'ldapExpertUUIDGroupAttr' => null, |
|
| 92 | - 'lastJpegPhotoLookup' => null, |
|
| 93 | - 'ldapNestedGroups' => false, |
|
| 94 | - 'ldapPagingSize' => null, |
|
| 95 | - 'turnOnPasswordChange' => false, |
|
| 96 | - 'ldapDynamicGroupMemberURL' => null, |
|
| 97 | - 'ldapDefaultPPolicyDN' => null, |
|
| 98 | - ); |
|
| 42 | + //settings |
|
| 43 | + protected $config = array( |
|
| 44 | + 'ldapHost' => null, |
|
| 45 | + 'ldapPort' => null, |
|
| 46 | + 'ldapBackupHost' => null, |
|
| 47 | + 'ldapBackupPort' => null, |
|
| 48 | + 'ldapBase' => null, |
|
| 49 | + 'ldapBaseUsers' => null, |
|
| 50 | + 'ldapBaseGroups' => null, |
|
| 51 | + 'ldapAgentName' => null, |
|
| 52 | + 'ldapAgentPassword' => null, |
|
| 53 | + 'ldapTLS' => null, |
|
| 54 | + 'turnOffCertCheck' => null, |
|
| 55 | + 'ldapIgnoreNamingRules' => null, |
|
| 56 | + 'ldapUserDisplayName' => null, |
|
| 57 | + 'ldapUserDisplayName2' => null, |
|
| 58 | + 'ldapGidNumber' => null, |
|
| 59 | + 'ldapUserFilterObjectclass' => null, |
|
| 60 | + 'ldapUserFilterGroups' => null, |
|
| 61 | + 'ldapUserFilter' => null, |
|
| 62 | + 'ldapUserFilterMode' => null, |
|
| 63 | + 'ldapGroupFilter' => null, |
|
| 64 | + 'ldapGroupFilterMode' => null, |
|
| 65 | + 'ldapGroupFilterObjectclass' => null, |
|
| 66 | + 'ldapGroupFilterGroups' => null, |
|
| 67 | + 'ldapGroupDisplayName' => null, |
|
| 68 | + 'ldapGroupMemberAssocAttr' => null, |
|
| 69 | + 'ldapLoginFilter' => null, |
|
| 70 | + 'ldapLoginFilterMode' => null, |
|
| 71 | + 'ldapLoginFilterEmail' => null, |
|
| 72 | + 'ldapLoginFilterUsername' => null, |
|
| 73 | + 'ldapLoginFilterAttributes' => null, |
|
| 74 | + 'ldapQuotaAttribute' => null, |
|
| 75 | + 'ldapQuotaDefault' => null, |
|
| 76 | + 'ldapEmailAttribute' => null, |
|
| 77 | + 'ldapCacheTTL' => null, |
|
| 78 | + 'ldapUuidUserAttribute' => 'auto', |
|
| 79 | + 'ldapUuidGroupAttribute' => 'auto', |
|
| 80 | + 'ldapOverrideMainServer' => false, |
|
| 81 | + 'ldapConfigurationActive' => false, |
|
| 82 | + 'ldapAttributesForUserSearch' => null, |
|
| 83 | + 'ldapAttributesForGroupSearch' => null, |
|
| 84 | + 'ldapExperiencedAdmin' => false, |
|
| 85 | + 'homeFolderNamingRule' => null, |
|
| 86 | + 'hasPagedResultSupport' => false, |
|
| 87 | + 'hasMemberOfFilterSupport' => false, |
|
| 88 | + 'useMemberOfToDetectMembership' => true, |
|
| 89 | + 'ldapExpertUsernameAttr' => null, |
|
| 90 | + 'ldapExpertUUIDUserAttr' => null, |
|
| 91 | + 'ldapExpertUUIDGroupAttr' => null, |
|
| 92 | + 'lastJpegPhotoLookup' => null, |
|
| 93 | + 'ldapNestedGroups' => false, |
|
| 94 | + 'ldapPagingSize' => null, |
|
| 95 | + 'turnOnPasswordChange' => false, |
|
| 96 | + 'ldapDynamicGroupMemberURL' => null, |
|
| 97 | + 'ldapDefaultPPolicyDN' => null, |
|
| 98 | + ); |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @param string $configPrefix |
|
| 102 | - * @param bool $autoRead |
|
| 103 | - */ |
|
| 104 | - public function __construct($configPrefix, $autoRead = true) { |
|
| 105 | - $this->configPrefix = $configPrefix; |
|
| 106 | - if($autoRead) { |
|
| 107 | - $this->readConfiguration(); |
|
| 108 | - } |
|
| 109 | - } |
|
| 100 | + /** |
|
| 101 | + * @param string $configPrefix |
|
| 102 | + * @param bool $autoRead |
|
| 103 | + */ |
|
| 104 | + public function __construct($configPrefix, $autoRead = true) { |
|
| 105 | + $this->configPrefix = $configPrefix; |
|
| 106 | + if($autoRead) { |
|
| 107 | + $this->readConfiguration(); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * @param string $name |
|
| 113 | - * @return mixed|null |
|
| 114 | - */ |
|
| 115 | - public function __get($name) { |
|
| 116 | - if(isset($this->config[$name])) { |
|
| 117 | - return $this->config[$name]; |
|
| 118 | - } |
|
| 119 | - return null; |
|
| 120 | - } |
|
| 111 | + /** |
|
| 112 | + * @param string $name |
|
| 113 | + * @return mixed|null |
|
| 114 | + */ |
|
| 115 | + public function __get($name) { |
|
| 116 | + if(isset($this->config[$name])) { |
|
| 117 | + return $this->config[$name]; |
|
| 118 | + } |
|
| 119 | + return null; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * @param string $name |
|
| 124 | - * @param mixed $value |
|
| 125 | - */ |
|
| 126 | - public function __set($name, $value) { |
|
| 127 | - $this->setConfiguration(array($name => $value)); |
|
| 128 | - } |
|
| 122 | + /** |
|
| 123 | + * @param string $name |
|
| 124 | + * @param mixed $value |
|
| 125 | + */ |
|
| 126 | + public function __set($name, $value) { |
|
| 127 | + $this->setConfiguration(array($name => $value)); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * @return array |
|
| 132 | - */ |
|
| 133 | - public function getConfiguration() { |
|
| 134 | - return $this->config; |
|
| 135 | - } |
|
| 130 | + /** |
|
| 131 | + * @return array |
|
| 132 | + */ |
|
| 133 | + public function getConfiguration() { |
|
| 134 | + return $this->config; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * set LDAP configuration with values delivered by an array, not read |
|
| 139 | - * from configuration. It does not save the configuration! To do so, you |
|
| 140 | - * must call saveConfiguration afterwards. |
|
| 141 | - * @param array $config array that holds the config parameters in an associated |
|
| 142 | - * array |
|
| 143 | - * @param array &$applied optional; array where the set fields will be given to |
|
| 144 | - * @return false|null |
|
| 145 | - */ |
|
| 146 | - public function setConfiguration($config, &$applied = null) { |
|
| 147 | - if(!is_array($config)) { |
|
| 148 | - return false; |
|
| 149 | - } |
|
| 137 | + /** |
|
| 138 | + * set LDAP configuration with values delivered by an array, not read |
|
| 139 | + * from configuration. It does not save the configuration! To do so, you |
|
| 140 | + * must call saveConfiguration afterwards. |
|
| 141 | + * @param array $config array that holds the config parameters in an associated |
|
| 142 | + * array |
|
| 143 | + * @param array &$applied optional; array where the set fields will be given to |
|
| 144 | + * @return false|null |
|
| 145 | + */ |
|
| 146 | + public function setConfiguration($config, &$applied = null) { |
|
| 147 | + if(!is_array($config)) { |
|
| 148 | + return false; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - $cta = $this->getConfigTranslationArray(); |
|
| 152 | - foreach($config as $inputKey => $val) { |
|
| 153 | - if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
| 154 | - $key = $cta[$inputKey]; |
|
| 155 | - } elseif(array_key_exists($inputKey, $this->config)) { |
|
| 156 | - $key = $inputKey; |
|
| 157 | - } else { |
|
| 158 | - continue; |
|
| 159 | - } |
|
| 151 | + $cta = $this->getConfigTranslationArray(); |
|
| 152 | + foreach($config as $inputKey => $val) { |
|
| 153 | + if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
| 154 | + $key = $cta[$inputKey]; |
|
| 155 | + } elseif(array_key_exists($inputKey, $this->config)) { |
|
| 156 | + $key = $inputKey; |
|
| 157 | + } else { |
|
| 158 | + continue; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - $setMethod = 'setValue'; |
|
| 162 | - switch($key) { |
|
| 163 | - case 'ldapAgentPassword': |
|
| 164 | - $setMethod = 'setRawValue'; |
|
| 165 | - break; |
|
| 166 | - case 'homeFolderNamingRule': |
|
| 167 | - $trimmedVal = trim($val); |
|
| 168 | - if ($trimmedVal !== '' && strpos($val, 'attr:') === false) { |
|
| 169 | - $val = 'attr:'.$trimmedVal; |
|
| 170 | - } |
|
| 171 | - break; |
|
| 172 | - case 'ldapBase': |
|
| 173 | - case 'ldapBaseUsers': |
|
| 174 | - case 'ldapBaseGroups': |
|
| 175 | - case 'ldapAttributesForUserSearch': |
|
| 176 | - case 'ldapAttributesForGroupSearch': |
|
| 177 | - case 'ldapUserFilterObjectclass': |
|
| 178 | - case 'ldapUserFilterGroups': |
|
| 179 | - case 'ldapGroupFilterObjectclass': |
|
| 180 | - case 'ldapGroupFilterGroups': |
|
| 181 | - case 'ldapLoginFilterAttributes': |
|
| 182 | - $setMethod = 'setMultiLine'; |
|
| 183 | - break; |
|
| 184 | - } |
|
| 185 | - $this->$setMethod($key, $val); |
|
| 186 | - if(is_array($applied)) { |
|
| 187 | - $applied[] = $inputKey; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - return null; |
|
| 191 | - } |
|
| 161 | + $setMethod = 'setValue'; |
|
| 162 | + switch($key) { |
|
| 163 | + case 'ldapAgentPassword': |
|
| 164 | + $setMethod = 'setRawValue'; |
|
| 165 | + break; |
|
| 166 | + case 'homeFolderNamingRule': |
|
| 167 | + $trimmedVal = trim($val); |
|
| 168 | + if ($trimmedVal !== '' && strpos($val, 'attr:') === false) { |
|
| 169 | + $val = 'attr:'.$trimmedVal; |
|
| 170 | + } |
|
| 171 | + break; |
|
| 172 | + case 'ldapBase': |
|
| 173 | + case 'ldapBaseUsers': |
|
| 174 | + case 'ldapBaseGroups': |
|
| 175 | + case 'ldapAttributesForUserSearch': |
|
| 176 | + case 'ldapAttributesForGroupSearch': |
|
| 177 | + case 'ldapUserFilterObjectclass': |
|
| 178 | + case 'ldapUserFilterGroups': |
|
| 179 | + case 'ldapGroupFilterObjectclass': |
|
| 180 | + case 'ldapGroupFilterGroups': |
|
| 181 | + case 'ldapLoginFilterAttributes': |
|
| 182 | + $setMethod = 'setMultiLine'; |
|
| 183 | + break; |
|
| 184 | + } |
|
| 185 | + $this->$setMethod($key, $val); |
|
| 186 | + if(is_array($applied)) { |
|
| 187 | + $applied[] = $inputKey; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + return null; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - public function readConfiguration() { |
|
| 194 | - if(!$this->configRead && !is_null($this->configPrefix)) { |
|
| 195 | - $cta = array_flip($this->getConfigTranslationArray()); |
|
| 196 | - foreach($this->config as $key => $val) { |
|
| 197 | - if(!isset($cta[$key])) { |
|
| 198 | - //some are determined |
|
| 199 | - continue; |
|
| 200 | - } |
|
| 201 | - $dbKey = $cta[$key]; |
|
| 202 | - switch($key) { |
|
| 203 | - case 'ldapBase': |
|
| 204 | - case 'ldapBaseUsers': |
|
| 205 | - case 'ldapBaseGroups': |
|
| 206 | - case 'ldapAttributesForUserSearch': |
|
| 207 | - case 'ldapAttributesForGroupSearch': |
|
| 208 | - case 'ldapUserFilterObjectclass': |
|
| 209 | - case 'ldapUserFilterGroups': |
|
| 210 | - case 'ldapGroupFilterObjectclass': |
|
| 211 | - case 'ldapGroupFilterGroups': |
|
| 212 | - case 'ldapLoginFilterAttributes': |
|
| 213 | - $readMethod = 'getMultiLine'; |
|
| 214 | - break; |
|
| 215 | - case 'ldapIgnoreNamingRules': |
|
| 216 | - $readMethod = 'getSystemValue'; |
|
| 217 | - $dbKey = $key; |
|
| 218 | - break; |
|
| 219 | - case 'ldapAgentPassword': |
|
| 220 | - $readMethod = 'getPwd'; |
|
| 221 | - break; |
|
| 222 | - case 'ldapUserDisplayName2': |
|
| 223 | - case 'ldapGroupDisplayName': |
|
| 224 | - $readMethod = 'getLcValue'; |
|
| 225 | - break; |
|
| 226 | - case 'ldapUserDisplayName': |
|
| 227 | - default: |
|
| 228 | - // user display name does not lower case because |
|
| 229 | - // we rely on an upper case N as indicator whether to |
|
| 230 | - // auto-detect it or not. FIXME |
|
| 231 | - $readMethod = 'getValue'; |
|
| 232 | - break; |
|
| 233 | - } |
|
| 234 | - $this->config[$key] = $this->$readMethod($dbKey); |
|
| 235 | - } |
|
| 236 | - $this->configRead = true; |
|
| 237 | - } |
|
| 238 | - } |
|
| 193 | + public function readConfiguration() { |
|
| 194 | + if(!$this->configRead && !is_null($this->configPrefix)) { |
|
| 195 | + $cta = array_flip($this->getConfigTranslationArray()); |
|
| 196 | + foreach($this->config as $key => $val) { |
|
| 197 | + if(!isset($cta[$key])) { |
|
| 198 | + //some are determined |
|
| 199 | + continue; |
|
| 200 | + } |
|
| 201 | + $dbKey = $cta[$key]; |
|
| 202 | + switch($key) { |
|
| 203 | + case 'ldapBase': |
|
| 204 | + case 'ldapBaseUsers': |
|
| 205 | + case 'ldapBaseGroups': |
|
| 206 | + case 'ldapAttributesForUserSearch': |
|
| 207 | + case 'ldapAttributesForGroupSearch': |
|
| 208 | + case 'ldapUserFilterObjectclass': |
|
| 209 | + case 'ldapUserFilterGroups': |
|
| 210 | + case 'ldapGroupFilterObjectclass': |
|
| 211 | + case 'ldapGroupFilterGroups': |
|
| 212 | + case 'ldapLoginFilterAttributes': |
|
| 213 | + $readMethod = 'getMultiLine'; |
|
| 214 | + break; |
|
| 215 | + case 'ldapIgnoreNamingRules': |
|
| 216 | + $readMethod = 'getSystemValue'; |
|
| 217 | + $dbKey = $key; |
|
| 218 | + break; |
|
| 219 | + case 'ldapAgentPassword': |
|
| 220 | + $readMethod = 'getPwd'; |
|
| 221 | + break; |
|
| 222 | + case 'ldapUserDisplayName2': |
|
| 223 | + case 'ldapGroupDisplayName': |
|
| 224 | + $readMethod = 'getLcValue'; |
|
| 225 | + break; |
|
| 226 | + case 'ldapUserDisplayName': |
|
| 227 | + default: |
|
| 228 | + // user display name does not lower case because |
|
| 229 | + // we rely on an upper case N as indicator whether to |
|
| 230 | + // auto-detect it or not. FIXME |
|
| 231 | + $readMethod = 'getValue'; |
|
| 232 | + break; |
|
| 233 | + } |
|
| 234 | + $this->config[$key] = $this->$readMethod($dbKey); |
|
| 235 | + } |
|
| 236 | + $this->configRead = true; |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * saves the current Configuration in the database |
|
| 242 | - */ |
|
| 243 | - public function saveConfiguration() { |
|
| 244 | - $cta = array_flip($this->getConfigTranslationArray()); |
|
| 245 | - foreach($this->config as $key => $value) { |
|
| 246 | - switch ($key) { |
|
| 247 | - case 'ldapAgentPassword': |
|
| 248 | - $value = base64_encode($value); |
|
| 249 | - break; |
|
| 250 | - case 'ldapBase': |
|
| 251 | - case 'ldapBaseUsers': |
|
| 252 | - case 'ldapBaseGroups': |
|
| 253 | - case 'ldapAttributesForUserSearch': |
|
| 254 | - case 'ldapAttributesForGroupSearch': |
|
| 255 | - case 'ldapUserFilterObjectclass': |
|
| 256 | - case 'ldapUserFilterGroups': |
|
| 257 | - case 'ldapGroupFilterObjectclass': |
|
| 258 | - case 'ldapGroupFilterGroups': |
|
| 259 | - case 'ldapLoginFilterAttributes': |
|
| 260 | - if(is_array($value)) { |
|
| 261 | - $value = implode("\n", $value); |
|
| 262 | - } |
|
| 263 | - break; |
|
| 264 | - //following options are not stored but detected, skip them |
|
| 265 | - case 'ldapIgnoreNamingRules': |
|
| 266 | - case 'hasPagedResultSupport': |
|
| 267 | - case 'ldapUuidUserAttribute': |
|
| 268 | - case 'ldapUuidGroupAttribute': |
|
| 269 | - continue 2; |
|
| 270 | - } |
|
| 271 | - if(is_null($value)) { |
|
| 272 | - $value = ''; |
|
| 273 | - } |
|
| 274 | - $this->saveValue($cta[$key], $value); |
|
| 275 | - } |
|
| 276 | - } |
|
| 240 | + /** |
|
| 241 | + * saves the current Configuration in the database |
|
| 242 | + */ |
|
| 243 | + public function saveConfiguration() { |
|
| 244 | + $cta = array_flip($this->getConfigTranslationArray()); |
|
| 245 | + foreach($this->config as $key => $value) { |
|
| 246 | + switch ($key) { |
|
| 247 | + case 'ldapAgentPassword': |
|
| 248 | + $value = base64_encode($value); |
|
| 249 | + break; |
|
| 250 | + case 'ldapBase': |
|
| 251 | + case 'ldapBaseUsers': |
|
| 252 | + case 'ldapBaseGroups': |
|
| 253 | + case 'ldapAttributesForUserSearch': |
|
| 254 | + case 'ldapAttributesForGroupSearch': |
|
| 255 | + case 'ldapUserFilterObjectclass': |
|
| 256 | + case 'ldapUserFilterGroups': |
|
| 257 | + case 'ldapGroupFilterObjectclass': |
|
| 258 | + case 'ldapGroupFilterGroups': |
|
| 259 | + case 'ldapLoginFilterAttributes': |
|
| 260 | + if(is_array($value)) { |
|
| 261 | + $value = implode("\n", $value); |
|
| 262 | + } |
|
| 263 | + break; |
|
| 264 | + //following options are not stored but detected, skip them |
|
| 265 | + case 'ldapIgnoreNamingRules': |
|
| 266 | + case 'hasPagedResultSupport': |
|
| 267 | + case 'ldapUuidUserAttribute': |
|
| 268 | + case 'ldapUuidGroupAttribute': |
|
| 269 | + continue 2; |
|
| 270 | + } |
|
| 271 | + if(is_null($value)) { |
|
| 272 | + $value = ''; |
|
| 273 | + } |
|
| 274 | + $this->saveValue($cta[$key], $value); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - /** |
|
| 279 | - * @param string $varName |
|
| 280 | - * @return array|string |
|
| 281 | - */ |
|
| 282 | - protected function getMultiLine($varName) { |
|
| 283 | - $value = $this->getValue($varName); |
|
| 284 | - if(empty($value)) { |
|
| 285 | - $value = ''; |
|
| 286 | - } else { |
|
| 287 | - $value = preg_split('/\r\n|\r|\n/', $value); |
|
| 288 | - } |
|
| 278 | + /** |
|
| 279 | + * @param string $varName |
|
| 280 | + * @return array|string |
|
| 281 | + */ |
|
| 282 | + protected function getMultiLine($varName) { |
|
| 283 | + $value = $this->getValue($varName); |
|
| 284 | + if(empty($value)) { |
|
| 285 | + $value = ''; |
|
| 286 | + } else { |
|
| 287 | + $value = preg_split('/\r\n|\r|\n/', $value); |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - return $value; |
|
| 291 | - } |
|
| 290 | + return $value; |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * Sets multi-line values as arrays |
|
| 295 | - * |
|
| 296 | - * @param string $varName name of config-key |
|
| 297 | - * @param array|string $value to set |
|
| 298 | - */ |
|
| 299 | - protected function setMultiLine($varName, $value) { |
|
| 300 | - if(empty($value)) { |
|
| 301 | - $value = ''; |
|
| 302 | - } else if (!is_array($value)) { |
|
| 303 | - $value = preg_split('/\r\n|\r|\n|;/', $value); |
|
| 304 | - if($value === false) { |
|
| 305 | - $value = ''; |
|
| 306 | - } |
|
| 307 | - } |
|
| 293 | + /** |
|
| 294 | + * Sets multi-line values as arrays |
|
| 295 | + * |
|
| 296 | + * @param string $varName name of config-key |
|
| 297 | + * @param array|string $value to set |
|
| 298 | + */ |
|
| 299 | + protected function setMultiLine($varName, $value) { |
|
| 300 | + if(empty($value)) { |
|
| 301 | + $value = ''; |
|
| 302 | + } else if (!is_array($value)) { |
|
| 303 | + $value = preg_split('/\r\n|\r|\n|;/', $value); |
|
| 304 | + if($value === false) { |
|
| 305 | + $value = ''; |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - if(!is_array($value)) { |
|
| 310 | - $finalValue = trim($value); |
|
| 311 | - } else { |
|
| 312 | - $finalValue = []; |
|
| 313 | - foreach($value as $key => $val) { |
|
| 314 | - if(is_string($val)) { |
|
| 315 | - $val = trim($val); |
|
| 316 | - if ($val !== '') { |
|
| 317 | - //accidental line breaks are not wanted and can cause |
|
| 318 | - // odd behaviour. Thus, away with them. |
|
| 319 | - $finalValue[] = $val; |
|
| 320 | - } |
|
| 321 | - } else { |
|
| 322 | - $finalValue[] = $val; |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - } |
|
| 309 | + if(!is_array($value)) { |
|
| 310 | + $finalValue = trim($value); |
|
| 311 | + } else { |
|
| 312 | + $finalValue = []; |
|
| 313 | + foreach($value as $key => $val) { |
|
| 314 | + if(is_string($val)) { |
|
| 315 | + $val = trim($val); |
|
| 316 | + if ($val !== '') { |
|
| 317 | + //accidental line breaks are not wanted and can cause |
|
| 318 | + // odd behaviour. Thus, away with them. |
|
| 319 | + $finalValue[] = $val; |
|
| 320 | + } |
|
| 321 | + } else { |
|
| 322 | + $finalValue[] = $val; |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - $this->setRawValue($varName, $finalValue); |
|
| 328 | - } |
|
| 327 | + $this->setRawValue($varName, $finalValue); |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - /** |
|
| 331 | - * @param string $varName |
|
| 332 | - * @return string |
|
| 333 | - */ |
|
| 334 | - protected function getPwd($varName) { |
|
| 335 | - return base64_decode($this->getValue($varName)); |
|
| 336 | - } |
|
| 330 | + /** |
|
| 331 | + * @param string $varName |
|
| 332 | + * @return string |
|
| 333 | + */ |
|
| 334 | + protected function getPwd($varName) { |
|
| 335 | + return base64_decode($this->getValue($varName)); |
|
| 336 | + } |
|
| 337 | 337 | |
| 338 | - /** |
|
| 339 | - * @param string $varName |
|
| 340 | - * @return string |
|
| 341 | - */ |
|
| 342 | - protected function getLcValue($varName) { |
|
| 343 | - return mb_strtolower($this->getValue($varName), 'UTF-8'); |
|
| 344 | - } |
|
| 338 | + /** |
|
| 339 | + * @param string $varName |
|
| 340 | + * @return string |
|
| 341 | + */ |
|
| 342 | + protected function getLcValue($varName) { |
|
| 343 | + return mb_strtolower($this->getValue($varName), 'UTF-8'); |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | - /** |
|
| 347 | - * @param string $varName |
|
| 348 | - * @return string |
|
| 349 | - */ |
|
| 350 | - protected function getSystemValue($varName) { |
|
| 351 | - //FIXME: if another system value is added, softcode the default value |
|
| 352 | - return \OC::$server->getConfig()->getSystemValue($varName, false); |
|
| 353 | - } |
|
| 346 | + /** |
|
| 347 | + * @param string $varName |
|
| 348 | + * @return string |
|
| 349 | + */ |
|
| 350 | + protected function getSystemValue($varName) { |
|
| 351 | + //FIXME: if another system value is added, softcode the default value |
|
| 352 | + return \OC::$server->getConfig()->getSystemValue($varName, false); |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - /** |
|
| 356 | - * @param string $varName |
|
| 357 | - * @return string |
|
| 358 | - */ |
|
| 359 | - protected function getValue($varName) { |
|
| 360 | - static $defaults; |
|
| 361 | - if(is_null($defaults)) { |
|
| 362 | - $defaults = $this->getDefaults(); |
|
| 363 | - } |
|
| 364 | - return \OCP\Config::getAppValue('user_ldap', |
|
| 365 | - $this->configPrefix.$varName, |
|
| 366 | - $defaults[$varName]); |
|
| 367 | - } |
|
| 355 | + /** |
|
| 356 | + * @param string $varName |
|
| 357 | + * @return string |
|
| 358 | + */ |
|
| 359 | + protected function getValue($varName) { |
|
| 360 | + static $defaults; |
|
| 361 | + if(is_null($defaults)) { |
|
| 362 | + $defaults = $this->getDefaults(); |
|
| 363 | + } |
|
| 364 | + return \OCP\Config::getAppValue('user_ldap', |
|
| 365 | + $this->configPrefix.$varName, |
|
| 366 | + $defaults[$varName]); |
|
| 367 | + } |
|
| 368 | 368 | |
| 369 | - /** |
|
| 370 | - * Sets a scalar value. |
|
| 371 | - * |
|
| 372 | - * @param string $varName name of config key |
|
| 373 | - * @param mixed $value to set |
|
| 374 | - */ |
|
| 375 | - protected function setValue($varName, $value) { |
|
| 376 | - if(is_string($value)) { |
|
| 377 | - $value = trim($value); |
|
| 378 | - } |
|
| 379 | - $this->config[$varName] = $value; |
|
| 380 | - } |
|
| 369 | + /** |
|
| 370 | + * Sets a scalar value. |
|
| 371 | + * |
|
| 372 | + * @param string $varName name of config key |
|
| 373 | + * @param mixed $value to set |
|
| 374 | + */ |
|
| 375 | + protected function setValue($varName, $value) { |
|
| 376 | + if(is_string($value)) { |
|
| 377 | + $value = trim($value); |
|
| 378 | + } |
|
| 379 | + $this->config[$varName] = $value; |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | - /** |
|
| 383 | - * Sets a scalar value without trimming. |
|
| 384 | - * |
|
| 385 | - * @param string $varName name of config key |
|
| 386 | - * @param mixed $value to set |
|
| 387 | - */ |
|
| 388 | - protected function setRawValue($varName, $value) { |
|
| 389 | - $this->config[$varName] = $value; |
|
| 390 | - } |
|
| 382 | + /** |
|
| 383 | + * Sets a scalar value without trimming. |
|
| 384 | + * |
|
| 385 | + * @param string $varName name of config key |
|
| 386 | + * @param mixed $value to set |
|
| 387 | + */ |
|
| 388 | + protected function setRawValue($varName, $value) { |
|
| 389 | + $this->config[$varName] = $value; |
|
| 390 | + } |
|
| 391 | 391 | |
| 392 | - /** |
|
| 393 | - * @param string $varName |
|
| 394 | - * @param string $value |
|
| 395 | - * @return bool |
|
| 396 | - */ |
|
| 397 | - protected function saveValue($varName, $value) { |
|
| 398 | - \OC::$server->getConfig()->setAppValue( |
|
| 399 | - 'user_ldap', |
|
| 400 | - $this->configPrefix.$varName, |
|
| 401 | - $value |
|
| 402 | - ); |
|
| 403 | - return true; |
|
| 404 | - } |
|
| 392 | + /** |
|
| 393 | + * @param string $varName |
|
| 394 | + * @param string $value |
|
| 395 | + * @return bool |
|
| 396 | + */ |
|
| 397 | + protected function saveValue($varName, $value) { |
|
| 398 | + \OC::$server->getConfig()->setAppValue( |
|
| 399 | + 'user_ldap', |
|
| 400 | + $this->configPrefix.$varName, |
|
| 401 | + $value |
|
| 402 | + ); |
|
| 403 | + return true; |
|
| 404 | + } |
|
| 405 | 405 | |
| 406 | - /** |
|
| 407 | - * @return array an associative array with the default values. Keys are correspond |
|
| 408 | - * to config-value entries in the database table |
|
| 409 | - */ |
|
| 410 | - public function getDefaults() { |
|
| 411 | - return array( |
|
| 412 | - 'ldap_host' => '', |
|
| 413 | - 'ldap_port' => '', |
|
| 414 | - 'ldap_backup_host' => '', |
|
| 415 | - 'ldap_backup_port' => '', |
|
| 416 | - 'ldap_override_main_server' => '', |
|
| 417 | - 'ldap_dn' => '', |
|
| 418 | - 'ldap_agent_password' => '', |
|
| 419 | - 'ldap_base' => '', |
|
| 420 | - 'ldap_base_users' => '', |
|
| 421 | - 'ldap_base_groups' => '', |
|
| 422 | - 'ldap_userlist_filter' => '', |
|
| 423 | - 'ldap_user_filter_mode' => 0, |
|
| 424 | - 'ldap_userfilter_objectclass' => '', |
|
| 425 | - 'ldap_userfilter_groups' => '', |
|
| 426 | - 'ldap_login_filter' => '', |
|
| 427 | - 'ldap_login_filter_mode' => 0, |
|
| 428 | - 'ldap_loginfilter_email' => 0, |
|
| 429 | - 'ldap_loginfilter_username' => 1, |
|
| 430 | - 'ldap_loginfilter_attributes' => '', |
|
| 431 | - 'ldap_group_filter' => '', |
|
| 432 | - 'ldap_group_filter_mode' => 0, |
|
| 433 | - 'ldap_groupfilter_objectclass' => '', |
|
| 434 | - 'ldap_groupfilter_groups' => '', |
|
| 435 | - 'ldap_gid_number' => 'gidNumber', |
|
| 436 | - 'ldap_display_name' => 'displayName', |
|
| 437 | - 'ldap_user_display_name_2' => '', |
|
| 438 | - 'ldap_group_display_name' => 'cn', |
|
| 439 | - 'ldap_tls' => 0, |
|
| 440 | - 'ldap_quota_def' => '', |
|
| 441 | - 'ldap_quota_attr' => '', |
|
| 442 | - 'ldap_email_attr' => '', |
|
| 443 | - 'ldap_group_member_assoc_attribute' => 'uniqueMember', |
|
| 444 | - 'ldap_cache_ttl' => 600, |
|
| 445 | - 'ldap_uuid_user_attribute' => 'auto', |
|
| 446 | - 'ldap_uuid_group_attribute' => 'auto', |
|
| 447 | - 'home_folder_naming_rule' => '', |
|
| 448 | - 'ldap_turn_off_cert_check' => 0, |
|
| 449 | - 'ldap_configuration_active' => 0, |
|
| 450 | - 'ldap_attributes_for_user_search' => '', |
|
| 451 | - 'ldap_attributes_for_group_search' => '', |
|
| 452 | - 'ldap_expert_username_attr' => '', |
|
| 453 | - 'ldap_expert_uuid_user_attr' => '', |
|
| 454 | - 'ldap_expert_uuid_group_attr' => '', |
|
| 455 | - 'has_memberof_filter_support' => 0, |
|
| 456 | - 'use_memberof_to_detect_membership' => 1, |
|
| 457 | - 'last_jpegPhoto_lookup' => 0, |
|
| 458 | - 'ldap_nested_groups' => 0, |
|
| 459 | - 'ldap_paging_size' => 500, |
|
| 460 | - 'ldap_turn_on_pwd_change' => 0, |
|
| 461 | - 'ldap_experienced_admin' => 0, |
|
| 462 | - 'ldap_dynamic_group_member_url' => '', |
|
| 463 | - 'ldap_default_ppolicy_dn' => '', |
|
| 464 | - ); |
|
| 465 | - } |
|
| 406 | + /** |
|
| 407 | + * @return array an associative array with the default values. Keys are correspond |
|
| 408 | + * to config-value entries in the database table |
|
| 409 | + */ |
|
| 410 | + public function getDefaults() { |
|
| 411 | + return array( |
|
| 412 | + 'ldap_host' => '', |
|
| 413 | + 'ldap_port' => '', |
|
| 414 | + 'ldap_backup_host' => '', |
|
| 415 | + 'ldap_backup_port' => '', |
|
| 416 | + 'ldap_override_main_server' => '', |
|
| 417 | + 'ldap_dn' => '', |
|
| 418 | + 'ldap_agent_password' => '', |
|
| 419 | + 'ldap_base' => '', |
|
| 420 | + 'ldap_base_users' => '', |
|
| 421 | + 'ldap_base_groups' => '', |
|
| 422 | + 'ldap_userlist_filter' => '', |
|
| 423 | + 'ldap_user_filter_mode' => 0, |
|
| 424 | + 'ldap_userfilter_objectclass' => '', |
|
| 425 | + 'ldap_userfilter_groups' => '', |
|
| 426 | + 'ldap_login_filter' => '', |
|
| 427 | + 'ldap_login_filter_mode' => 0, |
|
| 428 | + 'ldap_loginfilter_email' => 0, |
|
| 429 | + 'ldap_loginfilter_username' => 1, |
|
| 430 | + 'ldap_loginfilter_attributes' => '', |
|
| 431 | + 'ldap_group_filter' => '', |
|
| 432 | + 'ldap_group_filter_mode' => 0, |
|
| 433 | + 'ldap_groupfilter_objectclass' => '', |
|
| 434 | + 'ldap_groupfilter_groups' => '', |
|
| 435 | + 'ldap_gid_number' => 'gidNumber', |
|
| 436 | + 'ldap_display_name' => 'displayName', |
|
| 437 | + 'ldap_user_display_name_2' => '', |
|
| 438 | + 'ldap_group_display_name' => 'cn', |
|
| 439 | + 'ldap_tls' => 0, |
|
| 440 | + 'ldap_quota_def' => '', |
|
| 441 | + 'ldap_quota_attr' => '', |
|
| 442 | + 'ldap_email_attr' => '', |
|
| 443 | + 'ldap_group_member_assoc_attribute' => 'uniqueMember', |
|
| 444 | + 'ldap_cache_ttl' => 600, |
|
| 445 | + 'ldap_uuid_user_attribute' => 'auto', |
|
| 446 | + 'ldap_uuid_group_attribute' => 'auto', |
|
| 447 | + 'home_folder_naming_rule' => '', |
|
| 448 | + 'ldap_turn_off_cert_check' => 0, |
|
| 449 | + 'ldap_configuration_active' => 0, |
|
| 450 | + 'ldap_attributes_for_user_search' => '', |
|
| 451 | + 'ldap_attributes_for_group_search' => '', |
|
| 452 | + 'ldap_expert_username_attr' => '', |
|
| 453 | + 'ldap_expert_uuid_user_attr' => '', |
|
| 454 | + 'ldap_expert_uuid_group_attr' => '', |
|
| 455 | + 'has_memberof_filter_support' => 0, |
|
| 456 | + 'use_memberof_to_detect_membership' => 1, |
|
| 457 | + 'last_jpegPhoto_lookup' => 0, |
|
| 458 | + 'ldap_nested_groups' => 0, |
|
| 459 | + 'ldap_paging_size' => 500, |
|
| 460 | + 'ldap_turn_on_pwd_change' => 0, |
|
| 461 | + 'ldap_experienced_admin' => 0, |
|
| 462 | + 'ldap_dynamic_group_member_url' => '', |
|
| 463 | + 'ldap_default_ppolicy_dn' => '', |
|
| 464 | + ); |
|
| 465 | + } |
|
| 466 | 466 | |
| 467 | - /** |
|
| 468 | - * @return array that maps internal variable names to database fields |
|
| 469 | - */ |
|
| 470 | - public function getConfigTranslationArray() { |
|
| 471 | - //TODO: merge them into one representation |
|
| 472 | - static $array = array( |
|
| 473 | - 'ldap_host' => 'ldapHost', |
|
| 474 | - 'ldap_port' => 'ldapPort', |
|
| 475 | - 'ldap_backup_host' => 'ldapBackupHost', |
|
| 476 | - 'ldap_backup_port' => 'ldapBackupPort', |
|
| 477 | - 'ldap_override_main_server' => 'ldapOverrideMainServer', |
|
| 478 | - 'ldap_dn' => 'ldapAgentName', |
|
| 479 | - 'ldap_agent_password' => 'ldapAgentPassword', |
|
| 480 | - 'ldap_base' => 'ldapBase', |
|
| 481 | - 'ldap_base_users' => 'ldapBaseUsers', |
|
| 482 | - 'ldap_base_groups' => 'ldapBaseGroups', |
|
| 483 | - 'ldap_userfilter_objectclass' => 'ldapUserFilterObjectclass', |
|
| 484 | - 'ldap_userfilter_groups' => 'ldapUserFilterGroups', |
|
| 485 | - 'ldap_userlist_filter' => 'ldapUserFilter', |
|
| 486 | - 'ldap_user_filter_mode' => 'ldapUserFilterMode', |
|
| 487 | - 'ldap_login_filter' => 'ldapLoginFilter', |
|
| 488 | - 'ldap_login_filter_mode' => 'ldapLoginFilterMode', |
|
| 489 | - 'ldap_loginfilter_email' => 'ldapLoginFilterEmail', |
|
| 490 | - 'ldap_loginfilter_username' => 'ldapLoginFilterUsername', |
|
| 491 | - 'ldap_loginfilter_attributes' => 'ldapLoginFilterAttributes', |
|
| 492 | - 'ldap_group_filter' => 'ldapGroupFilter', |
|
| 493 | - 'ldap_group_filter_mode' => 'ldapGroupFilterMode', |
|
| 494 | - 'ldap_groupfilter_objectclass' => 'ldapGroupFilterObjectclass', |
|
| 495 | - 'ldap_groupfilter_groups' => 'ldapGroupFilterGroups', |
|
| 496 | - 'ldap_gid_number' => 'ldapGidNumber', |
|
| 497 | - 'ldap_display_name' => 'ldapUserDisplayName', |
|
| 498 | - 'ldap_user_display_name_2' => 'ldapUserDisplayName2', |
|
| 499 | - 'ldap_group_display_name' => 'ldapGroupDisplayName', |
|
| 500 | - 'ldap_tls' => 'ldapTLS', |
|
| 501 | - 'ldap_quota_def' => 'ldapQuotaDefault', |
|
| 502 | - 'ldap_quota_attr' => 'ldapQuotaAttribute', |
|
| 503 | - 'ldap_email_attr' => 'ldapEmailAttribute', |
|
| 504 | - 'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr', |
|
| 505 | - 'ldap_cache_ttl' => 'ldapCacheTTL', |
|
| 506 | - 'home_folder_naming_rule' => 'homeFolderNamingRule', |
|
| 507 | - 'ldap_turn_off_cert_check' => 'turnOffCertCheck', |
|
| 508 | - 'ldap_configuration_active' => 'ldapConfigurationActive', |
|
| 509 | - 'ldap_attributes_for_user_search' => 'ldapAttributesForUserSearch', |
|
| 510 | - 'ldap_attributes_for_group_search' => 'ldapAttributesForGroupSearch', |
|
| 511 | - 'ldap_expert_username_attr' => 'ldapExpertUsernameAttr', |
|
| 512 | - 'ldap_expert_uuid_user_attr' => 'ldapExpertUUIDUserAttr', |
|
| 513 | - 'ldap_expert_uuid_group_attr' => 'ldapExpertUUIDGroupAttr', |
|
| 514 | - 'has_memberof_filter_support' => 'hasMemberOfFilterSupport', |
|
| 515 | - 'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership', |
|
| 516 | - 'last_jpegPhoto_lookup' => 'lastJpegPhotoLookup', |
|
| 517 | - 'ldap_nested_groups' => 'ldapNestedGroups', |
|
| 518 | - 'ldap_paging_size' => 'ldapPagingSize', |
|
| 519 | - 'ldap_turn_on_pwd_change' => 'turnOnPasswordChange', |
|
| 520 | - 'ldap_experienced_admin' => 'ldapExperiencedAdmin', |
|
| 521 | - 'ldap_dynamic_group_member_url' => 'ldapDynamicGroupMemberURL', |
|
| 522 | - 'ldap_default_ppolicy_dn' => 'ldapDefaultPPolicyDN', |
|
| 523 | - ); |
|
| 524 | - return $array; |
|
| 525 | - } |
|
| 467 | + /** |
|
| 468 | + * @return array that maps internal variable names to database fields |
|
| 469 | + */ |
|
| 470 | + public function getConfigTranslationArray() { |
|
| 471 | + //TODO: merge them into one representation |
|
| 472 | + static $array = array( |
|
| 473 | + 'ldap_host' => 'ldapHost', |
|
| 474 | + 'ldap_port' => 'ldapPort', |
|
| 475 | + 'ldap_backup_host' => 'ldapBackupHost', |
|
| 476 | + 'ldap_backup_port' => 'ldapBackupPort', |
|
| 477 | + 'ldap_override_main_server' => 'ldapOverrideMainServer', |
|
| 478 | + 'ldap_dn' => 'ldapAgentName', |
|
| 479 | + 'ldap_agent_password' => 'ldapAgentPassword', |
|
| 480 | + 'ldap_base' => 'ldapBase', |
|
| 481 | + 'ldap_base_users' => 'ldapBaseUsers', |
|
| 482 | + 'ldap_base_groups' => 'ldapBaseGroups', |
|
| 483 | + 'ldap_userfilter_objectclass' => 'ldapUserFilterObjectclass', |
|
| 484 | + 'ldap_userfilter_groups' => 'ldapUserFilterGroups', |
|
| 485 | + 'ldap_userlist_filter' => 'ldapUserFilter', |
|
| 486 | + 'ldap_user_filter_mode' => 'ldapUserFilterMode', |
|
| 487 | + 'ldap_login_filter' => 'ldapLoginFilter', |
|
| 488 | + 'ldap_login_filter_mode' => 'ldapLoginFilterMode', |
|
| 489 | + 'ldap_loginfilter_email' => 'ldapLoginFilterEmail', |
|
| 490 | + 'ldap_loginfilter_username' => 'ldapLoginFilterUsername', |
|
| 491 | + 'ldap_loginfilter_attributes' => 'ldapLoginFilterAttributes', |
|
| 492 | + 'ldap_group_filter' => 'ldapGroupFilter', |
|
| 493 | + 'ldap_group_filter_mode' => 'ldapGroupFilterMode', |
|
| 494 | + 'ldap_groupfilter_objectclass' => 'ldapGroupFilterObjectclass', |
|
| 495 | + 'ldap_groupfilter_groups' => 'ldapGroupFilterGroups', |
|
| 496 | + 'ldap_gid_number' => 'ldapGidNumber', |
|
| 497 | + 'ldap_display_name' => 'ldapUserDisplayName', |
|
| 498 | + 'ldap_user_display_name_2' => 'ldapUserDisplayName2', |
|
| 499 | + 'ldap_group_display_name' => 'ldapGroupDisplayName', |
|
| 500 | + 'ldap_tls' => 'ldapTLS', |
|
| 501 | + 'ldap_quota_def' => 'ldapQuotaDefault', |
|
| 502 | + 'ldap_quota_attr' => 'ldapQuotaAttribute', |
|
| 503 | + 'ldap_email_attr' => 'ldapEmailAttribute', |
|
| 504 | + 'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr', |
|
| 505 | + 'ldap_cache_ttl' => 'ldapCacheTTL', |
|
| 506 | + 'home_folder_naming_rule' => 'homeFolderNamingRule', |
|
| 507 | + 'ldap_turn_off_cert_check' => 'turnOffCertCheck', |
|
| 508 | + 'ldap_configuration_active' => 'ldapConfigurationActive', |
|
| 509 | + 'ldap_attributes_for_user_search' => 'ldapAttributesForUserSearch', |
|
| 510 | + 'ldap_attributes_for_group_search' => 'ldapAttributesForGroupSearch', |
|
| 511 | + 'ldap_expert_username_attr' => 'ldapExpertUsernameAttr', |
|
| 512 | + 'ldap_expert_uuid_user_attr' => 'ldapExpertUUIDUserAttr', |
|
| 513 | + 'ldap_expert_uuid_group_attr' => 'ldapExpertUUIDGroupAttr', |
|
| 514 | + 'has_memberof_filter_support' => 'hasMemberOfFilterSupport', |
|
| 515 | + 'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership', |
|
| 516 | + 'last_jpegPhoto_lookup' => 'lastJpegPhotoLookup', |
|
| 517 | + 'ldap_nested_groups' => 'ldapNestedGroups', |
|
| 518 | + 'ldap_paging_size' => 'ldapPagingSize', |
|
| 519 | + 'ldap_turn_on_pwd_change' => 'turnOnPasswordChange', |
|
| 520 | + 'ldap_experienced_admin' => 'ldapExperiencedAdmin', |
|
| 521 | + 'ldap_dynamic_group_member_url' => 'ldapDynamicGroupMemberURL', |
|
| 522 | + 'ldap_default_ppolicy_dn' => 'ldapDefaultPPolicyDN', |
|
| 523 | + ); |
|
| 524 | + return $array; |
|
| 525 | + } |
|
| 526 | 526 | |
| 527 | 527 | } |
@@ -26,13 +26,13 @@ |
||
| 26 | 26 | namespace OCA\User_LDAP; |
| 27 | 27 | |
| 28 | 28 | abstract class LDAPUtility { |
| 29 | - protected $ldap; |
|
| 29 | + protected $ldap; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * constructor, make sure the subclasses call this one! |
|
| 33 | - * @param ILDAPWrapper $ldapWrapper an instance of an ILDAPWrapper |
|
| 34 | - */ |
|
| 35 | - public function __construct(ILDAPWrapper $ldapWrapper) { |
|
| 36 | - $this->ldap = $ldapWrapper; |
|
| 37 | - } |
|
| 31 | + /** |
|
| 32 | + * constructor, make sure the subclasses call this one! |
|
| 33 | + * @param ILDAPWrapper $ldapWrapper an instance of an ILDAPWrapper |
|
| 34 | + */ |
|
| 35 | + public function __construct(ILDAPWrapper $ldapWrapper) { |
|
| 36 | + $this->ldap = $ldapWrapper; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -28,55 +28,55 @@ |
||
| 28 | 28 | use OCP\Settings\IIconSection; |
| 29 | 29 | |
| 30 | 30 | class Section implements IIconSection { |
| 31 | - /** @var IL10N */ |
|
| 32 | - private $l; |
|
| 33 | - /** @var IURLGenerator */ |
|
| 34 | - private $url; |
|
| 31 | + /** @var IL10N */ |
|
| 32 | + private $l; |
|
| 33 | + /** @var IURLGenerator */ |
|
| 34 | + private $url; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param IURLGenerator $url |
|
| 38 | - * @param IL10N $l |
|
| 39 | - */ |
|
| 40 | - public function __construct(IURLGenerator $url, IL10N $l) { |
|
| 41 | - $this->url = $url; |
|
| 42 | - $this->l = $l; |
|
| 43 | - } |
|
| 36 | + /** |
|
| 37 | + * @param IURLGenerator $url |
|
| 38 | + * @param IL10N $l |
|
| 39 | + */ |
|
| 40 | + public function __construct(IURLGenerator $url, IL10N $l) { |
|
| 41 | + $this->url = $url; |
|
| 42 | + $this->l = $l; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * returns the ID of the section. It is supposed to be a lower case string, |
|
| 47 | - * e.g. 'ldap' |
|
| 48 | - * |
|
| 49 | - * @returns string |
|
| 50 | - */ |
|
| 51 | - public function getID() { |
|
| 52 | - return 'ldap'; |
|
| 53 | - } |
|
| 45 | + /** |
|
| 46 | + * returns the ID of the section. It is supposed to be a lower case string, |
|
| 47 | + * e.g. 'ldap' |
|
| 48 | + * |
|
| 49 | + * @returns string |
|
| 50 | + */ |
|
| 51 | + public function getID() { |
|
| 52 | + return 'ldap'; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * returns the translated name as it should be displayed, e.g. 'LDAP / AD |
|
| 57 | - * integration'. Use the L10N service to translate it. |
|
| 58 | - * |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public function getName() { |
|
| 62 | - return $this->l->t('LDAP / AD integration'); |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * returns the translated name as it should be displayed, e.g. 'LDAP / AD |
|
| 57 | + * integration'. Use the L10N service to translate it. |
|
| 58 | + * |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public function getName() { |
|
| 62 | + return $this->l->t('LDAP / AD integration'); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @return int whether the form should be rather on the top or bottom of |
|
| 67 | - * the settings navigation. The sections are arranged in ascending order of |
|
| 68 | - * the priority values. It is required to return a value between 0 and 99. |
|
| 69 | - * |
|
| 70 | - * E.g.: 70 |
|
| 71 | - */ |
|
| 72 | - public function getPriority() { |
|
| 73 | - return 25; |
|
| 74 | - } |
|
| 65 | + /** |
|
| 66 | + * @return int whether the form should be rather on the top or bottom of |
|
| 67 | + * the settings navigation. The sections are arranged in ascending order of |
|
| 68 | + * the priority values. It is required to return a value between 0 and 99. |
|
| 69 | + * |
|
| 70 | + * E.g.: 70 |
|
| 71 | + */ |
|
| 72 | + public function getPriority() { |
|
| 73 | + return 25; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * {@inheritdoc} |
|
| 78 | - */ |
|
| 79 | - public function getIcon() { |
|
| 80 | - return $this->url->imagePath('user_ldap', 'app-dark.svg'); |
|
| 81 | - } |
|
| 76 | + /** |
|
| 77 | + * {@inheritdoc} |
|
| 78 | + */ |
|
| 79 | + public function getIcon() { |
|
| 80 | + return $this->url->imagePath('user_ldap', 'app-dark.svg'); |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -31,59 +31,59 @@ |
||
| 31 | 31 | use OCP\Template; |
| 32 | 32 | |
| 33 | 33 | class Admin implements ISettings { |
| 34 | - /** @var IL10N */ |
|
| 35 | - private $l; |
|
| 34 | + /** @var IL10N */ |
|
| 35 | + private $l; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param IL10N $l |
|
| 39 | - */ |
|
| 40 | - public function __construct(IL10N $l) { |
|
| 41 | - $this->l = $l; |
|
| 42 | - } |
|
| 37 | + /** |
|
| 38 | + * @param IL10N $l |
|
| 39 | + */ |
|
| 40 | + public function __construct(IL10N $l) { |
|
| 41 | + $this->l = $l; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return TemplateResponse |
|
| 46 | - */ |
|
| 47 | - public function getForm() { |
|
| 48 | - $helper = new Helper(\OC::$server->getConfig()); |
|
| 49 | - $prefixes = $helper->getServerConfigurationPrefixes(); |
|
| 50 | - $hosts = $helper->getServerConfigurationHosts(); |
|
| 44 | + /** |
|
| 45 | + * @return TemplateResponse |
|
| 46 | + */ |
|
| 47 | + public function getForm() { |
|
| 48 | + $helper = new Helper(\OC::$server->getConfig()); |
|
| 49 | + $prefixes = $helper->getServerConfigurationPrefixes(); |
|
| 50 | + $hosts = $helper->getServerConfigurationHosts(); |
|
| 51 | 51 | |
| 52 | - $wControls = new Template('user_ldap', 'part.wizardcontrols'); |
|
| 53 | - $wControls = $wControls->fetchPage(); |
|
| 54 | - $sControls = new Template('user_ldap', 'part.settingcontrols'); |
|
| 55 | - $sControls = $sControls->fetchPage(); |
|
| 52 | + $wControls = new Template('user_ldap', 'part.wizardcontrols'); |
|
| 53 | + $wControls = $wControls->fetchPage(); |
|
| 54 | + $sControls = new Template('user_ldap', 'part.settingcontrols'); |
|
| 55 | + $sControls = $sControls->fetchPage(); |
|
| 56 | 56 | |
| 57 | - $parameters['serverConfigurationPrefixes'] = $prefixes; |
|
| 58 | - $parameters['serverConfigurationHosts'] = $hosts; |
|
| 59 | - $parameters['settingControls'] = $sControls; |
|
| 60 | - $parameters['wizardControls'] = $wControls; |
|
| 57 | + $parameters['serverConfigurationPrefixes'] = $prefixes; |
|
| 58 | + $parameters['serverConfigurationHosts'] = $hosts; |
|
| 59 | + $parameters['settingControls'] = $sControls; |
|
| 60 | + $parameters['wizardControls'] = $wControls; |
|
| 61 | 61 | |
| 62 | - // assign default values |
|
| 63 | - $config = new Configuration('', false); |
|
| 64 | - $defaults = $config->getDefaults(); |
|
| 65 | - foreach($defaults as $key => $default) { |
|
| 66 | - $parameters[$key.'_default'] = $default; |
|
| 67 | - } |
|
| 62 | + // assign default values |
|
| 63 | + $config = new Configuration('', false); |
|
| 64 | + $defaults = $config->getDefaults(); |
|
| 65 | + foreach($defaults as $key => $default) { |
|
| 66 | + $parameters[$key.'_default'] = $default; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - return new TemplateResponse('user_ldap', 'settings', $parameters); |
|
| 70 | - } |
|
| 69 | + return new TemplateResponse('user_ldap', 'settings', $parameters); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @return string the section ID, e.g. 'sharing' |
|
| 74 | - */ |
|
| 75 | - public function getSection() { |
|
| 76 | - return 'ldap'; |
|
| 77 | - } |
|
| 72 | + /** |
|
| 73 | + * @return string the section ID, e.g. 'sharing' |
|
| 74 | + */ |
|
| 75 | + public function getSection() { |
|
| 76 | + return 'ldap'; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @return int whether the form should be rather on the top or bottom of |
|
| 81 | - * the admin section. The forms are arranged in ascending order of the |
|
| 82 | - * priority values. It is required to return a value between 0 and 100. |
|
| 83 | - * |
|
| 84 | - * E.g.: 70 |
|
| 85 | - */ |
|
| 86 | - public function getPriority() { |
|
| 87 | - return 5; |
|
| 88 | - } |
|
| 79 | + /** |
|
| 80 | + * @return int whether the form should be rather on the top or bottom of |
|
| 81 | + * the admin section. The forms are arranged in ascending order of the |
|
| 82 | + * priority values. It is required to return a value between 0 and 100. |
|
| 83 | + * |
|
| 84 | + * E.g.: 70 |
|
| 85 | + */ |
|
| 86 | + public function getPriority() { |
|
| 87 | + return 5; |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -62,7 +62,7 @@ |
||
| 62 | 62 | // assign default values |
| 63 | 63 | $config = new Configuration('', false); |
| 64 | 64 | $defaults = $config->getDefaults(); |
| 65 | - foreach($defaults as $key => $default) { |
|
| 65 | + foreach ($defaults as $key => $default) { |
|
| 66 | 66 | $parameters[$key.'_default'] = $default; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $this->configuration = new Configuration($configPrefix, |
| 88 | 88 | !is_null($configID)); |
| 89 | 89 | $memcache = \OC::$server->getMemCacheFactory(); |
| 90 | - if($memcache->isAvailable()) { |
|
| 90 | + if ($memcache->isAvailable()) { |
|
| 91 | 91 | $this->cache = $memcache->create(); |
| 92 | 92 | } |
| 93 | 93 | $helper = new Helper(\OC::$server->getConfig()); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | public function __destruct() { |
| 102 | - if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 102 | + if (!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 103 | 103 | @$this->ldap->unbind($this->ldapConnectionRes); |
| 104 | 104 | }; |
| 105 | 105 | } |
@@ -119,11 +119,11 @@ discard block |
||
| 119 | 119 | * @return bool|mixed|void |
| 120 | 120 | */ |
| 121 | 121 | public function __get($name) { |
| 122 | - if(!$this->configured) { |
|
| 122 | + if (!$this->configured) { |
|
| 123 | 123 | $this->readConfiguration(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if($name === 'hasPagedResultSupport') { |
|
| 126 | + if ($name === 'hasPagedResultSupport') { |
|
| 127 | 127 | return $this->hasPagedResultSupport; |
| 128 | 128 | } |
| 129 | 129 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | $before = $this->configuration->$name; |
| 140 | 140 | $this->configuration->$name = $value; |
| 141 | 141 | $after = $this->configuration->$name; |
| 142 | - if($before !== $after) { |
|
| 142 | + if ($before !== $after) { |
|
| 143 | 143 | if ($this->configID !== '') { |
| 144 | 144 | $this->configuration->saveConfiguration(); |
| 145 | 145 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @param bool $state |
| 155 | 155 | */ |
| 156 | 156 | public function setIgnoreValidation($state) { |
| 157 | - $this->ignoreValidation = (bool)$state; |
|
| 157 | + $this->ignoreValidation = (bool) $state; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -170,14 +170,14 @@ discard block |
||
| 170 | 170 | * Returns the LDAP handler |
| 171 | 171 | */ |
| 172 | 172 | public function getConnectionResource() { |
| 173 | - if(!$this->ldapConnectionRes) { |
|
| 173 | + if (!$this->ldapConnectionRes) { |
|
| 174 | 174 | $this->init(); |
| 175 | - } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 175 | + } else if (!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 176 | 176 | $this->ldapConnectionRes = null; |
| 177 | 177 | $this->establishConnection(); |
| 178 | 178 | } |
| 179 | - if(is_null($this->ldapConnectionRes)) { |
|
| 180 | - \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
| 179 | + if (is_null($this->ldapConnectionRes)) { |
|
| 180 | + \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server '.$this->configuration->ldapHost, \OCP\Util::ERROR); |
|
| 181 | 181 | throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
| 182 | 182 | } |
| 183 | 183 | return $this->ldapConnectionRes; |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * resets the connection resource |
| 188 | 188 | */ |
| 189 | 189 | public function resetConnectionResource() { |
| 190 | - if(!is_null($this->ldapConnectionRes)) { |
|
| 190 | + if (!is_null($this->ldapConnectionRes)) { |
|
| 191 | 191 | @$this->ldap->unbind($this->ldapConnectionRes); |
| 192 | 192 | $this->ldapConnectionRes = null; |
| 193 | 193 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | private function getCacheKey($key) { |
| 201 | 201 | $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
| 202 | - if(is_null($key)) { |
|
| 202 | + if (is_null($key)) { |
|
| 203 | 203 | return $prefix; |
| 204 | 204 | } |
| 205 | 205 | return $prefix.md5($key); |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | * @return mixed|null |
| 211 | 211 | */ |
| 212 | 212 | public function getFromCache($key) { |
| 213 | - if(!$this->configured) { |
|
| 213 | + if (!$this->configured) { |
|
| 214 | 214 | $this->readConfiguration(); |
| 215 | 215 | } |
| 216 | - if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
| 216 | + if (is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
| 217 | 217 | return null; |
| 218 | 218 | } |
| 219 | 219 | $key = $this->getCacheKey($key); |
@@ -228,10 +228,10 @@ discard block |
||
| 228 | 228 | * @return string |
| 229 | 229 | */ |
| 230 | 230 | public function writeToCache($key, $value) { |
| 231 | - if(!$this->configured) { |
|
| 231 | + if (!$this->configured) { |
|
| 232 | 232 | $this->readConfiguration(); |
| 233 | 233 | } |
| 234 | - if(is_null($this->cache) |
|
| 234 | + if (is_null($this->cache) |
|
| 235 | 235 | || !$this->configuration->ldapCacheTTL |
| 236 | 236 | || !$this->configuration->ldapConfigurationActive) { |
| 237 | 237 | return null; |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | public function clearCache() { |
| 245 | - if(!is_null($this->cache)) { |
|
| 245 | + if (!is_null($this->cache)) { |
|
| 246 | 246 | $this->cache->clear($this->getCacheKey(null)); |
| 247 | 247 | } |
| 248 | 248 | } |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | * @return null |
| 255 | 255 | */ |
| 256 | 256 | private function readConfiguration($force = false) { |
| 257 | - if((!$this->configured || $force) && !is_null($this->configID)) { |
|
| 257 | + if ((!$this->configured || $force) && !is_null($this->configID)) { |
|
| 258 | 258 | $this->configuration->readConfiguration(); |
| 259 | 259 | $this->configured = $this->validateConfiguration(); |
| 260 | 260 | } |
@@ -267,12 +267,12 @@ discard block |
||
| 267 | 267 | * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
| 268 | 268 | */ |
| 269 | 269 | public function setConfiguration($config, &$setParameters = null) { |
| 270 | - if(is_null($setParameters)) { |
|
| 270 | + if (is_null($setParameters)) { |
|
| 271 | 271 | $setParameters = array(); |
| 272 | 272 | } |
| 273 | 273 | $this->doNotValidate = false; |
| 274 | 274 | $this->configuration->setConfiguration($config, $setParameters); |
| 275 | - if(count($setParameters) > 0) { |
|
| 275 | + if (count($setParameters) > 0) { |
|
| 276 | 276 | $this->configured = $this->validateConfiguration(); |
| 277 | 277 | } |
| 278 | 278 | |
@@ -299,10 +299,10 @@ discard block |
||
| 299 | 299 | $config = $this->configuration->getConfiguration(); |
| 300 | 300 | $cta = $this->configuration->getConfigTranslationArray(); |
| 301 | 301 | $result = array(); |
| 302 | - foreach($cta as $dbkey => $configkey) { |
|
| 303 | - switch($configkey) { |
|
| 302 | + foreach ($cta as $dbkey => $configkey) { |
|
| 303 | + switch ($configkey) { |
|
| 304 | 304 | case 'homeFolderNamingRule': |
| 305 | - if(strpos($config[$configkey], 'attr:') === 0) { |
|
| 305 | + if (strpos($config[$configkey], 'attr:') === 0) { |
|
| 306 | 306 | $result[$dbkey] = substr($config[$configkey], 5); |
| 307 | 307 | } else { |
| 308 | 308 | $result[$dbkey] = ''; |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | case 'ldapBaseGroups': |
| 314 | 314 | case 'ldapAttributesForUserSearch': |
| 315 | 315 | case 'ldapAttributesForGroupSearch': |
| 316 | - if(is_array($config[$configkey])) { |
|
| 316 | + if (is_array($config[$configkey])) { |
|
| 317 | 317 | $result[$dbkey] = implode("\n", $config[$configkey]); |
| 318 | 318 | break; |
| 319 | 319 | } //else follows default |
@@ -326,23 +326,23 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | private function doSoftValidation() { |
| 328 | 328 | //if User or Group Base are not set, take over Base DN setting |
| 329 | - foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
| 329 | + foreach (array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
| 330 | 330 | $val = $this->configuration->$keyBase; |
| 331 | - if(empty($val)) { |
|
| 331 | + if (empty($val)) { |
|
| 332 | 332 | $this->configuration->$keyBase = $this->configuration->ldapBase; |
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
| 336 | + foreach (array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
| 337 | 337 | 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
| 338 | 338 | as $expertSetting => $effectiveSetting) { |
| 339 | 339 | $uuidOverride = $this->configuration->$expertSetting; |
| 340 | - if(!empty($uuidOverride)) { |
|
| 340 | + if (!empty($uuidOverride)) { |
|
| 341 | 341 | $this->configuration->$effectiveSetting = $uuidOverride; |
| 342 | 342 | } else { |
| 343 | 343 | $uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid', |
| 344 | 344 | 'objectguid', 'guid', 'ipauniqueid'); |
| 345 | - if(!in_array($this->configuration->$effectiveSetting, |
|
| 345 | + if (!in_array($this->configuration->$effectiveSetting, |
|
| 346 | 346 | $uuidAttributes) |
| 347 | 347 | && (!is_null($this->configID))) { |
| 348 | 348 | $this->configuration->$effectiveSetting = 'auto'; |
@@ -364,14 +364,14 @@ discard block |
||
| 364 | 364 | //make sure empty search attributes are saved as simple, empty array |
| 365 | 365 | $saKeys = array('ldapAttributesForUserSearch', |
| 366 | 366 | 'ldapAttributesForGroupSearch'); |
| 367 | - foreach($saKeys as $key) { |
|
| 367 | + foreach ($saKeys as $key) { |
|
| 368 | 368 | $val = $this->configuration->$key; |
| 369 | - if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
| 369 | + if (is_array($val) && count($val) === 1 && empty($val[0])) { |
|
| 370 | 370 | $this->configuration->$key = array(); |
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
| 374 | + if ((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
| 375 | 375 | && $this->configuration->ldapTLS) { |
| 376 | 376 | $this->configuration->ldapTLS = false; |
| 377 | 377 | \OCP\Util::writeLog('user_ldap', |
@@ -392,10 +392,10 @@ discard block |
||
| 392 | 392 | //options that shall not be empty |
| 393 | 393 | $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
| 394 | 394 | 'ldapGroupDisplayName', 'ldapLoginFilter'); |
| 395 | - foreach($options as $key) { |
|
| 395 | + foreach ($options as $key) { |
|
| 396 | 396 | $val = $this->configuration->$key; |
| 397 | - if(empty($val)) { |
|
| 398 | - switch($key) { |
|
| 397 | + if (empty($val)) { |
|
| 398 | + switch ($key) { |
|
| 399 | 399 | case 'ldapHost': |
| 400 | 400 | $subj = 'LDAP Host'; |
| 401 | 401 | break; |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | $agent = $this->configuration->ldapAgentName; |
| 427 | 427 | $pwd = $this->configuration->ldapAgentPassword; |
| 428 | 428 | if ( |
| 429 | - ($agent === '' && $pwd !== '') |
|
| 429 | + ($agent === '' && $pwd !== '') |
|
| 430 | 430 | || ($agent !== '' && $pwd === '') |
| 431 | 431 | ) { |
| 432 | 432 | \OCP\Util::writeLog('user_ldap', |
@@ -441,14 +441,14 @@ discard block |
||
| 441 | 441 | $baseUsers = $this->configuration->ldapBaseUsers; |
| 442 | 442 | $baseGroups = $this->configuration->ldapBaseGroups; |
| 443 | 443 | |
| 444 | - if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
| 444 | + if (empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
| 445 | 445 | \OCP\Util::writeLog('user_ldap', |
| 446 | 446 | $errorStr.'Not a single Base DN given.', |
| 447 | 447 | \OCP\Util::WARN); |
| 448 | 448 | $configurationOK = false; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 451 | + if (mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 452 | 452 | === false) { |
| 453 | 453 | \OCP\Util::writeLog('user_ldap', |
| 454 | 454 | $errorStr.'login filter does not contain %uid '. |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | */ |
| 467 | 467 | private function validateConfiguration() { |
| 468 | 468 | |
| 469 | - if($this->doNotValidate) { |
|
| 469 | + if ($this->doNotValidate) { |
|
| 470 | 470 | //don't do a validation if it is a new configuration with pure |
| 471 | 471 | //default values. Will be allowed on changes via __set or |
| 472 | 472 | //setConfiguration |
@@ -487,21 +487,21 @@ discard block |
||
| 487 | 487 | * Connects and Binds to LDAP |
| 488 | 488 | */ |
| 489 | 489 | private function establishConnection() { |
| 490 | - if(!$this->configuration->ldapConfigurationActive) { |
|
| 490 | + if (!$this->configuration->ldapConfigurationActive) { |
|
| 491 | 491 | return null; |
| 492 | 492 | } |
| 493 | 493 | static $phpLDAPinstalled = true; |
| 494 | - if(!$phpLDAPinstalled) { |
|
| 494 | + if (!$phpLDAPinstalled) { |
|
| 495 | 495 | return false; |
| 496 | 496 | } |
| 497 | - if(!$this->ignoreValidation && !$this->configured) { |
|
| 497 | + if (!$this->ignoreValidation && !$this->configured) { |
|
| 498 | 498 | \OCP\Util::writeLog('user_ldap', |
| 499 | 499 | 'Configuration is invalid, cannot connect', |
| 500 | 500 | \OCP\Util::WARN); |
| 501 | 501 | return false; |
| 502 | 502 | } |
| 503 | - if(!$this->ldapConnectionRes) { |
|
| 504 | - if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
| 503 | + if (!$this->ldapConnectionRes) { |
|
| 504 | + if (!$this->ldap->areLDAPFunctionsAvailable()) { |
|
| 505 | 505 | $phpLDAPinstalled = false; |
| 506 | 506 | \OCP\Util::writeLog('user_ldap', |
| 507 | 507 | 'function ldap_connect is not available. Make '. |
@@ -510,8 +510,8 @@ discard block |
||
| 510 | 510 | |
| 511 | 511 | return false; |
| 512 | 512 | } |
| 513 | - if($this->configuration->turnOffCertCheck) { |
|
| 514 | - if(putenv('LDAPTLS_REQCERT=never')) { |
|
| 513 | + if ($this->configuration->turnOffCertCheck) { |
|
| 514 | + if (putenv('LDAPTLS_REQCERT=never')) { |
|
| 515 | 515 | \OCP\Util::writeLog('user_ldap', |
| 516 | 516 | 'Turned off SSL certificate validation successfully.', |
| 517 | 517 | \OCP\Util::DEBUG); |
@@ -534,24 +534,24 @@ discard block |
||
| 534 | 534 | $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
| 535 | 535 | $this->ldap->errno($this->ldapConnectionRes) : -1; |
| 536 | 536 | } |
| 537 | - if($bindStatus === true) { |
|
| 537 | + if ($bindStatus === true) { |
|
| 538 | 538 | return $bindStatus; |
| 539 | 539 | } |
| 540 | 540 | } catch (\OC\ServerNotAvailableException $e) { |
| 541 | - if(trim($this->configuration->ldapBackupHost) === "") { |
|
| 541 | + if (trim($this->configuration->ldapBackupHost) === "") { |
|
| 542 | 542 | throw $e; |
| 543 | 543 | } |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | //if LDAP server is not reachable, try the Backup (Replica!) Server |
| 547 | - if( $error !== 0 |
|
| 547 | + if ($error !== 0 |
|
| 548 | 548 | || $this->configuration->ldapOverrideMainServer |
| 549 | 549 | || $this->getFromCache('overrideMainServer')) |
| 550 | 550 | { |
| 551 | 551 | $this->doConnect($this->configuration->ldapBackupHost, |
| 552 | 552 | $this->configuration->ldapBackupPort); |
| 553 | 553 | $bindStatus = $this->bind(); |
| 554 | - if($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { |
|
| 554 | + if ($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { |
|
| 555 | 555 | //when bind to backup server succeeded and failed to main server, |
| 556 | 556 | //skip contacting him until next cache refresh |
| 557 | 557 | $this->writeToCache('overrideMainServer', true); |
@@ -573,9 +573,9 @@ discard block |
||
| 573 | 573 | return false; |
| 574 | 574 | } |
| 575 | 575 | $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
| 576 | - if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
| 577 | - if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
| 578 | - if($this->configuration->ldapTLS) { |
|
| 576 | + if ($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
| 577 | + if ($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
| 578 | + if ($this->configuration->ldapTLS) { |
|
| 579 | 579 | $this->ldap->startTls($this->ldapConnectionRes); |
| 580 | 580 | } |
| 581 | 581 | } |
@@ -590,25 +590,25 @@ discard block |
||
| 590 | 590 | */ |
| 591 | 591 | public function bind() { |
| 592 | 592 | static $getConnectionResourceAttempt = false; |
| 593 | - if(!$this->configuration->ldapConfigurationActive) { |
|
| 593 | + if (!$this->configuration->ldapConfigurationActive) { |
|
| 594 | 594 | return false; |
| 595 | 595 | } |
| 596 | - if($getConnectionResourceAttempt) { |
|
| 596 | + if ($getConnectionResourceAttempt) { |
|
| 597 | 597 | $getConnectionResourceAttempt = false; |
| 598 | 598 | return false; |
| 599 | 599 | } |
| 600 | 600 | $getConnectionResourceAttempt = true; |
| 601 | 601 | $cr = $this->getConnectionResource(); |
| 602 | 602 | $getConnectionResourceAttempt = false; |
| 603 | - if(!$this->ldap->isResource($cr)) { |
|
| 603 | + if (!$this->ldap->isResource($cr)) { |
|
| 604 | 604 | return false; |
| 605 | 605 | } |
| 606 | 606 | $ldapLogin = @$this->ldap->bind($cr, |
| 607 | 607 | $this->configuration->ldapAgentName, |
| 608 | 608 | $this->configuration->ldapAgentPassword); |
| 609 | - if(!$ldapLogin) { |
|
| 609 | + if (!$ldapLogin) { |
|
| 610 | 610 | \OCP\Util::writeLog('user_ldap', |
| 611 | - 'Bind failed: ' . $this->ldap->errno($cr) . ': ' . $this->ldap->error($cr), |
|
| 611 | + 'Bind failed: '.$this->ldap->errno($cr).': '.$this->ldap->error($cr), |
|
| 612 | 612 | \OCP\Util::WARN); |
| 613 | 613 | $this->ldapConnectionRes = null; |
| 614 | 614 | return false; |
@@ -52,574 +52,574 @@ |
||
| 52 | 52 | * @property string ldapUuidGroupAttribute |
| 53 | 53 | */ |
| 54 | 54 | class Connection extends LDAPUtility { |
| 55 | - private $ldapConnectionRes = null; |
|
| 56 | - private $configPrefix; |
|
| 57 | - private $configID; |
|
| 58 | - private $configured = false; |
|
| 59 | - private $hasPagedResultSupport = true; |
|
| 60 | - //whether connection should be kept on __destruct |
|
| 61 | - private $dontDestruct = false; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var bool runtime flag that indicates whether supported primary groups are available |
|
| 65 | - */ |
|
| 66 | - public $hasPrimaryGroups = true; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var bool runtime flag that indicates whether supported POSIX gidNumber are available |
|
| 70 | - */ |
|
| 71 | - public $hasGidNumber = true; |
|
| 72 | - |
|
| 73 | - //cache handler |
|
| 74 | - protected $cache; |
|
| 75 | - |
|
| 76 | - /** @var Configuration settings handler **/ |
|
| 77 | - protected $configuration; |
|
| 78 | - |
|
| 79 | - protected $doNotValidate = false; |
|
| 80 | - |
|
| 81 | - protected $ignoreValidation = false; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Constructor |
|
| 85 | - * @param ILDAPWrapper $ldap |
|
| 86 | - * @param string $configPrefix a string with the prefix for the configkey column (appconfig table) |
|
| 87 | - * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections |
|
| 88 | - */ |
|
| 89 | - public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') { |
|
| 90 | - parent::__construct($ldap); |
|
| 91 | - $this->configPrefix = $configPrefix; |
|
| 92 | - $this->configID = $configID; |
|
| 93 | - $this->configuration = new Configuration($configPrefix, |
|
| 94 | - !is_null($configID)); |
|
| 95 | - $memcache = \OC::$server->getMemCacheFactory(); |
|
| 96 | - if($memcache->isAvailable()) { |
|
| 97 | - $this->cache = $memcache->create(); |
|
| 98 | - } |
|
| 99 | - $helper = new Helper(\OC::$server->getConfig()); |
|
| 100 | - $this->doNotValidate = !in_array($this->configPrefix, |
|
| 101 | - $helper->getServerConfigurationPrefixes()); |
|
| 102 | - $this->hasPagedResultSupport = |
|
| 103 | - intval($this->configuration->ldapPagingSize) !== 0 |
|
| 104 | - || $this->ldap->hasPagedResultSupport(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function __destruct() { |
|
| 108 | - if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 109 | - @$this->ldap->unbind($this->ldapConnectionRes); |
|
| 110 | - }; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * defines behaviour when the instance is cloned |
|
| 115 | - */ |
|
| 116 | - public function __clone() { |
|
| 117 | - $this->configuration = new Configuration($this->configPrefix, |
|
| 118 | - !is_null($this->configID)); |
|
| 119 | - $this->ldapConnectionRes = null; |
|
| 120 | - $this->dontDestruct = true; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @param string $name |
|
| 125 | - * @return bool|mixed|void |
|
| 126 | - */ |
|
| 127 | - public function __get($name) { |
|
| 128 | - if(!$this->configured) { |
|
| 129 | - $this->readConfiguration(); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if($name === 'hasPagedResultSupport') { |
|
| 133 | - return $this->hasPagedResultSupport; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $this->configuration->$name; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param string $name |
|
| 141 | - * @param mixed $value |
|
| 142 | - */ |
|
| 143 | - public function __set($name, $value) { |
|
| 144 | - $this->doNotValidate = false; |
|
| 145 | - $before = $this->configuration->$name; |
|
| 146 | - $this->configuration->$name = $value; |
|
| 147 | - $after = $this->configuration->$name; |
|
| 148 | - if($before !== $after) { |
|
| 149 | - if ($this->configID !== '') { |
|
| 150 | - $this->configuration->saveConfiguration(); |
|
| 151 | - } |
|
| 152 | - $this->validateConfiguration(); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * sets whether the result of the configuration validation shall |
|
| 158 | - * be ignored when establishing the connection. Used by the Wizard |
|
| 159 | - * in early configuration state. |
|
| 160 | - * @param bool $state |
|
| 161 | - */ |
|
| 162 | - public function setIgnoreValidation($state) { |
|
| 163 | - $this->ignoreValidation = (bool)$state; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * initializes the LDAP backend |
|
| 168 | - * @param bool $force read the config settings no matter what |
|
| 169 | - */ |
|
| 170 | - public function init($force = false) { |
|
| 171 | - $this->readConfiguration($force); |
|
| 172 | - $this->establishConnection(); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Returns the LDAP handler |
|
| 177 | - */ |
|
| 178 | - public function getConnectionResource() { |
|
| 179 | - if(!$this->ldapConnectionRes) { |
|
| 180 | - $this->init(); |
|
| 181 | - } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 182 | - $this->ldapConnectionRes = null; |
|
| 183 | - $this->establishConnection(); |
|
| 184 | - } |
|
| 185 | - if(is_null($this->ldapConnectionRes)) { |
|
| 186 | - \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
| 187 | - throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
|
| 188 | - } |
|
| 189 | - return $this->ldapConnectionRes; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * resets the connection resource |
|
| 194 | - */ |
|
| 195 | - public function resetConnectionResource() { |
|
| 196 | - if(!is_null($this->ldapConnectionRes)) { |
|
| 197 | - @$this->ldap->unbind($this->ldapConnectionRes); |
|
| 198 | - $this->ldapConnectionRes = null; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @param string|null $key |
|
| 204 | - * @return string |
|
| 205 | - */ |
|
| 206 | - private function getCacheKey($key) { |
|
| 207 | - $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
|
| 208 | - if(is_null($key)) { |
|
| 209 | - return $prefix; |
|
| 210 | - } |
|
| 211 | - return $prefix.md5($key); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @param string $key |
|
| 216 | - * @return mixed|null |
|
| 217 | - */ |
|
| 218 | - public function getFromCache($key) { |
|
| 219 | - if(!$this->configured) { |
|
| 220 | - $this->readConfiguration(); |
|
| 221 | - } |
|
| 222 | - if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
| 223 | - return null; |
|
| 224 | - } |
|
| 225 | - $key = $this->getCacheKey($key); |
|
| 226 | - |
|
| 227 | - return json_decode(base64_decode($this->cache->get($key)), true); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * @param string $key |
|
| 232 | - * @param mixed $value |
|
| 233 | - * |
|
| 234 | - * @return string |
|
| 235 | - */ |
|
| 236 | - public function writeToCache($key, $value) { |
|
| 237 | - if(!$this->configured) { |
|
| 238 | - $this->readConfiguration(); |
|
| 239 | - } |
|
| 240 | - if(is_null($this->cache) |
|
| 241 | - || !$this->configuration->ldapCacheTTL |
|
| 242 | - || !$this->configuration->ldapConfigurationActive) { |
|
| 243 | - return null; |
|
| 244 | - } |
|
| 245 | - $key = $this->getCacheKey($key); |
|
| 246 | - $value = base64_encode(json_encode($value)); |
|
| 247 | - $this->cache->set($key, $value, $this->configuration->ldapCacheTTL); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - public function clearCache() { |
|
| 251 | - if(!is_null($this->cache)) { |
|
| 252 | - $this->cache->clear($this->getCacheKey(null)); |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Caches the general LDAP configuration. |
|
| 258 | - * @param bool $force optional. true, if the re-read should be forced. defaults |
|
| 259 | - * to false. |
|
| 260 | - * @return null |
|
| 261 | - */ |
|
| 262 | - private function readConfiguration($force = false) { |
|
| 263 | - if((!$this->configured || $force) && !is_null($this->configID)) { |
|
| 264 | - $this->configuration->readConfiguration(); |
|
| 265 | - $this->configured = $this->validateConfiguration(); |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * set LDAP configuration with values delivered by an array, not read from configuration |
|
| 271 | - * @param array $config array that holds the config parameters in an associated array |
|
| 272 | - * @param array &$setParameters optional; array where the set fields will be given to |
|
| 273 | - * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
|
| 274 | - */ |
|
| 275 | - public function setConfiguration($config, &$setParameters = null) { |
|
| 276 | - if(is_null($setParameters)) { |
|
| 277 | - $setParameters = array(); |
|
| 278 | - } |
|
| 279 | - $this->doNotValidate = false; |
|
| 280 | - $this->configuration->setConfiguration($config, $setParameters); |
|
| 281 | - if(count($setParameters) > 0) { |
|
| 282 | - $this->configured = $this->validateConfiguration(); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - return $this->configured; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * saves the current Configuration in the database and empties the |
|
| 291 | - * cache |
|
| 292 | - * @return null |
|
| 293 | - */ |
|
| 294 | - public function saveConfiguration() { |
|
| 295 | - $this->configuration->saveConfiguration(); |
|
| 296 | - $this->clearCache(); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * get the current LDAP configuration |
|
| 301 | - * @return array |
|
| 302 | - */ |
|
| 303 | - public function getConfiguration() { |
|
| 304 | - $this->readConfiguration(); |
|
| 305 | - $config = $this->configuration->getConfiguration(); |
|
| 306 | - $cta = $this->configuration->getConfigTranslationArray(); |
|
| 307 | - $result = array(); |
|
| 308 | - foreach($cta as $dbkey => $configkey) { |
|
| 309 | - switch($configkey) { |
|
| 310 | - case 'homeFolderNamingRule': |
|
| 311 | - if(strpos($config[$configkey], 'attr:') === 0) { |
|
| 312 | - $result[$dbkey] = substr($config[$configkey], 5); |
|
| 313 | - } else { |
|
| 314 | - $result[$dbkey] = ''; |
|
| 315 | - } |
|
| 316 | - break; |
|
| 317 | - case 'ldapBase': |
|
| 318 | - case 'ldapBaseUsers': |
|
| 319 | - case 'ldapBaseGroups': |
|
| 320 | - case 'ldapAttributesForUserSearch': |
|
| 321 | - case 'ldapAttributesForGroupSearch': |
|
| 322 | - if(is_array($config[$configkey])) { |
|
| 323 | - $result[$dbkey] = implode("\n", $config[$configkey]); |
|
| 324 | - break; |
|
| 325 | - } //else follows default |
|
| 326 | - default: |
|
| 327 | - $result[$dbkey] = $config[$configkey]; |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - return $result; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - private function doSoftValidation() { |
|
| 334 | - //if User or Group Base are not set, take over Base DN setting |
|
| 335 | - foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
| 336 | - $val = $this->configuration->$keyBase; |
|
| 337 | - if(empty($val)) { |
|
| 338 | - $this->configuration->$keyBase = $this->configuration->ldapBase; |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
| 343 | - 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
|
| 344 | - as $expertSetting => $effectiveSetting) { |
|
| 345 | - $uuidOverride = $this->configuration->$expertSetting; |
|
| 346 | - if(!empty($uuidOverride)) { |
|
| 347 | - $this->configuration->$effectiveSetting = $uuidOverride; |
|
| 348 | - } else { |
|
| 349 | - $uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid', |
|
| 350 | - 'objectguid', 'guid', 'ipauniqueid'); |
|
| 351 | - if(!in_array($this->configuration->$effectiveSetting, |
|
| 352 | - $uuidAttributes) |
|
| 353 | - && (!is_null($this->configID))) { |
|
| 354 | - $this->configuration->$effectiveSetting = 'auto'; |
|
| 355 | - $this->configuration->saveConfiguration(); |
|
| 356 | - \OCP\Util::writeLog('user_ldap', |
|
| 357 | - 'Illegal value for the '. |
|
| 358 | - $effectiveSetting.', '.'reset to '. |
|
| 359 | - 'autodetect.', \OCP\Util::INFO); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - $backupPort = intval($this->configuration->ldapBackupPort); |
|
| 366 | - if ($backupPort <= 0) { |
|
| 367 | - $this->configuration->backupPort = $this->configuration->ldapPort; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - //make sure empty search attributes are saved as simple, empty array |
|
| 371 | - $saKeys = array('ldapAttributesForUserSearch', |
|
| 372 | - 'ldapAttributesForGroupSearch'); |
|
| 373 | - foreach($saKeys as $key) { |
|
| 374 | - $val = $this->configuration->$key; |
|
| 375 | - if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
| 376 | - $this->configuration->$key = array(); |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
| 381 | - && $this->configuration->ldapTLS) { |
|
| 382 | - $this->configuration->ldapTLS = false; |
|
| 383 | - \OCP\Util::writeLog('user_ldap', |
|
| 384 | - 'LDAPS (already using secure connection) and '. |
|
| 385 | - 'TLS do not work together. Switched off TLS.', |
|
| 386 | - \OCP\Util::INFO); |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * @return bool |
|
| 392 | - */ |
|
| 393 | - private function doCriticalValidation() { |
|
| 394 | - $configurationOK = true; |
|
| 395 | - $errorStr = 'Configuration Error (prefix '. |
|
| 396 | - strval($this->configPrefix).'): '; |
|
| 397 | - |
|
| 398 | - //options that shall not be empty |
|
| 399 | - $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
|
| 400 | - 'ldapGroupDisplayName', 'ldapLoginFilter'); |
|
| 401 | - foreach($options as $key) { |
|
| 402 | - $val = $this->configuration->$key; |
|
| 403 | - if(empty($val)) { |
|
| 404 | - switch($key) { |
|
| 405 | - case 'ldapHost': |
|
| 406 | - $subj = 'LDAP Host'; |
|
| 407 | - break; |
|
| 408 | - case 'ldapPort': |
|
| 409 | - $subj = 'LDAP Port'; |
|
| 410 | - break; |
|
| 411 | - case 'ldapUserDisplayName': |
|
| 412 | - $subj = 'LDAP User Display Name'; |
|
| 413 | - break; |
|
| 414 | - case 'ldapGroupDisplayName': |
|
| 415 | - $subj = 'LDAP Group Display Name'; |
|
| 416 | - break; |
|
| 417 | - case 'ldapLoginFilter': |
|
| 418 | - $subj = 'LDAP Login Filter'; |
|
| 419 | - break; |
|
| 420 | - default: |
|
| 421 | - $subj = $key; |
|
| 422 | - break; |
|
| 423 | - } |
|
| 424 | - $configurationOK = false; |
|
| 425 | - \OCP\Util::writeLog('user_ldap', |
|
| 426 | - $errorStr.'No '.$subj.' given!', |
|
| 427 | - \OCP\Util::WARN); |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - //combinations |
|
| 432 | - $agent = $this->configuration->ldapAgentName; |
|
| 433 | - $pwd = $this->configuration->ldapAgentPassword; |
|
| 434 | - if ( |
|
| 435 | - ($agent === '' && $pwd !== '') |
|
| 436 | - || ($agent !== '' && $pwd === '') |
|
| 437 | - ) { |
|
| 438 | - \OCP\Util::writeLog('user_ldap', |
|
| 439 | - $errorStr.'either no password is given for the'. |
|
| 440 | - 'user agent or a password is given, but not an'. |
|
| 441 | - 'LDAP agent.', |
|
| 442 | - \OCP\Util::WARN); |
|
| 443 | - $configurationOK = false; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - $base = $this->configuration->ldapBase; |
|
| 447 | - $baseUsers = $this->configuration->ldapBaseUsers; |
|
| 448 | - $baseGroups = $this->configuration->ldapBaseGroups; |
|
| 449 | - |
|
| 450 | - if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
| 451 | - \OCP\Util::writeLog('user_ldap', |
|
| 452 | - $errorStr.'Not a single Base DN given.', |
|
| 453 | - \OCP\Util::WARN); |
|
| 454 | - $configurationOK = false; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 458 | - === false) { |
|
| 459 | - \OCP\Util::writeLog('user_ldap', |
|
| 460 | - $errorStr.'login filter does not contain %uid '. |
|
| 461 | - 'place holder.', |
|
| 462 | - \OCP\Util::WARN); |
|
| 463 | - $configurationOK = false; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - return $configurationOK; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Validates the user specified configuration |
|
| 471 | - * @return bool true if configuration seems OK, false otherwise |
|
| 472 | - */ |
|
| 473 | - private function validateConfiguration() { |
|
| 474 | - |
|
| 475 | - if($this->doNotValidate) { |
|
| 476 | - //don't do a validation if it is a new configuration with pure |
|
| 477 | - //default values. Will be allowed on changes via __set or |
|
| 478 | - //setConfiguration |
|
| 479 | - return false; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - // first step: "soft" checks: settings that are not really |
|
| 483 | - // necessary, but advisable. If left empty, give an info message |
|
| 484 | - $this->doSoftValidation(); |
|
| 485 | - |
|
| 486 | - //second step: critical checks. If left empty or filled wrong, mark as |
|
| 487 | - //not configured and give a warning. |
|
| 488 | - return $this->doCriticalValidation(); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * Connects and Binds to LDAP |
|
| 494 | - */ |
|
| 495 | - private function establishConnection() { |
|
| 496 | - if(!$this->configuration->ldapConfigurationActive) { |
|
| 497 | - return null; |
|
| 498 | - } |
|
| 499 | - static $phpLDAPinstalled = true; |
|
| 500 | - if(!$phpLDAPinstalled) { |
|
| 501 | - return false; |
|
| 502 | - } |
|
| 503 | - if(!$this->ignoreValidation && !$this->configured) { |
|
| 504 | - \OCP\Util::writeLog('user_ldap', |
|
| 505 | - 'Configuration is invalid, cannot connect', |
|
| 506 | - \OCP\Util::WARN); |
|
| 507 | - return false; |
|
| 508 | - } |
|
| 509 | - if(!$this->ldapConnectionRes) { |
|
| 510 | - if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
| 511 | - $phpLDAPinstalled = false; |
|
| 512 | - \OCP\Util::writeLog('user_ldap', |
|
| 513 | - 'function ldap_connect is not available. Make '. |
|
| 514 | - 'sure that the PHP ldap module is installed.', |
|
| 515 | - \OCP\Util::ERROR); |
|
| 516 | - |
|
| 517 | - return false; |
|
| 518 | - } |
|
| 519 | - if($this->configuration->turnOffCertCheck) { |
|
| 520 | - if(putenv('LDAPTLS_REQCERT=never')) { |
|
| 521 | - \OCP\Util::writeLog('user_ldap', |
|
| 522 | - 'Turned off SSL certificate validation successfully.', |
|
| 523 | - \OCP\Util::DEBUG); |
|
| 524 | - } else { |
|
| 525 | - \OCP\Util::writeLog('user_ldap', |
|
| 526 | - 'Could not turn off SSL certificate validation.', |
|
| 527 | - \OCP\Util::WARN); |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - $bindStatus = false; |
|
| 532 | - $error = -1; |
|
| 533 | - try { |
|
| 534 | - if (!$this->configuration->ldapOverrideMainServer |
|
| 535 | - && !$this->getFromCache('overrideMainServer') |
|
| 536 | - ) { |
|
| 537 | - $this->doConnect($this->configuration->ldapHost, |
|
| 538 | - $this->configuration->ldapPort); |
|
| 539 | - $bindStatus = $this->bind(); |
|
| 540 | - $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
|
| 541 | - $this->ldap->errno($this->ldapConnectionRes) : -1; |
|
| 542 | - } |
|
| 543 | - if($bindStatus === true) { |
|
| 544 | - return $bindStatus; |
|
| 545 | - } |
|
| 546 | - } catch (\OC\ServerNotAvailableException $e) { |
|
| 547 | - if(trim($this->configuration->ldapBackupHost) === "") { |
|
| 548 | - throw $e; |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - //if LDAP server is not reachable, try the Backup (Replica!) Server |
|
| 553 | - if( $error !== 0 |
|
| 554 | - || $this->configuration->ldapOverrideMainServer |
|
| 555 | - || $this->getFromCache('overrideMainServer')) |
|
| 556 | - { |
|
| 557 | - $this->doConnect($this->configuration->ldapBackupHost, |
|
| 558 | - $this->configuration->ldapBackupPort); |
|
| 559 | - $bindStatus = $this->bind(); |
|
| 560 | - if($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { |
|
| 561 | - //when bind to backup server succeeded and failed to main server, |
|
| 562 | - //skip contacting him until next cache refresh |
|
| 563 | - $this->writeToCache('overrideMainServer', true); |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - return $bindStatus; |
|
| 567 | - } |
|
| 568 | - return null; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * @param string $host |
|
| 573 | - * @param string $port |
|
| 574 | - * @return bool |
|
| 575 | - * @throws \OC\ServerNotAvailableException |
|
| 576 | - */ |
|
| 577 | - private function doConnect($host, $port) { |
|
| 578 | - if ($host === '') { |
|
| 579 | - return false; |
|
| 580 | - } |
|
| 581 | - $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
|
| 582 | - if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
| 583 | - if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
| 584 | - if($this->configuration->ldapTLS) { |
|
| 585 | - $this->ldap->startTls($this->ldapConnectionRes); |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - } else { |
|
| 589 | - throw new \OC\ServerNotAvailableException('Could not set required LDAP Protocol version.'); |
|
| 590 | - } |
|
| 591 | - return true; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * Binds to LDAP |
|
| 596 | - */ |
|
| 597 | - public function bind() { |
|
| 598 | - static $getConnectionResourceAttempt = false; |
|
| 599 | - if(!$this->configuration->ldapConfigurationActive) { |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - if($getConnectionResourceAttempt) { |
|
| 603 | - $getConnectionResourceAttempt = false; |
|
| 604 | - return false; |
|
| 605 | - } |
|
| 606 | - $getConnectionResourceAttempt = true; |
|
| 607 | - $cr = $this->getConnectionResource(); |
|
| 608 | - $getConnectionResourceAttempt = false; |
|
| 609 | - if(!$this->ldap->isResource($cr)) { |
|
| 610 | - return false; |
|
| 611 | - } |
|
| 612 | - $ldapLogin = @$this->ldap->bind($cr, |
|
| 613 | - $this->configuration->ldapAgentName, |
|
| 614 | - $this->configuration->ldapAgentPassword); |
|
| 615 | - if(!$ldapLogin) { |
|
| 616 | - \OCP\Util::writeLog('user_ldap', |
|
| 617 | - 'Bind failed: ' . $this->ldap->errno($cr) . ': ' . $this->ldap->error($cr), |
|
| 618 | - \OCP\Util::WARN); |
|
| 619 | - $this->ldapConnectionRes = null; |
|
| 620 | - return false; |
|
| 621 | - } |
|
| 622 | - return true; |
|
| 623 | - } |
|
| 55 | + private $ldapConnectionRes = null; |
|
| 56 | + private $configPrefix; |
|
| 57 | + private $configID; |
|
| 58 | + private $configured = false; |
|
| 59 | + private $hasPagedResultSupport = true; |
|
| 60 | + //whether connection should be kept on __destruct |
|
| 61 | + private $dontDestruct = false; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var bool runtime flag that indicates whether supported primary groups are available |
|
| 65 | + */ |
|
| 66 | + public $hasPrimaryGroups = true; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var bool runtime flag that indicates whether supported POSIX gidNumber are available |
|
| 70 | + */ |
|
| 71 | + public $hasGidNumber = true; |
|
| 72 | + |
|
| 73 | + //cache handler |
|
| 74 | + protected $cache; |
|
| 75 | + |
|
| 76 | + /** @var Configuration settings handler **/ |
|
| 77 | + protected $configuration; |
|
| 78 | + |
|
| 79 | + protected $doNotValidate = false; |
|
| 80 | + |
|
| 81 | + protected $ignoreValidation = false; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Constructor |
|
| 85 | + * @param ILDAPWrapper $ldap |
|
| 86 | + * @param string $configPrefix a string with the prefix for the configkey column (appconfig table) |
|
| 87 | + * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections |
|
| 88 | + */ |
|
| 89 | + public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') { |
|
| 90 | + parent::__construct($ldap); |
|
| 91 | + $this->configPrefix = $configPrefix; |
|
| 92 | + $this->configID = $configID; |
|
| 93 | + $this->configuration = new Configuration($configPrefix, |
|
| 94 | + !is_null($configID)); |
|
| 95 | + $memcache = \OC::$server->getMemCacheFactory(); |
|
| 96 | + if($memcache->isAvailable()) { |
|
| 97 | + $this->cache = $memcache->create(); |
|
| 98 | + } |
|
| 99 | + $helper = new Helper(\OC::$server->getConfig()); |
|
| 100 | + $this->doNotValidate = !in_array($this->configPrefix, |
|
| 101 | + $helper->getServerConfigurationPrefixes()); |
|
| 102 | + $this->hasPagedResultSupport = |
|
| 103 | + intval($this->configuration->ldapPagingSize) !== 0 |
|
| 104 | + || $this->ldap->hasPagedResultSupport(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + public function __destruct() { |
|
| 108 | + if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 109 | + @$this->ldap->unbind($this->ldapConnectionRes); |
|
| 110 | + }; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * defines behaviour when the instance is cloned |
|
| 115 | + */ |
|
| 116 | + public function __clone() { |
|
| 117 | + $this->configuration = new Configuration($this->configPrefix, |
|
| 118 | + !is_null($this->configID)); |
|
| 119 | + $this->ldapConnectionRes = null; |
|
| 120 | + $this->dontDestruct = true; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @param string $name |
|
| 125 | + * @return bool|mixed|void |
|
| 126 | + */ |
|
| 127 | + public function __get($name) { |
|
| 128 | + if(!$this->configured) { |
|
| 129 | + $this->readConfiguration(); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if($name === 'hasPagedResultSupport') { |
|
| 133 | + return $this->hasPagedResultSupport; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $this->configuration->$name; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param string $name |
|
| 141 | + * @param mixed $value |
|
| 142 | + */ |
|
| 143 | + public function __set($name, $value) { |
|
| 144 | + $this->doNotValidate = false; |
|
| 145 | + $before = $this->configuration->$name; |
|
| 146 | + $this->configuration->$name = $value; |
|
| 147 | + $after = $this->configuration->$name; |
|
| 148 | + if($before !== $after) { |
|
| 149 | + if ($this->configID !== '') { |
|
| 150 | + $this->configuration->saveConfiguration(); |
|
| 151 | + } |
|
| 152 | + $this->validateConfiguration(); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * sets whether the result of the configuration validation shall |
|
| 158 | + * be ignored when establishing the connection. Used by the Wizard |
|
| 159 | + * in early configuration state. |
|
| 160 | + * @param bool $state |
|
| 161 | + */ |
|
| 162 | + public function setIgnoreValidation($state) { |
|
| 163 | + $this->ignoreValidation = (bool)$state; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * initializes the LDAP backend |
|
| 168 | + * @param bool $force read the config settings no matter what |
|
| 169 | + */ |
|
| 170 | + public function init($force = false) { |
|
| 171 | + $this->readConfiguration($force); |
|
| 172 | + $this->establishConnection(); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Returns the LDAP handler |
|
| 177 | + */ |
|
| 178 | + public function getConnectionResource() { |
|
| 179 | + if(!$this->ldapConnectionRes) { |
|
| 180 | + $this->init(); |
|
| 181 | + } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 182 | + $this->ldapConnectionRes = null; |
|
| 183 | + $this->establishConnection(); |
|
| 184 | + } |
|
| 185 | + if(is_null($this->ldapConnectionRes)) { |
|
| 186 | + \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
| 187 | + throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
|
| 188 | + } |
|
| 189 | + return $this->ldapConnectionRes; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * resets the connection resource |
|
| 194 | + */ |
|
| 195 | + public function resetConnectionResource() { |
|
| 196 | + if(!is_null($this->ldapConnectionRes)) { |
|
| 197 | + @$this->ldap->unbind($this->ldapConnectionRes); |
|
| 198 | + $this->ldapConnectionRes = null; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @param string|null $key |
|
| 204 | + * @return string |
|
| 205 | + */ |
|
| 206 | + private function getCacheKey($key) { |
|
| 207 | + $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
|
| 208 | + if(is_null($key)) { |
|
| 209 | + return $prefix; |
|
| 210 | + } |
|
| 211 | + return $prefix.md5($key); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @param string $key |
|
| 216 | + * @return mixed|null |
|
| 217 | + */ |
|
| 218 | + public function getFromCache($key) { |
|
| 219 | + if(!$this->configured) { |
|
| 220 | + $this->readConfiguration(); |
|
| 221 | + } |
|
| 222 | + if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
| 223 | + return null; |
|
| 224 | + } |
|
| 225 | + $key = $this->getCacheKey($key); |
|
| 226 | + |
|
| 227 | + return json_decode(base64_decode($this->cache->get($key)), true); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * @param string $key |
|
| 232 | + * @param mixed $value |
|
| 233 | + * |
|
| 234 | + * @return string |
|
| 235 | + */ |
|
| 236 | + public function writeToCache($key, $value) { |
|
| 237 | + if(!$this->configured) { |
|
| 238 | + $this->readConfiguration(); |
|
| 239 | + } |
|
| 240 | + if(is_null($this->cache) |
|
| 241 | + || !$this->configuration->ldapCacheTTL |
|
| 242 | + || !$this->configuration->ldapConfigurationActive) { |
|
| 243 | + return null; |
|
| 244 | + } |
|
| 245 | + $key = $this->getCacheKey($key); |
|
| 246 | + $value = base64_encode(json_encode($value)); |
|
| 247 | + $this->cache->set($key, $value, $this->configuration->ldapCacheTTL); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + public function clearCache() { |
|
| 251 | + if(!is_null($this->cache)) { |
|
| 252 | + $this->cache->clear($this->getCacheKey(null)); |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Caches the general LDAP configuration. |
|
| 258 | + * @param bool $force optional. true, if the re-read should be forced. defaults |
|
| 259 | + * to false. |
|
| 260 | + * @return null |
|
| 261 | + */ |
|
| 262 | + private function readConfiguration($force = false) { |
|
| 263 | + if((!$this->configured || $force) && !is_null($this->configID)) { |
|
| 264 | + $this->configuration->readConfiguration(); |
|
| 265 | + $this->configured = $this->validateConfiguration(); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * set LDAP configuration with values delivered by an array, not read from configuration |
|
| 271 | + * @param array $config array that holds the config parameters in an associated array |
|
| 272 | + * @param array &$setParameters optional; array where the set fields will be given to |
|
| 273 | + * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
|
| 274 | + */ |
|
| 275 | + public function setConfiguration($config, &$setParameters = null) { |
|
| 276 | + if(is_null($setParameters)) { |
|
| 277 | + $setParameters = array(); |
|
| 278 | + } |
|
| 279 | + $this->doNotValidate = false; |
|
| 280 | + $this->configuration->setConfiguration($config, $setParameters); |
|
| 281 | + if(count($setParameters) > 0) { |
|
| 282 | + $this->configured = $this->validateConfiguration(); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + return $this->configured; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * saves the current Configuration in the database and empties the |
|
| 291 | + * cache |
|
| 292 | + * @return null |
|
| 293 | + */ |
|
| 294 | + public function saveConfiguration() { |
|
| 295 | + $this->configuration->saveConfiguration(); |
|
| 296 | + $this->clearCache(); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * get the current LDAP configuration |
|
| 301 | + * @return array |
|
| 302 | + */ |
|
| 303 | + public function getConfiguration() { |
|
| 304 | + $this->readConfiguration(); |
|
| 305 | + $config = $this->configuration->getConfiguration(); |
|
| 306 | + $cta = $this->configuration->getConfigTranslationArray(); |
|
| 307 | + $result = array(); |
|
| 308 | + foreach($cta as $dbkey => $configkey) { |
|
| 309 | + switch($configkey) { |
|
| 310 | + case 'homeFolderNamingRule': |
|
| 311 | + if(strpos($config[$configkey], 'attr:') === 0) { |
|
| 312 | + $result[$dbkey] = substr($config[$configkey], 5); |
|
| 313 | + } else { |
|
| 314 | + $result[$dbkey] = ''; |
|
| 315 | + } |
|
| 316 | + break; |
|
| 317 | + case 'ldapBase': |
|
| 318 | + case 'ldapBaseUsers': |
|
| 319 | + case 'ldapBaseGroups': |
|
| 320 | + case 'ldapAttributesForUserSearch': |
|
| 321 | + case 'ldapAttributesForGroupSearch': |
|
| 322 | + if(is_array($config[$configkey])) { |
|
| 323 | + $result[$dbkey] = implode("\n", $config[$configkey]); |
|
| 324 | + break; |
|
| 325 | + } //else follows default |
|
| 326 | + default: |
|
| 327 | + $result[$dbkey] = $config[$configkey]; |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + return $result; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + private function doSoftValidation() { |
|
| 334 | + //if User or Group Base are not set, take over Base DN setting |
|
| 335 | + foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
| 336 | + $val = $this->configuration->$keyBase; |
|
| 337 | + if(empty($val)) { |
|
| 338 | + $this->configuration->$keyBase = $this->configuration->ldapBase; |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
| 343 | + 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
|
| 344 | + as $expertSetting => $effectiveSetting) { |
|
| 345 | + $uuidOverride = $this->configuration->$expertSetting; |
|
| 346 | + if(!empty($uuidOverride)) { |
|
| 347 | + $this->configuration->$effectiveSetting = $uuidOverride; |
|
| 348 | + } else { |
|
| 349 | + $uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid', |
|
| 350 | + 'objectguid', 'guid', 'ipauniqueid'); |
|
| 351 | + if(!in_array($this->configuration->$effectiveSetting, |
|
| 352 | + $uuidAttributes) |
|
| 353 | + && (!is_null($this->configID))) { |
|
| 354 | + $this->configuration->$effectiveSetting = 'auto'; |
|
| 355 | + $this->configuration->saveConfiguration(); |
|
| 356 | + \OCP\Util::writeLog('user_ldap', |
|
| 357 | + 'Illegal value for the '. |
|
| 358 | + $effectiveSetting.', '.'reset to '. |
|
| 359 | + 'autodetect.', \OCP\Util::INFO); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + $backupPort = intval($this->configuration->ldapBackupPort); |
|
| 366 | + if ($backupPort <= 0) { |
|
| 367 | + $this->configuration->backupPort = $this->configuration->ldapPort; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + //make sure empty search attributes are saved as simple, empty array |
|
| 371 | + $saKeys = array('ldapAttributesForUserSearch', |
|
| 372 | + 'ldapAttributesForGroupSearch'); |
|
| 373 | + foreach($saKeys as $key) { |
|
| 374 | + $val = $this->configuration->$key; |
|
| 375 | + if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
| 376 | + $this->configuration->$key = array(); |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
| 381 | + && $this->configuration->ldapTLS) { |
|
| 382 | + $this->configuration->ldapTLS = false; |
|
| 383 | + \OCP\Util::writeLog('user_ldap', |
|
| 384 | + 'LDAPS (already using secure connection) and '. |
|
| 385 | + 'TLS do not work together. Switched off TLS.', |
|
| 386 | + \OCP\Util::INFO); |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * @return bool |
|
| 392 | + */ |
|
| 393 | + private function doCriticalValidation() { |
|
| 394 | + $configurationOK = true; |
|
| 395 | + $errorStr = 'Configuration Error (prefix '. |
|
| 396 | + strval($this->configPrefix).'): '; |
|
| 397 | + |
|
| 398 | + //options that shall not be empty |
|
| 399 | + $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
|
| 400 | + 'ldapGroupDisplayName', 'ldapLoginFilter'); |
|
| 401 | + foreach($options as $key) { |
|
| 402 | + $val = $this->configuration->$key; |
|
| 403 | + if(empty($val)) { |
|
| 404 | + switch($key) { |
|
| 405 | + case 'ldapHost': |
|
| 406 | + $subj = 'LDAP Host'; |
|
| 407 | + break; |
|
| 408 | + case 'ldapPort': |
|
| 409 | + $subj = 'LDAP Port'; |
|
| 410 | + break; |
|
| 411 | + case 'ldapUserDisplayName': |
|
| 412 | + $subj = 'LDAP User Display Name'; |
|
| 413 | + break; |
|
| 414 | + case 'ldapGroupDisplayName': |
|
| 415 | + $subj = 'LDAP Group Display Name'; |
|
| 416 | + break; |
|
| 417 | + case 'ldapLoginFilter': |
|
| 418 | + $subj = 'LDAP Login Filter'; |
|
| 419 | + break; |
|
| 420 | + default: |
|
| 421 | + $subj = $key; |
|
| 422 | + break; |
|
| 423 | + } |
|
| 424 | + $configurationOK = false; |
|
| 425 | + \OCP\Util::writeLog('user_ldap', |
|
| 426 | + $errorStr.'No '.$subj.' given!', |
|
| 427 | + \OCP\Util::WARN); |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + //combinations |
|
| 432 | + $agent = $this->configuration->ldapAgentName; |
|
| 433 | + $pwd = $this->configuration->ldapAgentPassword; |
|
| 434 | + if ( |
|
| 435 | + ($agent === '' && $pwd !== '') |
|
| 436 | + || ($agent !== '' && $pwd === '') |
|
| 437 | + ) { |
|
| 438 | + \OCP\Util::writeLog('user_ldap', |
|
| 439 | + $errorStr.'either no password is given for the'. |
|
| 440 | + 'user agent or a password is given, but not an'. |
|
| 441 | + 'LDAP agent.', |
|
| 442 | + \OCP\Util::WARN); |
|
| 443 | + $configurationOK = false; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + $base = $this->configuration->ldapBase; |
|
| 447 | + $baseUsers = $this->configuration->ldapBaseUsers; |
|
| 448 | + $baseGroups = $this->configuration->ldapBaseGroups; |
|
| 449 | + |
|
| 450 | + if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
| 451 | + \OCP\Util::writeLog('user_ldap', |
|
| 452 | + $errorStr.'Not a single Base DN given.', |
|
| 453 | + \OCP\Util::WARN); |
|
| 454 | + $configurationOK = false; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 458 | + === false) { |
|
| 459 | + \OCP\Util::writeLog('user_ldap', |
|
| 460 | + $errorStr.'login filter does not contain %uid '. |
|
| 461 | + 'place holder.', |
|
| 462 | + \OCP\Util::WARN); |
|
| 463 | + $configurationOK = false; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + return $configurationOK; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Validates the user specified configuration |
|
| 471 | + * @return bool true if configuration seems OK, false otherwise |
|
| 472 | + */ |
|
| 473 | + private function validateConfiguration() { |
|
| 474 | + |
|
| 475 | + if($this->doNotValidate) { |
|
| 476 | + //don't do a validation if it is a new configuration with pure |
|
| 477 | + //default values. Will be allowed on changes via __set or |
|
| 478 | + //setConfiguration |
|
| 479 | + return false; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + // first step: "soft" checks: settings that are not really |
|
| 483 | + // necessary, but advisable. If left empty, give an info message |
|
| 484 | + $this->doSoftValidation(); |
|
| 485 | + |
|
| 486 | + //second step: critical checks. If left empty or filled wrong, mark as |
|
| 487 | + //not configured and give a warning. |
|
| 488 | + return $this->doCriticalValidation(); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * Connects and Binds to LDAP |
|
| 494 | + */ |
|
| 495 | + private function establishConnection() { |
|
| 496 | + if(!$this->configuration->ldapConfigurationActive) { |
|
| 497 | + return null; |
|
| 498 | + } |
|
| 499 | + static $phpLDAPinstalled = true; |
|
| 500 | + if(!$phpLDAPinstalled) { |
|
| 501 | + return false; |
|
| 502 | + } |
|
| 503 | + if(!$this->ignoreValidation && !$this->configured) { |
|
| 504 | + \OCP\Util::writeLog('user_ldap', |
|
| 505 | + 'Configuration is invalid, cannot connect', |
|
| 506 | + \OCP\Util::WARN); |
|
| 507 | + return false; |
|
| 508 | + } |
|
| 509 | + if(!$this->ldapConnectionRes) { |
|
| 510 | + if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
| 511 | + $phpLDAPinstalled = false; |
|
| 512 | + \OCP\Util::writeLog('user_ldap', |
|
| 513 | + 'function ldap_connect is not available. Make '. |
|
| 514 | + 'sure that the PHP ldap module is installed.', |
|
| 515 | + \OCP\Util::ERROR); |
|
| 516 | + |
|
| 517 | + return false; |
|
| 518 | + } |
|
| 519 | + if($this->configuration->turnOffCertCheck) { |
|
| 520 | + if(putenv('LDAPTLS_REQCERT=never')) { |
|
| 521 | + \OCP\Util::writeLog('user_ldap', |
|
| 522 | + 'Turned off SSL certificate validation successfully.', |
|
| 523 | + \OCP\Util::DEBUG); |
|
| 524 | + } else { |
|
| 525 | + \OCP\Util::writeLog('user_ldap', |
|
| 526 | + 'Could not turn off SSL certificate validation.', |
|
| 527 | + \OCP\Util::WARN); |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + $bindStatus = false; |
|
| 532 | + $error = -1; |
|
| 533 | + try { |
|
| 534 | + if (!$this->configuration->ldapOverrideMainServer |
|
| 535 | + && !$this->getFromCache('overrideMainServer') |
|
| 536 | + ) { |
|
| 537 | + $this->doConnect($this->configuration->ldapHost, |
|
| 538 | + $this->configuration->ldapPort); |
|
| 539 | + $bindStatus = $this->bind(); |
|
| 540 | + $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
|
| 541 | + $this->ldap->errno($this->ldapConnectionRes) : -1; |
|
| 542 | + } |
|
| 543 | + if($bindStatus === true) { |
|
| 544 | + return $bindStatus; |
|
| 545 | + } |
|
| 546 | + } catch (\OC\ServerNotAvailableException $e) { |
|
| 547 | + if(trim($this->configuration->ldapBackupHost) === "") { |
|
| 548 | + throw $e; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + //if LDAP server is not reachable, try the Backup (Replica!) Server |
|
| 553 | + if( $error !== 0 |
|
| 554 | + || $this->configuration->ldapOverrideMainServer |
|
| 555 | + || $this->getFromCache('overrideMainServer')) |
|
| 556 | + { |
|
| 557 | + $this->doConnect($this->configuration->ldapBackupHost, |
|
| 558 | + $this->configuration->ldapBackupPort); |
|
| 559 | + $bindStatus = $this->bind(); |
|
| 560 | + if($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { |
|
| 561 | + //when bind to backup server succeeded and failed to main server, |
|
| 562 | + //skip contacting him until next cache refresh |
|
| 563 | + $this->writeToCache('overrideMainServer', true); |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + return $bindStatus; |
|
| 567 | + } |
|
| 568 | + return null; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * @param string $host |
|
| 573 | + * @param string $port |
|
| 574 | + * @return bool |
|
| 575 | + * @throws \OC\ServerNotAvailableException |
|
| 576 | + */ |
|
| 577 | + private function doConnect($host, $port) { |
|
| 578 | + if ($host === '') { |
|
| 579 | + return false; |
|
| 580 | + } |
|
| 581 | + $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
|
| 582 | + if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
| 583 | + if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
| 584 | + if($this->configuration->ldapTLS) { |
|
| 585 | + $this->ldap->startTls($this->ldapConnectionRes); |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + } else { |
|
| 589 | + throw new \OC\ServerNotAvailableException('Could not set required LDAP Protocol version.'); |
|
| 590 | + } |
|
| 591 | + return true; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * Binds to LDAP |
|
| 596 | + */ |
|
| 597 | + public function bind() { |
|
| 598 | + static $getConnectionResourceAttempt = false; |
|
| 599 | + if(!$this->configuration->ldapConfigurationActive) { |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + if($getConnectionResourceAttempt) { |
|
| 603 | + $getConnectionResourceAttempt = false; |
|
| 604 | + return false; |
|
| 605 | + } |
|
| 606 | + $getConnectionResourceAttempt = true; |
|
| 607 | + $cr = $this->getConnectionResource(); |
|
| 608 | + $getConnectionResourceAttempt = false; |
|
| 609 | + if(!$this->ldap->isResource($cr)) { |
|
| 610 | + return false; |
|
| 611 | + } |
|
| 612 | + $ldapLogin = @$this->ldap->bind($cr, |
|
| 613 | + $this->configuration->ldapAgentName, |
|
| 614 | + $this->configuration->ldapAgentPassword); |
|
| 615 | + if(!$ldapLogin) { |
|
| 616 | + \OCP\Util::writeLog('user_ldap', |
|
| 617 | + 'Bind failed: ' . $this->ldap->errno($cr) . ': ' . $this->ldap->error($cr), |
|
| 618 | + \OCP\Util::WARN); |
|
| 619 | + $this->ldapConnectionRes = null; |
|
| 620 | + return false; |
|
| 621 | + } |
|
| 622 | + return true; |
|
| 623 | + } |
|
| 624 | 624 | |
| 625 | 625 | } |
@@ -33,155 +33,155 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport { |
| 35 | 35 | |
| 36 | - private $backend; |
|
| 37 | - private $logger; |
|
| 38 | - private $helper; |
|
| 39 | - private $deletedUsersIndex; |
|
| 36 | + private $backend; |
|
| 37 | + private $logger; |
|
| 38 | + private $helper; |
|
| 39 | + private $deletedUsersIndex; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Create new LDAPProvider |
|
| 43 | - * @param \OCP\IServerContainer $serverContainer |
|
| 44 | - * @throws \Exception if user_ldap app was not enabled |
|
| 45 | - */ |
|
| 46 | - public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) { |
|
| 47 | - $this->logger = $serverContainer->getLogger(); |
|
| 48 | - $this->helper = $helper; |
|
| 49 | - $this->deletedUsersIndex = $deletedUsersIndex; |
|
| 50 | - foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
| 51 | - $this->logger->debug('instance '.get_class($backend).' backend.', ['app' => 'user_ldap']); |
|
| 52 | - if ($backend instanceof IUserLDAP) { |
|
| 53 | - $this->backend = $backend; |
|
| 54 | - return; |
|
| 55 | - } |
|
| 41 | + /** |
|
| 42 | + * Create new LDAPProvider |
|
| 43 | + * @param \OCP\IServerContainer $serverContainer |
|
| 44 | + * @throws \Exception if user_ldap app was not enabled |
|
| 45 | + */ |
|
| 46 | + public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) { |
|
| 47 | + $this->logger = $serverContainer->getLogger(); |
|
| 48 | + $this->helper = $helper; |
|
| 49 | + $this->deletedUsersIndex = $deletedUsersIndex; |
|
| 50 | + foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
| 51 | + $this->logger->debug('instance '.get_class($backend).' backend.', ['app' => 'user_ldap']); |
|
| 52 | + if ($backend instanceof IUserLDAP) { |
|
| 53 | + $this->backend = $backend; |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | 56 | } |
| 57 | - throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled'); |
|
| 58 | - } |
|
| 57 | + throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled'); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Translate an user id to LDAP DN |
|
| 62 | - * @param string $uid user id |
|
| 63 | - * @return string with the LDAP DN |
|
| 64 | - * @throws \Exception if translation was unsuccessful |
|
| 65 | - */ |
|
| 66 | - public function getUserDN($uid) { |
|
| 67 | - if(!$this->backend->userExists($uid)){ |
|
| 68 | - throw new \Exception('User id not found in LDAP'); |
|
| 69 | - } |
|
| 70 | - $result = $this->backend->getLDAPAccess($uid)->username2dn($uid); |
|
| 71 | - if(!$result){ |
|
| 72 | - throw new \Exception('Translation to LDAP DN unsuccessful'); |
|
| 73 | - } |
|
| 74 | - return $result; |
|
| 75 | - } |
|
| 60 | + /** |
|
| 61 | + * Translate an user id to LDAP DN |
|
| 62 | + * @param string $uid user id |
|
| 63 | + * @return string with the LDAP DN |
|
| 64 | + * @throws \Exception if translation was unsuccessful |
|
| 65 | + */ |
|
| 66 | + public function getUserDN($uid) { |
|
| 67 | + if(!$this->backend->userExists($uid)){ |
|
| 68 | + throw new \Exception('User id not found in LDAP'); |
|
| 69 | + } |
|
| 70 | + $result = $this->backend->getLDAPAccess($uid)->username2dn($uid); |
|
| 71 | + if(!$result){ |
|
| 72 | + throw new \Exception('Translation to LDAP DN unsuccessful'); |
|
| 73 | + } |
|
| 74 | + return $result; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Translate a LDAP DN to an internal user name. If there is no mapping between |
|
| 79 | - * the DN and the user name, a new one will be created. |
|
| 80 | - * @param string $dn LDAP DN |
|
| 81 | - * @return string with the internal user name |
|
| 82 | - * @throws \Exception if translation was unsuccessful |
|
| 83 | - */ |
|
| 84 | - public function getUserName($dn) { |
|
| 85 | - $result = $this->backend->dn2UserName($dn); |
|
| 86 | - if(!$result){ |
|
| 87 | - throw new \Exception('Translation to internal user name unsuccessful'); |
|
| 88 | - } |
|
| 89 | - return $result; |
|
| 90 | - } |
|
| 77 | + /** |
|
| 78 | + * Translate a LDAP DN to an internal user name. If there is no mapping between |
|
| 79 | + * the DN and the user name, a new one will be created. |
|
| 80 | + * @param string $dn LDAP DN |
|
| 81 | + * @return string with the internal user name |
|
| 82 | + * @throws \Exception if translation was unsuccessful |
|
| 83 | + */ |
|
| 84 | + public function getUserName($dn) { |
|
| 85 | + $result = $this->backend->dn2UserName($dn); |
|
| 86 | + if(!$result){ |
|
| 87 | + throw new \Exception('Translation to internal user name unsuccessful'); |
|
| 88 | + } |
|
| 89 | + return $result; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Convert a stored DN so it can be used as base parameter for LDAP queries. |
|
| 94 | - * @param string $dn the DN in question |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function DNasBaseParameter($dn) { |
|
| 98 | - return $this->helper->DNasBaseParameter($dn); |
|
| 99 | - } |
|
| 92 | + /** |
|
| 93 | + * Convert a stored DN so it can be used as base parameter for LDAP queries. |
|
| 94 | + * @param string $dn the DN in question |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function DNasBaseParameter($dn) { |
|
| 98 | + return $this->helper->DNasBaseParameter($dn); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Sanitize a DN received from the LDAP server. |
|
| 103 | - * @param array $dn the DN in question |
|
| 104 | - * @return array the sanitized DN |
|
| 105 | - */ |
|
| 106 | - public function sanitizeDN($dn) { |
|
| 107 | - return $this->helper->sanitizeDN($dn); |
|
| 108 | - } |
|
| 101 | + /** |
|
| 102 | + * Sanitize a DN received from the LDAP server. |
|
| 103 | + * @param array $dn the DN in question |
|
| 104 | + * @return array the sanitized DN |
|
| 105 | + */ |
|
| 106 | + public function sanitizeDN($dn) { |
|
| 107 | + return $this->helper->sanitizeDN($dn); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Return a new LDAP connection resource for the specified user. |
|
| 112 | - * The connection must be closed manually. |
|
| 113 | - * @param string $uid user id |
|
| 114 | - * @return resource of the LDAP connection |
|
| 115 | - * @throws \Exception if user id was not found in LDAP |
|
| 116 | - */ |
|
| 117 | - public function getLDAPConnection($uid) { |
|
| 118 | - if(!$this->backend->userExists($uid)){ |
|
| 119 | - throw new \Exception('User id not found in LDAP'); |
|
| 120 | - } |
|
| 121 | - return $this->backend->getNewLDAPConnection($uid); |
|
| 122 | - } |
|
| 110 | + /** |
|
| 111 | + * Return a new LDAP connection resource for the specified user. |
|
| 112 | + * The connection must be closed manually. |
|
| 113 | + * @param string $uid user id |
|
| 114 | + * @return resource of the LDAP connection |
|
| 115 | + * @throws \Exception if user id was not found in LDAP |
|
| 116 | + */ |
|
| 117 | + public function getLDAPConnection($uid) { |
|
| 118 | + if(!$this->backend->userExists($uid)){ |
|
| 119 | + throw new \Exception('User id not found in LDAP'); |
|
| 120 | + } |
|
| 121 | + return $this->backend->getNewLDAPConnection($uid); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Get the LDAP base for users. |
|
| 126 | - * @param string $uid user id |
|
| 127 | - * @return string the base for users |
|
| 128 | - * @throws \Exception if user id was not found in LDAP |
|
| 129 | - */ |
|
| 130 | - public function getLDAPBaseUsers($uid) { |
|
| 131 | - if(!$this->backend->userExists($uid)){ |
|
| 132 | - throw new \Exception('User id not found in LDAP'); |
|
| 133 | - } |
|
| 134 | - return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users']; |
|
| 135 | - } |
|
| 124 | + /** |
|
| 125 | + * Get the LDAP base for users. |
|
| 126 | + * @param string $uid user id |
|
| 127 | + * @return string the base for users |
|
| 128 | + * @throws \Exception if user id was not found in LDAP |
|
| 129 | + */ |
|
| 130 | + public function getLDAPBaseUsers($uid) { |
|
| 131 | + if(!$this->backend->userExists($uid)){ |
|
| 132 | + throw new \Exception('User id not found in LDAP'); |
|
| 133 | + } |
|
| 134 | + return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users']; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Get the LDAP base for groups. |
|
| 139 | - * @param string $uid user id |
|
| 140 | - * @return string the base for groups |
|
| 141 | - * @throws \Exception if user id was not found in LDAP |
|
| 142 | - */ |
|
| 143 | - public function getLDAPBaseGroups($uid) { |
|
| 144 | - if(!$this->backend->userExists($uid)){ |
|
| 145 | - throw new \Exception('User id not found in LDAP'); |
|
| 146 | - } |
|
| 147 | - return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups']; |
|
| 148 | - } |
|
| 137 | + /** |
|
| 138 | + * Get the LDAP base for groups. |
|
| 139 | + * @param string $uid user id |
|
| 140 | + * @return string the base for groups |
|
| 141 | + * @throws \Exception if user id was not found in LDAP |
|
| 142 | + */ |
|
| 143 | + public function getLDAPBaseGroups($uid) { |
|
| 144 | + if(!$this->backend->userExists($uid)){ |
|
| 145 | + throw new \Exception('User id not found in LDAP'); |
|
| 146 | + } |
|
| 147 | + return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups']; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Clear the cache if a cache is used, otherwise do nothing. |
|
| 152 | - * @param string $uid user id |
|
| 153 | - * @throws \Exception if user id was not found in LDAP |
|
| 154 | - */ |
|
| 155 | - public function clearCache($uid) { |
|
| 156 | - if(!$this->backend->userExists($uid)){ |
|
| 157 | - throw new \Exception('User id not found in LDAP'); |
|
| 158 | - } |
|
| 159 | - $this->backend->getLDAPAccess($uid)->getConnection()->clearCache(); |
|
| 160 | - } |
|
| 150 | + /** |
|
| 151 | + * Clear the cache if a cache is used, otherwise do nothing. |
|
| 152 | + * @param string $uid user id |
|
| 153 | + * @throws \Exception if user id was not found in LDAP |
|
| 154 | + */ |
|
| 155 | + public function clearCache($uid) { |
|
| 156 | + if(!$this->backend->userExists($uid)){ |
|
| 157 | + throw new \Exception('User id not found in LDAP'); |
|
| 158 | + } |
|
| 159 | + $this->backend->getLDAPAccess($uid)->getConnection()->clearCache(); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Check whether a LDAP DN exists |
|
| 164 | - * @param string $dn LDAP DN |
|
| 165 | - * @return bool whether the DN exists |
|
| 166 | - */ |
|
| 167 | - public function dnExists($dn) { |
|
| 168 | - $result = $this->backend->dn2UserName($dn); |
|
| 169 | - return !$result ? false : true; |
|
| 170 | - } |
|
| 162 | + /** |
|
| 163 | + * Check whether a LDAP DN exists |
|
| 164 | + * @param string $dn LDAP DN |
|
| 165 | + * @return bool whether the DN exists |
|
| 166 | + */ |
|
| 167 | + public function dnExists($dn) { |
|
| 168 | + $result = $this->backend->dn2UserName($dn); |
|
| 169 | + return !$result ? false : true; |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Flag record for deletion. |
|
| 174 | - * @param string $uid user id |
|
| 175 | - */ |
|
| 176 | - public function flagRecord($uid) { |
|
| 177 | - $this->deletedUsersIndex->markUser($uid); |
|
| 178 | - } |
|
| 172 | + /** |
|
| 173 | + * Flag record for deletion. |
|
| 174 | + * @param string $uid user id |
|
| 175 | + */ |
|
| 176 | + public function flagRecord($uid) { |
|
| 177 | + $this->deletedUsersIndex->markUser($uid); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Unflag record for deletion. |
|
| 182 | - * @param string $uid user id |
|
| 183 | - */ |
|
| 184 | - public function unflagRecord($uid) { |
|
| 185 | - //do nothing |
|
| 186 | - } |
|
| 180 | + /** |
|
| 181 | + * Unflag record for deletion. |
|
| 182 | + * @param string $uid user id |
|
| 183 | + */ |
|
| 184 | + public function unflagRecord($uid) { |
|
| 185 | + //do nothing |
|
| 186 | + } |
|
| 187 | 187 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $this->logger = $serverContainer->getLogger(); |
| 48 | 48 | $this->helper = $helper; |
| 49 | 49 | $this->deletedUsersIndex = $deletedUsersIndex; |
| 50 | - foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
| 50 | + foreach ($serverContainer->getUserManager()->getBackends() as $backend) { |
|
| 51 | 51 | $this->logger->debug('instance '.get_class($backend).' backend.', ['app' => 'user_ldap']); |
| 52 | 52 | if ($backend instanceof IUserLDAP) { |
| 53 | 53 | $this->backend = $backend; |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | * @throws \Exception if translation was unsuccessful |
| 65 | 65 | */ |
| 66 | 66 | public function getUserDN($uid) { |
| 67 | - if(!$this->backend->userExists($uid)){ |
|
| 67 | + if (!$this->backend->userExists($uid)) { |
|
| 68 | 68 | throw new \Exception('User id not found in LDAP'); |
| 69 | 69 | } |
| 70 | 70 | $result = $this->backend->getLDAPAccess($uid)->username2dn($uid); |
| 71 | - if(!$result){ |
|
| 71 | + if (!$result) { |
|
| 72 | 72 | throw new \Exception('Translation to LDAP DN unsuccessful'); |
| 73 | 73 | } |
| 74 | 74 | return $result; |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function getUserName($dn) { |
| 85 | 85 | $result = $this->backend->dn2UserName($dn); |
| 86 | - if(!$result){ |
|
| 86 | + if (!$result) { |
|
| 87 | 87 | throw new \Exception('Translation to internal user name unsuccessful'); |
| 88 | 88 | } |
| 89 | 89 | return $result; |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @throws \Exception if user id was not found in LDAP |
| 116 | 116 | */ |
| 117 | 117 | public function getLDAPConnection($uid) { |
| 118 | - if(!$this->backend->userExists($uid)){ |
|
| 118 | + if (!$this->backend->userExists($uid)) { |
|
| 119 | 119 | throw new \Exception('User id not found in LDAP'); |
| 120 | 120 | } |
| 121 | 121 | return $this->backend->getNewLDAPConnection($uid); |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @throws \Exception if user id was not found in LDAP |
| 129 | 129 | */ |
| 130 | 130 | public function getLDAPBaseUsers($uid) { |
| 131 | - if(!$this->backend->userExists($uid)){ |
|
| 131 | + if (!$this->backend->userExists($uid)) { |
|
| 132 | 132 | throw new \Exception('User id not found in LDAP'); |
| 133 | 133 | } |
| 134 | 134 | return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users']; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @throws \Exception if user id was not found in LDAP |
| 142 | 142 | */ |
| 143 | 143 | public function getLDAPBaseGroups($uid) { |
| 144 | - if(!$this->backend->userExists($uid)){ |
|
| 144 | + if (!$this->backend->userExists($uid)) { |
|
| 145 | 145 | throw new \Exception('User id not found in LDAP'); |
| 146 | 146 | } |
| 147 | 147 | return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups']; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @throws \Exception if user id was not found in LDAP |
| 154 | 154 | */ |
| 155 | 155 | public function clearCache($uid) { |
| 156 | - if(!$this->backend->userExists($uid)){ |
|
| 156 | + if (!$this->backend->userExists($uid)) { |
|
| 157 | 157 | throw new \Exception('User id not found in LDAP'); |
| 158 | 158 | } |
| 159 | 159 | $this->backend->getLDAPAccess($uid)->getConnection()->clearCache(); |
@@ -28,32 +28,32 @@ |
||
| 28 | 28 | use OCA\User_LDAP\Mapping\UserMapping; |
| 29 | 29 | |
| 30 | 30 | class LDAPProviderFactory implements ILDAPProviderFactory { |
| 31 | - /** |
|
| 32 | - * Server container |
|
| 33 | - * |
|
| 34 | - * @var IServerContainer |
|
| 35 | - */ |
|
| 36 | - private $serverContainer; |
|
| 31 | + /** |
|
| 32 | + * Server container |
|
| 33 | + * |
|
| 34 | + * @var IServerContainer |
|
| 35 | + */ |
|
| 36 | + private $serverContainer; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Constructor for the LDAP provider factory |
|
| 40 | - * |
|
| 41 | - * @param IServerContainer $serverContainer server container |
|
| 42 | - */ |
|
| 43 | - public function __construct(IServerContainer $serverContainer) { |
|
| 44 | - $this->serverContainer = $serverContainer; |
|
| 45 | - } |
|
| 38 | + /** |
|
| 39 | + * Constructor for the LDAP provider factory |
|
| 40 | + * |
|
| 41 | + * @param IServerContainer $serverContainer server container |
|
| 42 | + */ |
|
| 43 | + public function __construct(IServerContainer $serverContainer) { |
|
| 44 | + $this->serverContainer = $serverContainer; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * creates and returns an instance of the ILDAPProvider |
|
| 49 | - * |
|
| 50 | - * @return OCP\LDAP\ILDAPProvider |
|
| 51 | - */ |
|
| 52 | - public function getLDAPProvider() { |
|
| 53 | - $dbConnection = $this->serverContainer->getDatabaseConnection(); |
|
| 54 | - $userMapping = new UserMapping($dbConnection); |
|
| 55 | - return new LDAPProvider($this->serverContainer, new Helper($this->serverContainer->getConfig()), |
|
| 56 | - new DeletedUsersIndex($this->serverContainer->getConfig(), |
|
| 57 | - $dbConnection, $userMapping)); |
|
| 58 | - } |
|
| 47 | + /** |
|
| 48 | + * creates and returns an instance of the ILDAPProvider |
|
| 49 | + * |
|
| 50 | + * @return OCP\LDAP\ILDAPProvider |
|
| 51 | + */ |
|
| 52 | + public function getLDAPProvider() { |
|
| 53 | + $dbConnection = $this->serverContainer->getDatabaseConnection(); |
|
| 54 | + $userMapping = new UserMapping($dbConnection); |
|
| 55 | + return new LDAPProvider($this->serverContainer, new Helper($this->serverContainer->getConfig()), |
|
| 56 | + new DeletedUsersIndex($this->serverContainer->getConfig(), |
|
| 57 | + $dbConnection, $userMapping)); |
|
| 58 | + } |
|
| 59 | 59 | } |