Example #1
0
 public function testSetRoleId()
 {
     $roleLocator = new Mage_Webapi_Model_Authorization_RoleLocator();
     $expectedRoleId = '557';
     $roleLocator->setRoleId($expectedRoleId);
     $this->assertAttributeEquals($expectedRoleId, '_roleId', $roleLocator);
 }
Example #2
0
 /**
  * Authenticate user.
  *
  * @throws Mage_Webapi_Exception If authentication failed
  */
 public function authenticate()
 {
     try {
         $consumer = $this->_oauthServer->authenticateTwoLegged();
         $this->_roleLocator->setRoleId($consumer->getRoleId());
     } catch (Exception $e) {
         throw new Mage_Webapi_Exception($this->_oauthServer->reportProblem($e), Mage_Webapi_Exception::HTTP_UNAUTHORIZED);
     }
 }
Example #3
0
 /**
  * Authenticate user.
  *
  * @param stdClass $usernameToken WS-Security UsernameToken object
  * @throws Mage_Webapi_Exception If authentication failed
  */
 public function authenticate($usernameToken)
 {
     try {
         $token = $this->_tokenFactory->createFromArray();
         $request = $usernameToken;
         // @codingStandardsIgnoreStart
         $user = $token->authenticate($request->Username, $request->Password, $request->Created, $request->Nonce);
         // @codingStandardsIgnoreEnd
         $this->_roleLocator->setRoleId($user->getRoleId());
     } catch (Mage_Webapi_Model_Soap_Security_UsernameToken_NonceUsedException $e) {
         throw new Mage_Webapi_Exception($this->_helper->__('WS-Security UsernameToken Nonce is already used.'), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
     } catch (Mage_Webapi_Model_Soap_Security_UsernameToken_TimestampRefusedException $e) {
         throw new Mage_Webapi_Exception($this->_helper->__('WS-Security UsernameToken Created timestamp is refused.'), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
     } catch (Mage_Webapi_Model_Soap_Security_UsernameToken_InvalidCredentialException $e) {
         throw new Mage_Webapi_Exception($this->_helper->__('Invalid Username or Password.'), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
     } catch (Mage_Webapi_Model_Soap_Security_UsernameToken_InvalidDateException $e) {
         throw new Mage_Webapi_Exception($this->_helper->__('Invalid UsernameToken Created date.'), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
     }
 }