Changeset 1559

Show
Ignore:
Timestamp:
04/18/08 15:54:50 (1 month ago)
Author:
richi
Message:

peer::ldap: first working ldap implementation (anonymous bind)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/peer/ldap/stubLDAPURL.php

    r1556 r1559  
    6363     * @return  stubLDAPURL 
    6464     * @throws  stubMalformedURLException 
    65      * 
    6665     */ 
    6766    public static function fromString($urlString) 
     
    9392        // check scheme 
    9493        if($this->url['scheme'] !== 'ldap' && $this->url['scheme'] !== 'ldaps') { 
    95             return false; 
    96         } 
    97  
    98         // check port 
    99         if($this->url['scheme'] === 'ldap' && $this->url['port'] !== 389) { 
    100             return false; 
    101         } else if($this->url['scheme'] === 'ldaps' && $this->url['port'] !== 636) { 
    10294            return false; 
    10395        } 
     
    134126 
    135127    /** 
    136      * Gets the base dn (distinguished name) 
     128     * Gets the base dn (distinguished name). 
    137129     * 
    138130     * @return  string 
     
    143135            return null; 
    144136        } 
    145          
     137 
    146138        return $this->url['base_dn']; 
    147139    } 
    148140 
    149141    /** 
    150      * Gets the base dn (distinguished name) 
     142     * Changes the originally used base dn (distinguished name). 
     143     * 
     144     * @param  string  $newBaseDn 
     145     */ 
     146    public function setBaseDn($newBaseDn) 
     147    { 
     148        $this->url['base_dn'] = $newBaseDn; 
     149    } 
     150 
     151    /** 
     152     * Gets the base dn (distinguished name). 
    151153     * 
    152154     * @return  string 
     
    157159            return null; 
    158160        } 
    159          
     161 
    160162        return $this->url['base_dn']; 
    161163    } 
     
    164166     * Checks if query string was provided. 
    165167     * 
    166      * query:= attributes, scope and filter 
     168     * query:= {attributes}?{scope}?{filter}' 
    167169     * 
    168170     * @return  boolean 
     
    175177    /** 
    176178     * Gets the value of an optional parameter from the query string. 
    177      * 
    178      * parameter:= attributes|scope|filter 
    179      * 
    180      * There's a difference between a parameter explicity not set (returns '') 
    181      * and the param not set in the query string (returns null or defaultValue) 
    182      * or no query string at all (returns null or defaultvalue). 
     179     * Valid LDAP parameters are 'attributes', 'scope' or 'filter'. 
     180     * 
     181     * If they were not set before the default values are: 
     182     * attributes = '' 
     183     * scope      = 'base' 
     184     * filters    = 'objectClass=*' 
    183185     * 
    184186     * possibilities for query string: 
     
    191193     *         ?      ?x 
    192194     * 
    193      * @param   string  $name 
    194      * @param   string  $defaultValue 
    195      * @return  string 
     195     * @param   string       $name 
     196     * @param   string       $defaultValue 
     197     * @return  string|null 
    196198     */ 
    197199    public function getParam($name, $defaultValue = null) 
    198200    { 
    199         $result = ''
    200  
    201         if (isset($this->url['query']) === false) { 
    202             return $defaultValue
     201        $result = $defaultValue
     202 
     203        if ($this->hasQuery() === false) { 
     204            $queryValues = null
    203205        } else { 
    204206            $queryValues = explode('?', $this->url['query']); 
     
    207209        switch($name) { 
    208210            case 'attributes': 
    209                 $result = $queryValues[0]; 
     211                $result = ($queryValues !== null 
     212                                && $queryValues[0] !== '') ? $queryValues[0] : ''; 
    210213                break; 
    211214 
    212215            case 'scope': 
    213                 $result = (count($queryValues) >= 2) ? $queryValues[1] : null; 
     216                $result = ($queryValues !== null 
     217                                && count($queryValues) >= 2 
     218                                && $queryValues[1] !== '') ? $queryValues[1] : 'base'; 
    214219                break; 
    215220 
    216221            case 'filter': 
    217                 $result = (count($queryValues) >= 3) ? $queryValues[2] : null; 
     222                $result = ($queryValues !== null 
     223                                && count($queryValues) >= 3 
     224                                && $queryValues[2] !== '') ? $queryValues[2] : 'objectClass=*'; 
    218225                break; 
    219  
     226             
    220227            default: 
    221                 return $defaultValue; 
     228                // intentionally empty 
    222229        } 
    223230 
     
    275282 
    276283    /** 
    277      * Returns a stubLDAPConnection 
     284     * Returns a stubLDAPConnection. 
    278285     * 
    279286     * @return  stubLDAPConnection