Advertisement
Guest User

Untitled

a guest
May 21st, 2012
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. namespace RD\RpcBase\Security\Authentication\Token;
  3.  
  4. use TYPO3\FLOW3\Annotations as FLOW3;
  5.  
  6. /**
  7.  *
  8.  */
  9. class UsernamePasswordRPC extends \TYPO3\FLOW3\Security\Authentication\Token\AbstractToken {
  10.  
  11.     /**
  12.      * @var \RD\RpcBase\Resource\RpcRequest
  13.      */
  14.     protected $rpcRequest;
  15.  
  16.     /**
  17.      * The username/password credentials
  18.      * @var array
  19.      * @FLOW3\Transient
  20.      */
  21.     protected $credentials = array('username' => '', 'password' => '');
  22.  
  23.     /**
  24.      * Initializes the object
  25.      *
  26.      * @return void
  27.      */
  28.  
  29.     public function initializeObject() {
  30.  
  31.         $entryPoint = new \RD\RpcBase\Security\Authentication\EntryPoint\RPCCall();
  32.         $this->setAuthenticationEntryPoint($entryPoint);
  33.  
  34.     }
  35.  
  36.     /**
  37.      * Updates the username and password credentials from the HTTP authorization header.
  38.      * Sets the authentication status to AUTHENTICATION_NEEDED, if the header has been
  39.      * sent, to NO_CREDENTIALS_GIVEN if no authorization header was there.
  40.      *
  41.      * @param \TYPO3\FLOW3\Http\Request $request The current action request
  42.      * @return void
  43.      */
  44.     public function updateCredentials(\TYPO3\FLOW3\Http\Request $request) {
  45.  
  46.         $this->rpcRequest = new \RD\RpcBase\Resource\RpcRequest(file_get_contents('php://input'));
  47.  
  48.         if (isset($this->rpcRequest->getCurrentParams()->username) && isset($this->rpcRequest->getCurrentParams()->password)) {
  49.  
  50.             $this->credentials['username'] = $this->rpcRequest->getCurrentParams()->username;
  51.             $this->credentials['password'] = $this->rpcRequest->getCurrentParams()->password;
  52.             $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED);
  53.         }
  54.  
  55.     }
  56.  
  57.     /**
  58.      * Returns a string representation of the token for logging purposes.
  59.      *
  60.      * @return string The username credential
  61.      */
  62.     public function  __toString() {
  63.         return 'Username: "' . $this->credentials['username'] . '"';
  64.     }
  65.  
  66.  
  67. }
  68.  
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement