forceAuthentication() 공개 메소드

This method is called to be sure that the user is authenticated. When not authenticated, halt by redirecting to the CAS server; otherwise return true.
public forceAuthentication ( ) : true
리턴 true when the user is authenticated; otherwise halt.
 /**
  * Test that the user is redirected to the CAS server
  */
 public function test_redirect()
 {
     try {
         ob_start();
         $this->object->forceAuthentication();
         $this->assertTrue(false, 'Should have thrown a CAS_GracefullTerminationException.');
     } catch (CAS_GracefullTerminationException $e) {
         ob_end_clean();
         // It would be great to test for the existance of headers here, but
         // the don't get set properly due to output before the test.
     }
 }
예제 #2
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     //     	phpCAS::setDebug(dirname(__FILE__).'/../test.log');
     // 		error_reporting(E_ALL);
     $_SERVER['SERVER_NAME'] = 'www.clientapp.com';
     $_SERVER['SERVER_PORT'] = '80';
     $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
     $_SERVER['SERVER_ADMIN'] = 'root@localhost';
     $_SERVER['REQUEST_URI'] = '/';
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     $_SERVER['PHP_SELF'] = '/index.php';
     $_SESSION = array();
     $this->object = new CAS_Client(CAS_VERSION_2_0, true, 'cas.example.edu', 443, '/cas/', false);
     $this->object->setRequestImplementation('CAS_TestHarness_DummyRequest');
     $this->object->setCasServerCACert('/path/to/ca_cert.crt');
     // Bypass PGT storage since CAS_Client->callback() will exit. Just build
     // up the session manually so that we are in a state from which we can
     // attempt to fetch proxy tickets and make proxied requests.
     $_SESSION['phpCAS']['user'] = '******';
     $_SESSION['phpCAS']['pgt'] = 'PGT-clientapp-abc123';
     $_SESSION['phpCAS']['proxies'] = array();
     $_SESSION['phpCAS']['service_cookies'] = array();
     $_SESSION['phpCAS']['attributes'] = array();
     // Force Authentication to initialize the client.
     $this->object->forceAuthentication();
     /*********************************************************
      * Enumerate our responses
      *********************************************************/
     /*********************************************************
      * 1. Valid Proxy ticket and service
      *********************************************************/
     // Proxy ticket Response
     $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy');
     $response->matchQueryParameters(array('targetService' => 'http://www.service.com/my_webservice', 'pgt' => 'PGT-clientapp-abc123'));
     $response->ensureIsGet();
     $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked'));
     $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n    <cas:proxySuccess>\n        <cas:proxyTicket>PT-asdfas-dfasgww2323radf3</cas:proxyTicket>\n    </cas:proxySuccess>\n</cas:serviceResponse>\n");
     $response->ensureCaCertPathEquals('/path/to/ca_cert.crt');
     CAS_TestHarness_DummyRequest::addResponse($response);
     // Valid Service Response
     $response = new CAS_TestHarness_BasicResponse('http', 'www.service.com', '/my_webservice');
     $response->matchQueryParameters(array('ticket' => 'PT-asdfas-dfasgww2323radf3'));
     $response->ensureIsGet();
     $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/plain;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked'));
     $response->setResponseBody("Hello from the service.");
     CAS_TestHarness_DummyRequest::addResponse($response);
     /*********************************************************
      * 2. Proxy Ticket Error
      *********************************************************/
     // Error Proxy ticket Response
     $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy');
     $response->matchQueryParameters(array('targetService' => 'http://www.service.com/my_other_webservice', 'pgt' => 'PGT-clientapp-abc123'));
     $response->ensureIsGet();
     $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked'));
     $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n    <cas:proxyFailure code='INTERNAL_ERROR'>\n        an internal error occurred during ticket validation\n    </cas:proxyFailure>\n</cas:serviceResponse>\n");
     $response->ensureCaCertPathEquals('/path/to/ca_cert.crt');
     CAS_TestHarness_DummyRequest::addResponse($response);
     /*********************************************************
      * 3. Server that doesn't respond/exist (sending failure)
      *********************************************************/
     // Proxy ticket Response
     $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy');
     $response->matchQueryParameters(array('targetService' => 'ssh://me.example.net', 'pgt' => 'PGT-clientapp-abc123'));
     $response->ensureIsGet();
     $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked'));
     $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n    <cas:proxySuccess>\n        <cas:proxyTicket>PT-ssh-1234abce</cas:proxyTicket>\n    </cas:proxySuccess>\n</cas:serviceResponse>\n");
     $response->ensureCaCertPathEquals('/path/to/ca_cert.crt');
     CAS_TestHarness_DummyRequest::addResponse($response);
     /*********************************************************
      * 4. Service With Error status.
      *********************************************************/
     // Proxy ticket Response
     $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy');
     $response->matchQueryParameters(array('targetService' => 'http://www.service.com/my_webservice_that_has_problems', 'pgt' => 'PGT-clientapp-abc123'));
     $response->ensureIsGet();
     $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked'));
     $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n    <cas:proxySuccess>\n        <cas:proxyTicket>PT-12345-abscasdfasdf</cas:proxyTicket>\n    </cas:proxySuccess>\n</cas:serviceResponse>\n");
     $response->ensureCaCertPathEquals('/path/to/ca_cert.crt');
     CAS_TestHarness_DummyRequest::addResponse($response);
     // Service Error Response
     $response = new CAS_TestHarness_BasicResponse('http', 'www.service.com', '/my_webservice_that_has_problems');
     $response->matchQueryParameters(array('ticket' => 'PT-12345-abscasdfasdf'));
     $response->ensureIsGet();
     $response->setResponseHeaders(array('HTTP/1.1 500 INTERNAL SERVER ERROR', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/plain;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked'));
     $response->setResponseBody("Problems have Occurred.");
     CAS_TestHarness_DummyRequest::addResponse($response);
     /*********************************************************
      * 5. Valid Proxy ticket and POST service
      *********************************************************/
     // Proxy ticket Response
     $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy');
     $response->matchQueryParameters(array('targetService' => 'http://www.service.com/post_webservice', 'pgt' => 'PGT-clientapp-abc123'));
     $response->ensureIsGet();
     $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked'));
     $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n    <cas:proxySuccess>\n        <cas:proxyTicket>PT-posting-dfasgww2323radf3</cas:proxyTicket>\n    </cas:proxySuccess>\n</cas:serviceResponse>\n");
     $response->ensureCaCertPathEquals('/path/to/ca_cert.crt');
     CAS_TestHarness_DummyRequest::addResponse($response);
     // Valid Service Response
     $response = new CAS_TestHarness_BasicResponse('http', 'www.service.com', '/post_webservice');
     $response->matchQueryParameters(array('ticket' => 'PT-posting-dfasgww2323radf3'));
     $response->ensureIsPost();
     $response->ensurePostBodyEquals('<request><method>doSomething</method><param type="string">with this</param></request>');
     $response->ensureHasHeader('Content-Length: ' . strlen('<request><method>doSomething</method><param type="string">with this</param></request>'));
     $response->ensureHasHeader('Content-Type: text/xml');
     $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/xml;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked'));
     $response->setResponseBody("<result><string>Yay, it worked.</string></result>");
     CAS_TestHarness_DummyRequest::addResponse($response);
 }
예제 #3
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     //     	phpCAS::setDebug(dirname(__FILE__).'/../test.log');
     // 		error_reporting(E_ALL);
     $_SERVER['SERVER_NAME'] = 'www.clientapp.com';
     $_SERVER['SERVER_PORT'] = '80';
     $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
     $_SERVER['SERVER_ADMIN'] = 'root@localhost';
     $_SERVER['REQUEST_URI'] = '/';
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     $_SERVER['PHP_SELF'] = '/index.php';
     $_SESSION = array();
     $this->object = new CAS_Client(CAS_VERSION_2_0, true, 'cas.example.edu', 443, '/cas/', false);
     $this->object->setRequestImplementation('CAS_TestHarness_DummyRequest');
     $this->object->setCasServerCACert('/path/to/ca_cert.crt', true);
     // Bypass PGT storage since CAS_Client->callback() will exit. Just build
     // up the session manually so that we are in a state from which we can
     // attempt to fetch proxy tickets and make proxied requests.
     $_SESSION['phpCAS']['user'] = '******';
     $_SESSION['phpCAS']['pgt'] = 'PGT-clientapp-abc123';
     $_SESSION['phpCAS']['proxies'] = array();
     $_SESSION['phpCAS']['service_cookies'] = array();
     $_SESSION['phpCAS']['attributes'] = array();
     // Force Authentication to initialize the client.
     $this->object->forceAuthentication();
     /*********************************************************
      * Enumerate our responses
      *********************************************************/
     /*********************************************************
      * 1. Valid Proxy ticket and service
      *********************************************************/
     // Proxy ticket Response
     $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy');
     $response->matchQueryParameters(array('targetService' => 'imap://mail.example.edu/path/to/something', 'pgt' => 'PGT-clientapp-abc123'));
     $response->ensureIsGet();
     $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked'));
     $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n    <cas:proxySuccess>\n        <cas:proxyTicket>PT-asdfas-dfasgww2323radf3</cas:proxyTicket>\n    </cas:proxySuccess>\n</cas:serviceResponse>\n");
     $response->ensureCaCertPathEquals('/path/to/ca_cert.crt');
     CAS_TestHarness_DummyRequest::addResponse($response);
     /*********************************************************
      * 2. Proxy Ticket Error
      *********************************************************/
     // Error Proxy ticket Response
     $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/proxy');
     $response->matchQueryParameters(array('targetService' => 'imap://mail.example.edu/path/that/doesnt/exist', 'pgt' => 'PGT-clientapp-abc123'));
     $response->ensureIsGet();
     $response->setResponseHeaders(array('HTTP/1.1 200 OK', 'Date: Wed, 29 Sep 2010 19:20:57 GMT', 'Server: Apache-Coyote/1.1', 'Pragma: no-cache', 'Expires: Thu, 01 Jan 1970 00:00:00 GMT', 'Cache-Control: no-cache, no-store', 'Content-Type: text/html;charset=UTF-8', 'Content-Language: en-US', 'Via: 1.1 cas.example.edu', 'Connection: close', 'Transfer-Encoding: chunked'));
     $response->setResponseBody("<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n    <cas:proxyFailure code='INTERNAL_ERROR'>\n        an internal error occurred during ticket validation\n    </cas:proxyFailure>\n</cas:serviceResponse>\n");
     $response->ensureCaCertPathEquals('/path/to/ca_cert.crt');
     CAS_TestHarness_DummyRequest::addResponse($response);
     /*********************************************************
      * Ensure that IMAP constants are defined even if the IMAP
      * module is not installed.
      *********************************************************/
     if (!defined('OP_READONLY')) {
         // Not sure what this should actually  be. It is defined as:
         //  REGISTER_LONG_CONSTANT(
         //      "OP_READONLY", OP_READONLY, CONST_PERSISTENT | CONST_CS
         //  );
         // in http://php-imap.sourcearchive.com/lines/5.1.2-1/php__imap_8c-source.html
         // For now, just ensure that it is an integer.
         define('OP_READONLY', 1);
     }
 }
예제 #4
0
파일: CAS.php 프로젝트: DCUnit711/Demeter
 /**
  * This method is called to force authentication if the user was not already
  * authenticated. If the user is not authenticated, halt by redirecting to
  * the CAS server.
  *
  * @return bool Authentication
  */
 public static function forceAuthentication()
 {
     phpCAS::traceBegin();
     phpCAS::_validateClientExists();
     $auth = self::$_PHPCAS_CLIENT->forceAuthentication();
     // store where the authentication has been checked and the result
     self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
     /*      if (!$auth) {
              phpCAS :: trace('user is not authenticated, redirecting to the CAS server');
             self::$_PHPCAS_CLIENT->forceAuthentication();
             } else {
             phpCAS :: trace('no need to authenticate (user `' . phpCAS :: getUser() . '\' is already authenticated)');
             }*/
     phpCAS::traceEnd();
     return $auth;
 }