@@ -33,54 +33,54 @@ |
||
| 33 | 33 | |
| 34 | 34 | class LDAPAuthentificator implements IAuthentificator { |
| 35 | 35 | |
| 36 | - public function __construct() { |
|
| 37 | - // |
|
| 38 | - } |
|
| 36 | + public function __construct() { |
|
| 37 | + // |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * check password of user and import user, if neccessary |
|
| 42 | - * |
|
| 43 | - * @param $username string name of user |
|
| 44 | - * @param $password string password of user |
|
| 45 | - * |
|
| 46 | - * @return userID or -1, if credentials are wrong |
|
| 47 | - */ |
|
| 48 | - public function checkPasswordAndImport(string $username, string $password): int { |
|
| 49 | - //https://samjlevy.com/php-ldap-login/ |
|
| 40 | + /** |
|
| 41 | + * check password of user and import user, if neccessary |
|
| 42 | + * |
|
| 43 | + * @param $username string name of user |
|
| 44 | + * @param $password string password of user |
|
| 45 | + * |
|
| 46 | + * @return userID or -1, if credentials are wrong |
|
| 47 | + */ |
|
| 48 | + public function checkPasswordAndImport(string $username, string $password): int { |
|
| 49 | + //https://samjlevy.com/php-ldap-login/ |
|
| 50 | 50 | |
| 51 | - //Free test ldap server: https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/ |
|
| 51 | + //Free test ldap server: https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/ |
|
| 52 | 52 | |
| 53 | - //https://www.experts-exchange.com/questions/23969673/Using-PHP-with-LDAP-to-connect-to-Active-Directory-on-another-machine.html |
|
| 53 | + //https://www.experts-exchange.com/questions/23969673/Using-PHP-with-LDAP-to-connect-to-Active-Directory-on-another-machine.html |
|
| 54 | 54 | |
| 55 | - //http://www.devshed.com/c/a/php/using-php-with-ldap-part-1/3/ |
|
| 55 | + //http://www.devshed.com/c/a/php/using-php-with-ldap-part-1/3/ |
|
| 56 | 56 | |
| 57 | - //check, if username contains a komma (because komma is not allowed here) |
|
| 58 | - if (strpos($username, ",") !== FALSE) { |
|
| 59 | - throw new IllegalArgumentException("',' is not allowed in username."); |
|
| 60 | - return -1; |
|
| 61 | - } |
|
| 57 | + //check, if username contains a komma (because komma is not allowed here) |
|
| 58 | + if (strpos($username, ",") !== FALSE) { |
|
| 59 | + throw new IllegalArgumentException("',' is not allowed in username."); |
|
| 60 | + return -1; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $ldap_client = new LDAPClient(); |
|
| 63 | + $ldap_client = new LDAPClient(); |
|
| 64 | 64 | |
| 65 | - //try to login user on ldap server |
|
| 66 | - $res = $ldap_client->bind($username, $password); |
|
| 65 | + //try to login user on ldap server |
|
| 66 | + $res = $ldap_client->bind($username, $password); |
|
| 67 | 67 | |
| 68 | - if (!$res) { |
|
| 69 | - //user doesnt exists or credentials are wrong |
|
| 70 | - return -1; |
|
| 71 | - } |
|
| 68 | + if (!$res) { |
|
| 69 | + //user doesnt exists or credentials are wrong |
|
| 70 | + return -1; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - echo "user exists. User groups: "; |
|
| 73 | + echo "user exists. User groups: "; |
|
| 74 | 74 | |
| 75 | - print_r($ldap_client->listGroupsOfUser("riemann")); |
|
| 75 | + print_r($ldap_client->listGroupsOfUser("riemann")); |
|
| 76 | 76 | |
| 77 | - //unbind |
|
| 78 | - $ldap_client->unbind(); |
|
| 77 | + //unbind |
|
| 78 | + $ldap_client->unbind(); |
|
| 79 | 79 | |
| 80 | - exit; |
|
| 80 | + exit; |
|
| 81 | 81 | |
| 82 | - return -1; |
|
| 83 | - } |
|
| 82 | + return -1; |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | ?> |