-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuth.php
61 lines (53 loc) · 1.75 KB
/
Auth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
class RM_Auth {
/**
* @var Zend_Controller_Action
*/
private $_controller;
/**
* @var Zend_Auth_Adapter_Http_Resolver_Interface
*/
private $_authResolver;
private $_authAdapterClassName;
/**
* @param Zend_Controller_Action $controller
* @param Zend_Auth_Adapter_Http_Resolver_Interface $resolver
* @param $authAdapterName
*/
public function __construct(
Zend_Controller_Action $controller,
Zend_Auth_Adapter_Http_Resolver_Interface $resolver,
$authAdapterName
) {
$this->_controller = $controller;
$this->_authResolver = $resolver;
$this->_authAdapterClassName = $this->_validateAdapter( $authAdapterName );
}
/**
* @return Zend_Auth_Result
*/
public function authenticate() {
$auth = Zend_Auth::getInstance();
return $auth->authenticate( $this->_getHttpAuth() );
}
private function _getHttpAuth() {
/* @var Zend_Auth_Adapter_Http $httpAuth*/
$httpAuth = new $this->_authAdapterClassName(array(
'accept_schemes' => 'basic',
'realm' => Zend_Registry::get('cfg')['domain']
//TODO add params
) );
//Zend_Auth_Adapter_Interface
$httpAuth->setRequest( $this->_controller->getRequest() );
$httpAuth->setResponse( $this->_controller->getResponse() );
$httpAuth->setBasicResolver( $this->_authResolver );
return $httpAuth;
}
private function _validateAdapter( $authAdapterName ) {
$classRef = new Zend_Reflection_Class( $authAdapterName );
if (!$classRef->isSubclassOf('Zend_Auth_Adapter_Http')) {
throw RM_Auth_Exception::wrongAdapter();
}
return $authAdapterName;
}
}