Changeset 755

Show
Ignore:
Timestamp:
07/06/07 22:40:31 (1 year ago)
Author:
mikey
Message:

refining work on net.stubbles.auth for enhancement #46

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/auth/storage/stubAuthAbstractStorage.php

    r754 r755  
    4141    public function isValid() 
    4242    { 
     43        $result = $this->getResult(); 
     44        if (null === $result) { 
     45            return false; 
     46        } 
     47         
     48        if ($result->getStatus() != stubAuthResult::STATUS_SUCCESS) { 
     49            return false; 
     50        } 
     51         
    4352        if (time() > ($this->getStoreTime() + $this->timeout)) { 
    4453            return false; 
    4554        } 
    4655         
    47         return $this->doIsValid()
     56        return true
    4857    } 
    4958 
     
    5463     */ 
    5564    protected abstract function getStoreTime(); 
    56  
    57     /** 
    58      * check whether the authentication is still valid 
    59      * 
    60      * @return  bool 
    61      */ 
    62     protected abstract function doIsValid(); 
    6365 
    6466    /** 
     
    7981     */ 
    8082    protected abstract function doSetResult(stubAuthResult $result, $storeTime); 
     83 
     84    /** 
     85     * returns the authentication data from the result 
     86     * 
     87     * @return  mixed 
     88     */ 
     89    public function getAuthData() 
     90    { 
     91        $result = $this->getResult(); 
     92        return ((null !== $result) ? ($result->getAuthData()) : (null)); 
     93    } 
    8194} 
    8295?> 
  • trunk/src/main/php/net/stubbles/auth/storage/stubAuthSessionStorage.php

    r754 r755  
    4545 
    4646    /** 
    47      * check whether the authentication is still valid 
    48      * 
    49      * @return  bool 
    50      */ 
    51     protected function doIsValid() 
    52     { 
    53         $result = $this->getResult(); 
    54         if (null === $result) { 
    55             return false; 
    56         } 
    57          
    58         return $result->getStatus() == stubAuthResult::STATUS_SUCCESS; 
    59     } 
    60  
    61     /** 
    6247     * stores the result 
    6348     * 
     
    6954        $this->session->putValue('net.stubbles.auth.result', $result); 
    7055        $this->session->putValue('net.stubbles.auth.storeTime', $storeTime); 
     56        $this->session->regenerateId(); 
    7157    } 
    7258 
     
    7460     * returns the result 
    7561     * 
    76      * @return  mixed 
     62     * @return  stubAuthResult 
    7763     */ 
    7864    public function getResult() 
     
    8874        $this->session->removeValue('net.stubbles.auth.result'); 
    8975        $this->session->removeValue('net.stubbles.auth.storeTime'); 
     76        $this->session->regenerateId(); 
    9077    } 
    9178} 
  • trunk/src/main/php/net/stubbles/auth/storage/stubAuthStorage.php

    r754 r755  
    4040     * returns the result 
    4141     * 
    42      * @return  mixed 
     42     * @return  stubAuthResult 
    4343     */ 
    4444    public function getResult(); 
     
    4848     */ 
    4949    public function clear(); 
     50 
     51    /** 
     52     * returns the authentication data from the result 
     53     * 
     54     * @return  mixed 
     55     */ 
     56    public function getAuthData(); 
    5057} 
    5158?> 
  • trunk/src/main/php/net/stubbles/auth/stubAuth.php

    r754 r755  
    1010                      'net.stubbles.auth.storage.stubAuthStorage', 
    1111                      'net.stubbles.auth.strategy.stubAuthStrategy', 
     12                      'net.stubbles.auth.stubAuthException', 
    1213                      'net.stubbles.auth.stubAuthResult' 
    1314); 
     
    6667 
    6768    /** 
     69     * creates and returns an auth instance 
     70     * 
     71     * @param  stubAuthStrategy   $strategy  strategy to be used for authentification 
     72     * @param  stubAuthStorage    $storage   storage to be used for storing the result 
     73     * @param  string             $id        id of the auth instance to create 
     74     */ 
     75    public static function createInstance(stubAuthStrategy $strategy, stubAuthStorage $storage, $id = self::ID_DEFAULT) 
     76    { 
     77        if (isset(self::$instances[$id]) == true) { 
     78            return self::$instances[$id]; 
     79        } 
     80         
     81        self::$instances[$id] = new self($id); 
     82        self::$instances[$id]->setStrategy($strategy); 
     83        self::$instances[$id]->setStorage($storage); 
     84        return self::$instances[$id]; 
     85    } 
     86 
     87    /** 
    6888     * returns an auth instance 
     89     *  
     90     * If the instance does not exist a stubAuthException will be thrown. 
    6991     * 
    70      * @param  string  $id 
     92     * @param   string  $id  id of the auth instance 
     93     * @throws  stubAuthException 
    7194     */ 
    72     public function getInstance($id = self::ID_DEFAULT) 
     95    public static function getInstance($id = self::ID_DEFAULT) 
    7396    { 
    7497        if (isset(self::$instances[$id]) == false) { 
    75             self::$instances[$id] = new self($id); 
     98            throw new stubAuthException('Auth instance with id ' . $id . ' does not exist.'); 
    7699        } 
    77100         
    78101        return self::$instances[$id]; 
     102    } 
     103 
     104    /** 
     105     * checks if the specified auth instances contains a valid authentification 
     106     *  
     107     * Checking the validity for a non-existing instance will always return false. 
     108     * 
     109     * @param   string  $id  id of the auth instance 
     110     * @return  bool 
     111     */ 
     112    public static function isValid($id = self::ID_DEFAULT) 
     113    { 
     114        if (isset(self::$instances[$id]) == false) { 
     115            return false; 
     116        } 
     117         
     118        return self::$instances[$id]->getStorage()->isValid(); 
    79119    } 
    80120 
     
    100140 
    101141    /** 
    102      * sets the storage to be used for storing the credentials 
     142     * sets the storage to be used for storing the result 
    103143     * 
    104144     * @param  stubAuthStorage  $storage 
    105145     */ 
    106     public function setStore(stubAuthStorage $storage) 
     146    public function setStorage(stubAuthStorage $storage) 
    107147    { 
    108148        $this->storage = $storage; 
     
    110150 
    111151    /** 
     152     * returns the storage 
     153     * 
     154     * @return  stubAuthStorage 
     155     */ 
     156    public function getStorage() 
     157    { 
     158        return $this->storage; 
     159    } 
     160     
     161    /** 
    112162     * authenticate the credentials 
    113163     * 
    114      * @param   mixed           $credentials 
    115      * @return  stubAuthResult 
     164     * @param   mixed            $credentials 
     165     * @return  stubAuthStorage 
    116166     */ 
    117167    public function authenticate($credentials) 
    118168    { 
    119         $result = $this->authentificationStrategy->authenticate($this->authenticators, $credentials); 
    120         if ($result->getStatus() == stubAuthResult::STATUS_SUCCESS) { 
    121             $this->storage->setResult($result); 
    122         } 
    123          
    124         return $result; 
     169        $this->storage->setResult($this->authentificationStrategy->authenticate($this->authenticators, $credentials)); 
     170        return $this->storage; 
    125171    } 
    126172} 
  • trunk/src/main/php/net/stubbles/auth/stubAuthResult.php

    r754 r755  
    3131    protected $credentials; 
    3232    /** 
     33     * other authentication data, e.g. the instance of the authenticated user 
     34     * 
     35     * @var  mixed 
     36     */ 
     37    protected $authData; 
     38    /** 
    3339     * authentication status: authentication was successful 
    3440     */ 
     
    4854     * @param  int    $status       status of result, one of the stubAuthResult::STATUS_ constants 
    4955     * @param  mixed  $credentials  credentials used for the authentication attempt 
     56     * @param  mixed  $authData     optional  other authentication data, e.g. the instance of the authenticated user 
    5057     */ 
    51     public function __construct($status, $credentials
     58    public function __construct($status, $credentials, $authData = null
    5259    { 
    5360        $this->status      = $status; 
    5461        $this->credentials = $credentials; 
     62        $this->authData    = $authData; 
    5563    } 
    5664 
     
    7684        return $this->credentials; 
    7785    } 
     86 
     87    /** 
     88     * returns other authentication data, e.g. the instance of the authenticated user 
     89     * 
     90     * @return  mixed 
     91     */ 
     92    public function getAuthData() 
     93    { 
     94        return $this->authData; 
     95    } 
    7896} 
    7997?>