-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add faultyToken in order to be able to re-use token credential …
…because AD cannot keep authentication token fix #15
- Loading branch information
Showing
6 changed files
with
105 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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,7 @@ | ||
<?php | ||
namespace Riper\Security\ActiveDirectoryBundle\Exception; | ||
|
||
class WrongTokenException extends \Exception | ||
{ | ||
|
||
} |
This file contains 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 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 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 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,44 @@ | ||
<?php | ||
|
||
|
||
namespace Riper\Security\ActiveDirectoryBundle\Security\Factory; | ||
|
||
|
||
use Riper\Security\ActiveDirectoryBundle\Exception\WrongTokenException; | ||
use Riper\Security\ActiveDirectoryBundle\Service\AdldapService; | ||
use Riper\Security\ActiveDirectoryBundle\Token\FaultyToken; | ||
use Symfony\Component\Security\Core\SecurityContext; | ||
|
||
class AdldapFactory | ||
{ | ||
|
||
/** | ||
* @var SecurityContext | ||
*/ | ||
private $securityContext; | ||
|
||
/** | ||
* @var AdldapService | ||
*/ | ||
private $adldapService; | ||
|
||
public function __construct(SecurityContext $securityContext, AdldapService $adldapService) | ||
{ | ||
$this->securityContext = $securityContext; | ||
$this->adldapService = $adldapService; | ||
} | ||
|
||
|
||
public function getAuthenticatedAdLdap() | ||
{ | ||
$token = $this->securityContext->getToken(); | ||
if ($token instanceof FaultyToken) { | ||
throw new WrongTokenException( | ||
'The token is not the right one. Did you forget to set "keep_password_in_token" to "true" in bundle configuration ?' | ||
); | ||
} | ||
$adldap = $this->adldapService->getInstance(); | ||
$adldap->authenticate($token->getUsername(), $token->getCredentials()); | ||
} | ||
|
||
} |
This file contains 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,19 @@ | ||
<?php | ||
namespace Riper\Security\ActiveDirectoryBundle\Security\Token; | ||
|
||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | ||
|
||
class FaultyToken extends UsernamePasswordToken | ||
{ | ||
|
||
|
||
/** | ||
* This method cut of the behaviour in order to keep the password in the token | ||
* This is a bad practice, but is the only simple way to keep the password and reuse it after | ||
* For active directory authentication | ||
*/ | ||
public function eraseCredentials() | ||
{ | ||
|
||
} | ||
} |