Advertisement
Guest User

Untitled

a guest
May 21st, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. <?php
  2. namespace TYPO3\FLOW3\Security\Authentication\Token;
  3.  
  4. /* *
  5. * This script belongs to the FLOW3 framework. *
  6. * *
  7. * It is free software; you can redistribute it and/or modify it under *
  8. * the terms of the GNU Lesser General Public License, either version 3 *
  9. * of the License, or (at your option) any later version. *
  10. * *
  11. * The TYPO3 project - inspiring people to share! *
  12. * */
  13.  
  14. use TYPO3\FLOW3\Annotations as FLOW3;
  15.  
  16. /**
  17. * An authentication token used for simple username and password authentication.
  18. */
  19. class UsernamePassword extends \TYPO3\FLOW3\Security\Authentication\Token\AbstractToken {
  20.  
  21. /**
  22. * The username/password credentials
  23. * @var array
  24. * @FLOW3\Transient
  25. */
  26. protected $credentials = array('username' => '', 'password' => '');
  27.  
  28. /**
  29. * Updates the username and password credentials from the POST vars, if the POST parameters
  30. * are available. Sets the authentication status to REAUTHENTICATION_NEEDED, if credentials have been sent.
  31. *
  32. * Note: You need to send the username and password in these two POST parameters:
  33. * __authentication[TYPO3][FLOW3][Security][Authentication][Token][UsernamePassword][username]
  34. * and __authentication[TYPO3][FLOW3][Security][Authentication][Token][UsernamePassword][password]
  35. *
  36. * @param \TYPO3\FLOW3\Mvc\ActionRequest $actionRequest The current action request
  37. * @return void
  38. */
  39. public function updateCredentials(\TYPO3\FLOW3\Mvc\ActionRequest $actionRequest) {
  40. $httpRequest = $actionRequest->getHttpRequest();
  41. if ($httpRequest->getMethod() !== 'POST') {
  42. return;
  43. }
  44.  
  45. $arguments = $actionRequest->getInternalArguments();
  46. $username = \TYPO3\FLOW3\Reflection\ObjectAccess::getPropertyPath($arguments, '__authentication.TYPO3.FLOW3.Security.Authentication.Token.UsernamePassword.username');
  47. $password = \TYPO3\FLOW3\Reflection\ObjectAccess::getPropertyPath($arguments, '__authentication.TYPO3.FLOW3.Security.Authentication.Token.UsernamePassword.password');
  48.  
  49. if (!empty($username) && !empty($password)) {
  50. $this->credentials['username'] = $username;
  51. $this->credentials['password'] = $password;
  52.  
  53. $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED);
  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. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement