Permalink
Browse files

Merge branch '1.5.x'

  • Loading branch information...
1 parent c8ea95b commit f10e213536d8edcfe69700fff13bbc88ec7b5a8d @Maks3w committed Jun 8, 2012
@@ -43,11 +43,13 @@ public function bind($user_dn, $password)
}
if (!$user_dn) {
$this->logInfo('You must bind with an ldap user_dn');
+
return false;
}
if (!$password) {
$this->logInfo('Password can not be null to bind');
+
return false;
}
@@ -13,7 +13,7 @@
/**
* Bind to LDAP directory
*/
- function bind($user_dn, $password);
+ public function bind($user_dn, $password);
- function search($baseDn, $filter, array $attributes = array());
+ public function search($baseDn, $filter, array $attributes = array());
}
View
@@ -14,8 +14,7 @@ public function boot()
throw new \Exception("module php-ldap isn't install");
}
}
-
- /* Require Symfony > 2.1.x */
+
public function build(ContainerBuilder $container)
{
parent::build($container);
View
@@ -32,6 +32,7 @@ public static function ascToHex32($string)
$string = str_replace($char, '\\' . $hex, $string);
}
}
+
return $string;
}
@@ -49,6 +50,7 @@ public static function ascToHex32($string)
public static function hex32ToAsc($string)
{
$string = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $string);
+
return $string;
}
-}
+}
View
@@ -59,8 +59,8 @@ public function findUserBy(array $criteria)
/**
* Build Ldap filter
*
- * @param array $criteria
- * @param string $condition
+ * @param array $criteria
+ * @param string $condition
* @return string
*/
private function buildFilter(array $criteria, $condition = '&')
@@ -77,10 +77,10 @@ private function buildFilter(array $criteria, $condition = '&')
/**
* Hydrates an user entity with ldap attributes.
- *
+ *
* @param LdapUserInterface $user user to hydrate
* @param array $entry ldap result
- *
+ *
* @return LdapUserInterface
*/
protected function hydrate(LdapUserInterface $user, array $entry)
@@ -133,6 +133,7 @@ public static function escapeValue($values = array())
}
$values[$key] = $val;
}
+
return (count($values) == 1 && array_key_exists(0, $values)) ? $values[0] : $values;
}
@@ -155,6 +156,7 @@ public static function unescapeValue($values = array())
// Translate hex code into ascii
$values[$key] = Converter::hex32ToAsc($value);
}
+
return (count($values) == 1 && array_key_exists(0, $values)) ? $values[0] : $values;
}
}
@@ -10,27 +10,27 @@
/**
* Find a user by its username.
*
- * @param string $username
- * @return \Symfony\Component\Security\Core\User\UserInterface or null if user does not exist
+ * @param string $username
+ * @return \Symfony\Component\Security\Core\User\UserInterface|null The user or null if the user does not exist
*/
- function findUserByUsername($username);
+ public function findUserByUsername($username);
/**
* Finds one user by the given criteria.
*
- * @param array $criteria
+ * @param array $criteria
* @return \Symfony\Component\Security\Core\User\UserInterface
*/
- function findUserBy(array $criteria);
+ public function findUserBy(array $criteria);
/**
* Bind the user on ldap
*
- * @param LdapUserInterface $user
- * @param string $password
+ * @param LdapUserInterface $user
+ * @param string $password
* @return Boolean
*/
- function bind(LdapUserInterface $user, $password);
+ public function bind(LdapUserInterface $user, $password);
/**
* Escapes the given VALUES according to RFC 2254 so that they can be safely used in LDAP filters.
@@ -9,12 +9,12 @@
*
* @param string $dn Distinguished Name
*/
- function setDn($dn);
+ public function setDn($dn);
/**
* Get Ldap Distinguished Name
*
* @return string Distinguished Name
*/
- function getDn();
+ public function getDn();
}
@@ -12,14 +12,14 @@
*
* @return LdapUserInterface
*/
- function createUser();
+ public function createUser();
/**
* Find a user by his username.
*
* @param string $username
- *
+ *
* @return LdapUserInterface|null
*/
- function findUserByUsername($username);
+ public function findUserByUsername($username);
}
View
@@ -16,24 +16,23 @@ Features included:
**Note:** This bundle cannot work as standalone at this moment and requires an User Manager like `FOSUserBundle`
**Versions and compatibilities:**
-- 1.5.x is compatible with Symfony 2.0.x and is recommended for stable projects.
-- 1.6.x is compatible with Symfony 2.1.x and has the same features than 1.5.x
-- 2.0.x is actually compatible with Symfony 2.0.x and have new features. This version is actually under development and is subject to changes.
-
-[![Build Status](https://secure.travis-ci.org/Maks3w/FR3DLdapBundle.png?branch=master)](http://travis-ci.org/Maks3w/FR3DLdapBundle)
+- [![Build Status](https://secure.travis-ci.org/Maks3w/FR3DLdapBundle.png?branch=1.5.x)](http://travis-ci.org/Maks3w/FR3DLdapBundle) `1.5.x` is compatible with Symfony 2.0.x and is recommended for stable projects.
+- [![Build Status](https://secure.travis-ci.org/Maks3w/FR3DLdapBundle.png?branch=1.6.x)](http://travis-ci.org/Maks3w/FR3DLdapBundle) `1.6.x` is compatible with Symfony 2.1.x and has the same features than 1.5.x
+- [![Build Status](https://secure.travis-ci.org/Maks3w/FR3DLdapBundle.png?branch=2.0.x)](http://travis-ci.org/Maks3w/FR3DLdapBundle) `2.0.x` is actually compatible with Symfony 2.0.x and have new features. This version is actually under development and is subject to changes.
+- [![Build Status](https://secure.travis-ci.org/Maks3w/FR3DLdapBundle.png?branch=master)](http://travis-ci.org/Maks3w/FR3DLdapBundle) `Master` is, at this moment, synced with 1.5.x but I encourage you fix your installation to the 1.5.x version branch unless you like the risk.
Documentation
-------------
The bulk of the documentation is stored in the `Resources/doc/index.md`
file in this bundle:
-[Read the Documentation](https://github.com/Maks3w/FR3DLdapBundle/blob/master/Resources/doc/index.md)
+[Read the Documentation](Resources/doc/index.md)
Installation
------------
-All the installation instructions are located in [documentation](https://github.com/Maks3w/FR3DLdapBundle/blob/master/Resources/doc/index.md).
+All the installation instructions are located in [documentation](Resources/doc/index.md).
License
-------
@@ -3,7 +3,7 @@
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
-
+
<services>
<service id="security.authentication.factory.ldap" class="FR3D\LdapBundle\Security\Factory\LdapFactory" public="false">
<tag name="security.listener.factory" />
@@ -19,25 +19,25 @@
<tag name="monolog.logger" channel="ldap_connection" />
<argument type="service" id="logger" />
</service>
-
+
<service id="fr3d_ldap.ldap_manager.default" class="%fr3d_ldap.ldap_manager.class%">
<argument type="service" id="fr3d_ldap.client" />
<argument type="service" id="fr3d_ldap.user_manager" />
<argument>%fr3d_ldap.ldap_manager.parameters%</argument>
</service>
-
+
<service id="fr3d_ldap.security.user.provider" class="%fr3d_ldap.security.user.provider.class%">
<argument type="service" id="fr3d_ldap.ldap_manager" />
<tag name="monolog.logger" channel="security" />
<argument type="service" id="logger" />
</service>
-
+
<service id="fr3d_ldap.security.authentication.provider" class="%fr3d_ldap.security.authentication.provider.class%">
<argument type="service" id="security.user_checker" />
<argument /> <!-- Provider-key -->
<argument /> <!-- User Provider -->
<argument type="service" id="fr3d_ldap.ldap_manager" />
</service>
</services>
-
+
</container>
@@ -17,4 +17,4 @@
</services>
-</container>
+</container>
View
@@ -16,7 +16,7 @@ Install
### 1. Add FR3DLdapBundle in your composer.json
-Add this bundle to your ``vendor/`` dir:
+Add this bundle to your `vendor/` dir:
```json
{
@@ -48,13 +48,13 @@ public function registerBundles()
security:
firewalls:
main:
- pattern: ^/
- fr3d_ldap: ~
+ pattern: ^/
+ fr3d_ldap: ~
form_login:
always_use_default_target_path: true
default_target_path: /profile
- logout: true
- anonymous: true
+ logout: true
+ anonymous: true
providers:
fr3d_ldapbundle:
@@ -1,3 +1,3 @@
fr3d_ldap:
username:
- already_used: The username is already used
+ already_used: The username is already used
@@ -96,4 +96,4 @@ protected function checkAuthentication(UserInterface $user, UsernamePasswordToke
}
}
}
-}
+}
@@ -2,13 +2,24 @@
namespace FR3D\LdapBundle\Security\Factory;
-use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory;
+use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
+use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
-class LdapFactory extends AbstractFactory
+class LdapFactory implements SecurityFactoryInterface
{
+ public function create(ContainerBuilder $container, $id, $config, $userProviderId, $defaultEntryPointId)
+ {
+ // authentication provider
+ $authProviderId = $this->createAuthProvider($container, $id, $config, $userProviderId);
+
+ // authentication listener
+ $listenerId = $this->createListener($container, $id, $config, $userProviderId);
+
+ return array($authProviderId, $listenerId, $defaultEntryPointId);
+ }
public function getPosition()
{
@@ -20,21 +31,38 @@ public function getKey()
return 'fr3d_ldap';
}
- protected function getListenerId()
+ public function addConfiguration(NodeDefinition $node)
{
- return 'security.authentication.listener.form';
+ // Without Configuration
}
protected function createAuthProvider(ContainerBuilder $container, $id, $config, $userProviderId)
{
- $provider = 'fr3d_ldap.security.authentication.provider.' . $id;
+ $provider = 'fr3d_ldap.security.authentication.provider';
+ $providerId = $provider . '.' . $id;
+
+ $container
+ ->setDefinition($providerId, new DefinitionDecorator($provider))
+ ->replaceArgument(1, $id) // Provider Key
+ ->replaceArgument(2, new Reference($userProviderId)) // User Provider
+ ;
+
+ return $providerId;
+ }
+
+ protected function createListener(ContainerBuilder $container, $id, $config, $userProvider)
+ {
+ $listenerId = 'security.authentication.listener.form';
+
+ $listener = new DefinitionDecorator($listenerId);
+ $listener->replaceArgument(4, $id);
+ $listener->replaceArgument(5, $config);
+ $listenerId .= '.' . $id;
$container
- ->setDefinition($provider, new DefinitionDecorator('fr3d_ldap.security.authentication.provider'))
- ->replaceArgument(1, $id) // Provider Key
- ->replaceArgument(2, new Reference($userProviderId)) // User Provider
+ ->setDefinition($listenerId, $listener)
;
- return $provider;
+ return $listenerId;
}
-}
+}
@@ -2,7 +2,6 @@
namespace FR3D\LdapBundle\Security\User;
-use FR3D\LdapBundle\Model\LdapUserInterface;
use FR3D\LdapBundle\Ldap\LdapManagerInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
@@ -78,7 +78,6 @@ public function testConstruct()
$propertyLdapUsernameAttr = $reflectionClass->getProperty('ldapUsernameAttr');
$propertyLdapUsernameAttr->setAccessible(true);
-
$this->assertEquals(array('uid', 'mail'), $propertyLdapAttributes->getValue($this->ldapManager));
$this->assertEquals('uid', $propertyLdapUsernameAttr->getValue($this->ldapManager));
}
@@ -3,7 +3,6 @@
namespace FR3D\LdapBundle\Tests\Security\User;
use FR3D\LdapBundle\Security\User\LdapUserProvider;
-use FR3D\LdapBundle\Ldap\LdapManagerInterface;
use FR3D\LdapBundle\Tests\TestUser;
class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
@@ -67,4 +67,4 @@ public function testBadType()
{
$this->validator->isValid('bad_type', $this->constraint);
}
-}
+}
View
@@ -43,4 +43,4 @@ public function getTargets()
{
return self::CLASS_CONSTRAINT;
}
-}
+}
Oops, something went wrong.

0 comments on commit f10e213

Please sign in to comment.