-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Ldap] Added the possibility to configure all available Ldap options for connection #18725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+172
−26
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,22 +24,40 @@ abstract class AbstractConnection implements ConnectionInterface | |
| public function __construct(array $config = array()) | ||
| { | ||
| $resolver = new OptionsResolver(); | ||
|
|
||
| $this->configureOptions($resolver); | ||
|
|
||
| $this->config = $resolver->resolve($config); | ||
| } | ||
|
|
||
| /** | ||
| * Configures the adapter's options. | ||
| * | ||
| * @param OptionsResolver $resolver An OptionsResolver instance | ||
| */ | ||
| protected function configureOptions(OptionsResolver $resolver) | ||
| { | ||
| $resolver->setDefaults(array( | ||
| 'host' => null, | ||
| 'port' => 389, | ||
| 'host' => 'localhost', | ||
| 'version' => 3, | ||
| 'useSsl' => false, | ||
| 'useStartTls' => false, | ||
| 'optReferrals' => false, | ||
| 'connection_string' => null, | ||
| 'encryption' => 'none', | ||
| 'options' => array(), | ||
| )); | ||
| $resolver->setNormalizer('host', function (Options $options, $value) { | ||
| if ($value && $options['useSsl']) { | ||
| return 'ldaps://'.$value; | ||
| } | ||
|
|
||
| return $value; | ||
| $resolver->setDefault('port', function (Options $options) { | ||
| return 'ssl' === $options['encryption'] ? 636 : 389; | ||
| }); | ||
|
|
||
| $this->config = $resolver->resolve($config); | ||
| $resolver->setDefault('connection_string', function (Options $options) { | ||
| return sprintf('ldap%s://%s:%s', 'ssl' === $options['encryption'] ? 's' : '', $options['host'], $options['port']); | ||
| }); | ||
|
|
||
| $resolver->setAllowedTypes('host', 'string'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take into account that |
||
| $resolver->setAllowedTypes('port', 'numeric'); | ||
| $resolver->setAllowedTypes('connection_string', 'string'); | ||
| $resolver->setAllowedTypes('version', 'numeric'); | ||
| $resolver->setAllowedValues('encryption', array('none', 'ssl', 'tls')); | ||
| $resolver->setAllowedTypes('options', 'array'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/Symfony/Component/Ldap/Adapter/ExtLdap/ConnectionOptions.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <fabien@symfony.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\Component\Ldap\Adapter\ExtLdap; | ||
|
|
||
| use Symfony\Component\Ldap\Exception\LdapException; | ||
|
|
||
| /** | ||
| * A class representing the Ldap extension's options, which can be used with | ||
| * ldap_set_option or ldap_get_option. | ||
| * | ||
| * @author Charles Sarrazin <charles@sarraz.in> | ||
| * | ||
| * @internal | ||
| */ | ||
| final class ConnectionOptions | ||
| { | ||
| const API_INFO = 0x00; | ||
| const DEREF = 0x02; | ||
| const SIZELIMIT = 0x03; | ||
| const TIMELIMIT = 0x04; | ||
| const REFERRALS = 0x08; | ||
| const RESTART = 0x09; | ||
| const PROTOCOL_VERSION = 0x11; | ||
| const SERVER_CONTROLS = 0x12; | ||
| const CLIENT_CONTROLS = 0x13; | ||
| const API_FEATURE_INFO = 0x15; | ||
| const HOST_NAME = 0x30; | ||
| const ERROR_NUMBER = 0x31; | ||
| const ERROR_STRING = 0x32; | ||
| const MATCHED_DN = 0x33; | ||
| const DEBUG_LEVEL = 0x5001; | ||
| const NETWORK_TIMEOUT = 0x5005; | ||
| const X_SASL_MECH = 0x6100; | ||
| const X_SASL_REALM = 0x6101; | ||
| const X_SASL_AUTHCID = 0x6102; | ||
| const X_SASL_AUTHZID = 0x6103; | ||
|
|
||
| public static function getOptionName($name) | ||
| { | ||
| return sprintf('%s::%s', self::class, strtoupper($name)); | ||
| } | ||
|
|
||
| /** | ||
| * Fetches an option's corresponding constant value from an option name. | ||
| * The option name can either be in snake or camel case. | ||
| * | ||
| * @param string $name | ||
| * | ||
| * @return int | ||
| * | ||
| * @throws LdapException | ||
| */ | ||
| public static function getOption($name) | ||
| { | ||
| // Convert | ||
| $constantName = self::getOptionName($name); | ||
|
|
||
| if (!defined($constantName)) { | ||
| throw new LdapException(sprintf('Unknown option "%s"', $name)); | ||
| } | ||
|
|
||
| return constant($constantName); | ||
| } | ||
|
|
||
| public static function isOption($name) | ||
| { | ||
| return defined(self::getOptionName($name)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about 'secure' instead of encryption?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encryptionhaving a value ofnone,tlsorssl, I think something likearray('secure' => 'ssl')would make it misleading, as we are only talking about encryption over the wire, not neither authentication or RBAC.