Permalink
Browse files

Merge branch '1.5.x'

  • Loading branch information...
1 parent 02b4f4d commit b0d1c2c98fa4c3cca44ba93e231dc73fafadc882 @Maks3w committed Jun 8, 2012
View
2 FR3DLdapBundle.php
@@ -14,7 +14,7 @@ public function boot()
throw new \Exception("module php-ldap isn't install");
}
}
-
+
/* Require Symfony > 2.1.x
public function build(ContainerBuilder $container)
{
View
2 Ldap/Converter.php
@@ -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
16 Ldap/LdapManager.php
@@ -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 UserInterface $user user to hydrate
- * @param array $entry ldap result
- *
+ *
+ * @param UserInterface $user user to hydrate
+ * @param array $entry ldap result
+ *
* @return UserInterface
*/
protected function hydrate(UserInterface $user, array $entry)
@@ -116,7 +116,7 @@ public function bind(UserInterface $user, $password)
*/
public function getRolesForUsername($username)
{
-
+
}
/**
@@ -170,4 +170,4 @@ public static function unescapeValue($values = array())
}
return (count($values) == 1 && array_key_exists(0, $values)) ? $values[0] : $values;
}
-}
+}
View
14 Ldap/LdapManagerInterface.php
@@ -10,24 +10,24 @@
/**
* 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 UserInterface $user
- * @param string $password
+ * @param UserInterface $user
+ * @param string $password
* @return Boolean
*/
function bind(UserInterface $user, $password);
View
4 Model/LdapUserInterface.php
@@ -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();
}
View
6 Model/UserManagerInterface.php
@@ -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
14 README.md
@@ -17,25 +17,23 @@ Features include:
**Note:** This bundle don't provide at this moment User Management and requires
then an external 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=2.0.x)](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
-------
View
2 Resources/config/security_factories.xml
@@ -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" />
View
2 Resources/config/validator.xml
@@ -17,4 +17,4 @@
</services>
-</container>
+</container>
View
4 Resources/doc/index.md
@@ -19,11 +19,11 @@ Install
### 1. Download LdapBundle
-Add this bundle to your ``vendor/`` dir:
+Add this bundle to your `vendor/` dir:
* Using the vendors script.
- Add the following lines in your ``deps`` file::
+ Add the following lines in your `deps` file::
[zend]
git=git://github.com/zendframework/zf2.git
View
2 Resources/translations/validators.en.yml
@@ -1,3 +1,3 @@
fr3d_ldap:
username:
- already_used: The username is already used
+ already_used: The username is already used
View
2 Security/Authentication/LdapAuthenticationProvider.php
@@ -82,4 +82,4 @@ protected function checkAuthentication(UserInterface $user, UsernamePasswordToke
}
}
}
-}
+}
View
48 Security/Factory/LdapFactory.php
@@ -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;
}
-}
+}
View
1 Tests/Ldap/LdapManagerTest.php
@@ -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));
}
View
1 Tests/Security/User/LdapUserProviderTest.php
@@ -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
View
2 Tests/Validator/UniqueValidatorTest.php
@@ -67,4 +67,4 @@ public function testBadType()
{
$this->validator->isValid('bad_type', $this->constraint);
}
-}
+}
View
2 Validator/Unique.php
@@ -43,4 +43,4 @@ public function getTargets()
{
return self::CLASS_CONSTRAINT;
}
-}
+}
View
11 Validator/UniqueValidator.php
@@ -44,7 +44,7 @@ public function __construct(LdapManagerInterface $ldapManager)
* @param Constraint $constraint The constrain for the validation
*
* @return Boolean Whether or not the value is valid
- *
+ *
* @throws UnexpectedTypeException if $value is not instance of \Symfony\Component\Security\Core\User\UserInterface
*/
public function isValid($value, Constraint $constraint)
@@ -56,12 +56,13 @@ public function isValid($value, Constraint $constraint)
$user = $this->ldapManager->findUserByUsername($value->getUsername());
if ($user) {
- $this->context->addViolation($constraint->message, array(
- '%property%' => $constraint->property,
- ), $value);
+ $this->setMessage($constraint->message, array(
+ '%property%' => $constraint->property
+ ));
+
return false;
}
return true;
}
-}
+}

0 comments on commit b0d1c2c

Please sign in to comment.