Skip to content

Commit 74e1657

Browse files
committed
Remove try catch block, Update README.md
1 parent a8fe2dd commit 74e1657

4 files changed

Lines changed: 24 additions & 33 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ firewalls:
4141
secured_area:
4242
pattern: ^/
4343
anonymous: ~
44-
provider: chain_provider
44+
provider: main
4545
mapbender_ldap:
4646
login_path: /user/login
4747
check_path: /user/login/check
48+
provider: ldapProvider
4849
form_login:
4950
check_path: /user/login/check
5051
login_path: /user/login
51-
provider: main
52+
csrf_token_generator: security.csrf.token_manager
5253
logout:
5354
path: /user/logout
5455
target: /

Security/Provider/LDAPUserProvider.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
namespace Mapbender\LDAPBundle\Security\Provider;
55

66
use Mapbender\LDAPBundle\Component\LdapClient;
7+
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
78
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
89
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
910
use Symfony\Component\Security\Core\User\UserInterface;
1011
use Symfony\Component\Security\Core\User\UserProviderInterface;
1112
use Mapbender\LDAPBundle\Security\User\LDAPUser;
1213

13-
1414
/**
1515
* @author David Patzke <david.patzke@wheregroup.com>
1616
*/
@@ -31,14 +31,17 @@ class LDAPUserProvider implements UserProviderInterface
3131
* @param string $userQuery
3232
* @param string[] $defaultRoles
3333
*/
34-
public function __construct(LdapClient $ldapClient, LDAPGroupProvider $groupProvider,
35-
$userDN, $userQuery, Array $defaultRoles = ['ROLE_USER'])
34+
public function __construct(LdapClient $ldapClient,
35+
LDAPGroupProvider $groupProvider,
36+
$userDN,
37+
$userQuery,
38+
Array $defaultRoles = ['ROLE_USER'])
3639
{
37-
$this->ldapClient = $ldapClient;
40+
$this->ldapClient = $ldapClient;
3841
$this->groupProvider = $groupProvider;
39-
$this->userDN = $userDN;
40-
$this->userQuery = $userQuery;
41-
$this->defaultRoles = $defaultRoles;
42+
$this->userDN = $userDN;
43+
$this->userQuery = $userQuery;
44+
$this->defaultRoles = $defaultRoles;
4245
}
4346

4447
/**

Security/Provider/MapbenderLdapBindAuthenticationProvider.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\Security\Core\User\UserProviderInterface;
1818
use Symfony\Component\Security\Core\Authentication\Provider\LdapBindAuthenticationProvider;
1919

20-
class MapbenderLdapBindAuthenticationProvider extends LdapBindAuthenticationProvider
20+
class MapbenderLdapBindAuthenticationProvider extends LdapBindAuthenticationProvider
2121
{
2222
private $encoderFactory;
2323

@@ -30,8 +30,7 @@ public function __construct(UserProviderInterface $userProvider,
3030
$userQuery,
3131
$searchDn, $searchPassword)
3232
{
33-
parent::__construct( $userProvider, $userChecker, $providerKey, $ldap, $dnString, true, $searchDn, $searchPassword);
34-
33+
parent::__construct($userProvider, $userChecker, $providerKey, $ldap, $dnString, true, $searchDn, $searchPassword);
3534
$this->encoderFactory = $encoderFactory ;
3635

3736
// support Mapbender < 3.2.x (Symfony 2.8)
@@ -40,28 +39,16 @@ public function __construct(UserProviderInterface $userProvider,
4039
}
4140
}
4241

43-
44-
4542
/**
4643
* {@inheritdoc}
4744
*/
4845
protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
4946
{
50-
5147
$password = $token->getCredentials();
52-
try{
48+
try {
5349
parent::checkAuthentication($user, $token);
54-
} catch(BadCredentialsException $e){
55-
56-
try {
57-
if (!$this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $password, $user->getSalt())) {
58-
throw new BadCredentialsException('The presented password is invalid.');
59-
}
60-
} catch (\Exception $e){
61-
throw new BadCredentialsException('The presented password is invalid.');
62-
}
50+
} catch (BadCredentialsException $e) {
51+
throw new BadCredentialsException('The presented password is invalid: ' . $e->getMessage());
6352
}
6453
}
65-
66-
6754
}

Security/User/LDAPUser.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@
77
*/
88

99
namespace Mapbender\LDAPBundle\Security\User;
10+
1011
use Symfony\Component\Security\Core\User\UserInterface;
1112

1213
class LDAPUser implements UserInterface
1314
{
14-
1515
protected $username;
1616
protected $roles;
1717

18-
public function __construct($username,Array $roles = ["ROLE_USER"])
18+
public function __construct($username, Array $roles = ['ROLE_USER'])
1919
{
2020
$this->username = $username;
2121
$this->roles = $roles;
2222
}
2323

24-
2524
public function getRoles()
2625
{
2726
return $this->roles;
@@ -46,10 +45,11 @@ public function eraseCredentials()
4645
{
4746
return false;
4847
}
48+
4949
/*
5050
* This is uses to create proper ACEs in Mapbender
51-
* */
52-
public function getClass(){
53-
return "Mapbender\LDAPBundle\Security\User\LDAPUser";
51+
*/
52+
public function getClass() {
53+
return 'Mapbender\LDAPBundle\Security\User\LDAPUser';
5454
}
5555
}

0 commit comments

Comments
 (0)