/** * Sets a single instance of * Piece_Unity_Service_Authentication_State to the property. */ function Piece_Unity_Service_Authentication() { $this->_state =& Piece_Unity_Service_Authentication_State::singleton(); }
/** * Sets the Piece_Unity_Service_Authentication_State object to the session. */ private function _prepareAuthenticationState() { $session = $this->context->getSession(); $authenticationState = $session->getAttribute(self::SESSION_KEY); if (is_null($authenticationState)) { $authenticationState = Piece_Unity_Service_Authentication_State::singleton(); $session->setAttributeByRef(self::SESSION_KEY, $authenticationState); $session->setPreloadCallback('_Interceptor_Authentication', array('Piece_Unity_Plugin_Factory', 'factory')); $session->addPreloadClass('_Interceptor_Authentication', 'Interceptor_Authentication'); } else { Piece_Unity_Service_Authentication_State::setInstance($authenticationState); } $this->_authenticationState = $authenticationState; }
/** * Sets a single instance of Piece_Unity_Service_Authentication_State to * the property. */ public function __construct() { $this->_state = Piece_Unity_Service_Authentication_State::singleton(); }
/** * @test */ public function redirectTheRequestToTheCallbackUriOfTheGivenRealm() { Piece_Unity_Service_Authentication_State::singleton()->setCallbackURI('Foo', 'http://example.org/path/to/callback.php'); $config = new Piece_Unity_Config(); $context = Piece_Unity_Context::singleton(); $context->setConfiguration($config); $this->assertFalse($this->_authentication->isAuthenticated('Foo')); $this->_authentication->login('Foo'); $this->assertTrue($this->_authentication->hasCallbackURI('Foo')); $this->_authentication->redirectToCallbackURI('Foo'); $this->assertEquals('http://example.org/path/to/callback.php', $context->getView()); $this->assertTrue($config->getConfiguration('Renderer_Redirection', 'isExternal')); }
/** * Sets the Piece_Unity_Service_Authentication_State object to the session. */ function _prepareAuthenticationState() { $session =& $this->_context->getSession(); $authenticationState =& $session->getAttribute($GLOBALS['PIECE_UNITY_Interceptor_Authentication_AuthenticationStateSessionKey']); if (is_null($authenticationState)) { $authenticationState =& Piece_Unity_Service_Authentication_State::singleton(); $session->setAttributeByRef($GLOBALS['PIECE_UNITY_Interceptor_Authentication_AuthenticationStateSessionKey'], $authenticationState); $session->setPreloadCallback('_Interceptor_Authentication', array('Piece_Unity_Plugin_Factory', 'factory')); $session->addPreloadClass('_Interceptor_Authentication', 'Interceptor_Authentication'); } else { Piece_Unity_Service_Authentication_State::setInstance($authenticationState); } $this->_authenticationState =& $authenticationState; }
/** * @test * @since Method available since Release 1.0.0 */ public function keepTheCallbackUriIfTheAuthenticationUriIsRequestedDirectly() { $_SERVER['SERVER_NAME'] = 'example.org'; $_SERVER['SERVER_PORT'] = '80'; $_SERVER['REQUEST_URI'] = '/admin/foo.php'; $configurations = array('uri' => 'http://example.org/authenticate.php', 'includes' => array('^/admin/foo\\.php$', '^/admin/bar\\.php$')); $this->_configure($configurations); $interceptor = new Piece_Unity_Plugin_Interceptor_Authentication(); $interceptor->intercept(); $this->assertEquals('http://example.org/authenticate.php', Piece_Unity_Context::singleton()->getView()); $authenticationState = Piece_Unity_Service_Authentication_State::singleton(); $this->assertTrue($authenticationState->hasCallbackURI(null)); $this->assertEquals('http://example.org/admin/foo.php', $authenticationState->getCallbackURI(null)); $_SERVER['SERVER_NAME'] = 'example.org'; $_SERVER['SERVER_PORT'] = '80'; $_SERVER['REQUEST_URI'] = '/authenticate.php'; $configurations = array('uri' => 'http://example.org/authenticate.php', 'includes' => array('^/admin/foo\\.php$', '^/admin/bar\\.php$')); $this->_configure($configurations); Piece_Unity_Context::singleton()->setView('Bar'); Piece_Unity_Context::singleton()->setScriptName('/authenticate.php'); $interceptor = new Piece_Unity_Plugin_Interceptor_Authentication(); $interceptor->intercept(); $this->assertEquals('Bar', Piece_Unity_Context::singleton()->getView()); $this->assertTrue($authenticationState->hasCallbackURI(null)); $this->assertEquals('http://example.org/admin/foo.php', $authenticationState->getCallbackURI(null)); $_SERVER['SERVER_NAME'] = 'example.org'; $_SERVER['SERVER_PORT'] = '80'; $_SERVER['REQUEST_URI'] = '/authenticate.php'; $configurations = array('uri' => 'http://example.org/authenticate.php', 'includes' => array('^/admin/foo\\.php$', '^/admin/bar\\.php$')); $this->_configure($configurations); Piece_Unity_Context::singleton()->setView('Bar'); Piece_Unity_Context::singleton()->setScriptName('/authenticate.php'); $interceptor = new Piece_Unity_Plugin_Interceptor_Authentication(); $interceptor->intercept(); $this->assertEquals('Bar', Piece_Unity_Context::singleton()->getView()); $this->assertTrue($authenticationState->hasCallbackURI(null)); $this->assertEquals('http://example.org/admin/foo.php', $authenticationState->getCallbackURI(null)); }