Esempio n. 1
0
 /**
  * Validate the account information (username and password are correct)
  * @param $username
  * @param $password
  */
 public static function validateAccount($username, $password)
 {
     global $configArray;
     // Perform authentication:
     $authN = AuthenticationFactory::initAuthentication($configArray['Authentication']['method']);
     return $authN->validateAccount($username, $password);
 }
 public function test_invoke_ILS_authN_handler()
 {
     try {
         $authN = AuthenticationFactory::initAuthentication('ILS');
         $this->assertNotNull($authN);
     } catch (Exception $unexpected) {
         $this->fail('An unexpected exception has been raised:' . $unexpected);
     }
     return;
 }
 public function testAuthentication()
 {
     try {
         $_SERVER['entitlement'] = 'urn:mace:dir:entitlement:common-lib-terms';
         $_SERVER['persistent_id'] = '1234_1234';
         $_SERVER['unscoped_affiliation'] = 'member';
         $authN = AuthenticationFactory::initAuthentication('Shibboleth');
         $user = $authN->authenticate();
         print_r($user);
     } catch (Exception $expected) {
         $this->fail('An expected UnknownAuthenticationMethodException has not been raised.');
     }
 }
Esempio n. 4
0
 /**
  * Verify Persona assertion and log the user in
  *
  * @return true
  * @access public
  */
 public function login()
 {
     try {
         $authN = AuthenticationFactory::initAuthentication('MozillaPersona');
         $user = $authN->authenticate();
     } catch (Exception $e) {
         if ($configArray['System']['debug']) {
             error_log("Exception: " . $e->getMessage());
         }
         return $this->output(false, JSON::STATUS_ERROR);
     }
     // If we authenticated, store the user in the session:
     if (PEAR::isError($user)) {
         error_log('Persona login error: ' . $user->getMessage());
         return $this->output(false, JSON::STATUS_ERROR);
     }
     unset($_SESSION['no_store']);
     UserAccount::updateSession($user);
     return $this->output(true, JSON::STATUS_OK);
 }
Esempio n. 5
0
 /**
  * Try to log in the user using current query parameters; return User object
  * on success, PEAR error on failure.
  *
  * @param string $method Optional method to override configuration
  *
  * @return object
  * @access public
  */
 public static function login($method = '')
 {
     global $configArray;
     // Perform authentication:
     try {
         $authN = AuthenticationFactory::initAuthentication($method ? $method : $configArray['Authentication']['method']);
         $user = $authN->authenticate();
     } catch (Exception $e) {
         if ($configArray['System']['debug']) {
             echo "Exception: " . $e->getMessage();
         }
         error_log("Authentication exception: " . $e->getMessage());
         $user = new PEAR_Error('authentication_error_technical');
     }
     // If we authenticated, store the user in the session:
     if ($user && !PEAR::isError($user)) {
         self::verifyAccountInList($user);
         self::updateSession($user);
     }
     // Send back the user object (which may be a PEAR error):
     return $user;
 }
 /**
  * Do the actual work of authenticating the user (support method for
  * authenticate()).
  *
  * @return object User object if successful, PEAR_Error otherwise.
  * @access private
  */
 private function _authUser()
 {
     // Try authentication methods until we find one that works:
     foreach ($this->_methods as $method) {
         $authenticator = AuthenticationFactory::initAuthentication(trim($method));
         $user = $authenticator->authenticate();
         if (!PEAR::isError($user)) {
             break;
         }
     }
     // At this point, there are three possibilities: $user is a valid,
     // logged-in user; $user is a PEAR_Error that we need to return; or
     // $user is undefined, indicating that $this->_methods is empty and
     // thus something is wrong!
     return isset($user) ? $user : new PEAR_Error('authentication_error_technical');
 }
Esempio n. 7
0
</head>
<body>

<?php 
require_once 'Navigation.php';
require_once 'Authentication.php';
/*
 *	Encode array into JSON
 */
function json($data)
{
    if (is_array($data)) {
        return json_encode($data);
    }
}
$func = AuthenticationFactory::create();
if (is_null($func)) {
    echo "Nothing in login";
} else {
    $result = $func->RecoverAccount("*****@*****.**");
    echo json($result);
}
// $func = AuthenticationFactory::create();
// if(is_null($func))
// 	echo "Nothing in login";
// else
// 	echo json($func->IsAdminRegister());
// $nav = NavigationFactory::create();
// if(is_null($nav))
// 	echo "Nothing in Navigation";
// else
Esempio n. 8
0
 private function recoverAccount()
 {
     if ($this->get_request_method() != "POST") {
         $this->response('', 406);
     }
     $data = json_decode(file_get_contents("php://input"), true);
     $email = $data['email'];
     $func = AuthenticationFactory::create();
     if (is_null($func)) {
         $this->response('', 406);
     } else {
         $result = $func->RecoverAccount($email);
         if ($result['status'] == "success") {
             $this->response($this->json($result), 200);
         } else {
             $this->response($this->json($result), 406);
         }
     }
 }