| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace SimpleSAML\Module\monitor\TestCase\AuthSource\Ldap; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use \SimpleSAML\Module\monitor\State as State; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use \SimpleSAML\Module\monitor\TestData as TestData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use \SimpleSAML\Module\monitor\TestResult as TestResult; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 9 |  |  | final class Configuration extends \SimpleSAML\Module\monitor\TestCaseFactory | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  |     /* | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |      * @var \SimpleSAML_Auth_LDAP | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     private $connection; | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     /* | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      * @var string | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     private $hostname; | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     /* | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      * @var integer | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     private $port; | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     /* | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      * @var bool | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     private $enableTls; | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     /* | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      * @var integer | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     private $timeout; | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     /* | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      * @var bool | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     private $referrals; | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     /* | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      * @var bool | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     private $debug; | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     /* | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      * @param TestData $testData | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     protected function initialize($testData) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $authSourceData = $testData->getInputItem('authSourceData'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->hostname = $authSourceData->getString('hostname', '<< unset >>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $this->port = $authSourceData->getInteger('port', 636); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $this->enableTls = $authSourceData->getBoolean('enable_tls', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $this->timeout = $authSourceData->getInteger('timeout', 3); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->referrals = $authSourceData->getBoolean('referrals', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->debug = $authSourceData->getBoolean('debug', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $this->setSubject($this->hostname); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 64 |  |  |         parent::initialize($testData); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     /* | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     public function invokeTest() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         if (preg_match('/^(ldap[s]?:\/\/(.*))$/', $this->hostname, $matches)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             $connectString = $this->hostname; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             $connectString = $this->hostname .':'.$this->port; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $testResult = new TestResult('LDAP configuration', $connectString); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             $this->connection = new \SimpleSAML_Auth_LDAP( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                 $this->hostname, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                 $this->enableTls, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                 $this->debug, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                 $this->timeout, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 $this->port, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                 $this->referrals | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             $state = State::OK; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         } catch (\Exception $error) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             $state = State::FATAL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         if (isSet($error)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             $msg = str_replace('Library - LDAP __construct(): ', '', $error->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             $msg = 'Configuration syntax OK'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             $testResult->addOutput($this->connection, 'connection'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $testResult->setState($state); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $testResult->setMessage($msg); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 104 |  |  |         $this->setTestResult($testResult); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 106 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 107 |  |  |  |