Changeset 755
- Timestamp:
- 07/06/07 22:40:31 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/auth/storage/stubAuthAbstractStorage.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/auth/storage/stubAuthSessionStorage.php (modified) (4 diffs)
- trunk/src/main/php/net/stubbles/auth/storage/stubAuthStorage.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/auth/stubAuth.php (modified) (4 diffs)
- trunk/src/main/php/net/stubbles/auth/stubAuthException.php (added)
- trunk/src/main/php/net/stubbles/auth/stubAuthResult.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/auth/storage/stubAuthAbstractStorage.php
r754 r755 41 41 public function isValid() 42 42 { 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 43 52 if (time() > ($this->getStoreTime() + $this->timeout)) { 44 53 return false; 45 54 } 46 55 47 return $this->doIsValid();56 return true; 48 57 } 49 58 … … 54 63 */ 55 64 protected abstract function getStoreTime(); 56 57 /**58 * check whether the authentication is still valid59 *60 * @return bool61 */62 protected abstract function doIsValid();63 65 64 66 /** … … 79 81 */ 80 82 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 } 81 94 } 82 95 ?> trunk/src/main/php/net/stubbles/auth/storage/stubAuthSessionStorage.php
r754 r755 45 45 46 46 /** 47 * check whether the authentication is still valid48 *49 * @return bool50 */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 /**62 47 * stores the result 63 48 * … … 69 54 $this->session->putValue('net.stubbles.auth.result', $result); 70 55 $this->session->putValue('net.stubbles.auth.storeTime', $storeTime); 56 $this->session->regenerateId(); 71 57 } 72 58 … … 74 60 * returns the result 75 61 * 76 * @return mixed62 * @return stubAuthResult 77 63 */ 78 64 public function getResult() … … 88 74 $this->session->removeValue('net.stubbles.auth.result'); 89 75 $this->session->removeValue('net.stubbles.auth.storeTime'); 76 $this->session->regenerateId(); 90 77 } 91 78 } trunk/src/main/php/net/stubbles/auth/storage/stubAuthStorage.php
r754 r755 40 40 * returns the result 41 41 * 42 * @return mixed42 * @return stubAuthResult 43 43 */ 44 44 public function getResult(); … … 48 48 */ 49 49 public function clear(); 50 51 /** 52 * returns the authentication data from the result 53 * 54 * @return mixed 55 */ 56 public function getAuthData(); 50 57 } 51 58 ?> trunk/src/main/php/net/stubbles/auth/stubAuth.php
r754 r755 10 10 'net.stubbles.auth.storage.stubAuthStorage', 11 11 'net.stubbles.auth.strategy.stubAuthStrategy', 12 'net.stubbles.auth.stubAuthException', 12 13 'net.stubbles.auth.stubAuthResult' 13 14 ); … … 66 67 67 68 /** 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 /** 68 88 * returns an auth instance 89 * 90 * If the instance does not exist a stubAuthException will be thrown. 69 91 * 70 * @param string $id 92 * @param string $id id of the auth instance 93 * @throws stubAuthException 71 94 */ 72 public function getInstance($id = self::ID_DEFAULT)95 public static function getInstance($id = self::ID_DEFAULT) 73 96 { 74 97 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.'); 76 99 } 77 100 78 101 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(); 79 119 } 80 120 … … 100 140 101 141 /** 102 * sets the storage to be used for storing the credentials142 * sets the storage to be used for storing the result 103 143 * 104 144 * @param stubAuthStorage $storage 105 145 */ 106 public function setStor e(stubAuthStorage $storage)146 public function setStorage(stubAuthStorage $storage) 107 147 { 108 148 $this->storage = $storage; … … 110 150 111 151 /** 152 * returns the storage 153 * 154 * @return stubAuthStorage 155 */ 156 public function getStorage() 157 { 158 return $this->storage; 159 } 160 161 /** 112 162 * authenticate the credentials 113 163 * 114 * @param mixed $credentials115 * @return stubAuth Result164 * @param mixed $credentials 165 * @return stubAuthStorage 116 166 */ 117 167 public function authenticate($credentials) 118 168 { 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; 125 171 } 126 172 } trunk/src/main/php/net/stubbles/auth/stubAuthResult.php
r754 r755 31 31 protected $credentials; 32 32 /** 33 * other authentication data, e.g. the instance of the authenticated user 34 * 35 * @var mixed 36 */ 37 protected $authData; 38 /** 33 39 * authentication status: authentication was successful 34 40 */ … … 48 54 * @param int $status status of result, one of the stubAuthResult::STATUS_ constants 49 55 * @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 50 57 */ 51 public function __construct($status, $credentials )58 public function __construct($status, $credentials, $authData = null) 52 59 { 53 60 $this->status = $status; 54 61 $this->credentials = $credentials; 62 $this->authData = $authData; 55 63 } 56 64 … … 76 84 return $this->credentials; 77 85 } 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 } 78 96 } 79 97 ?>
