CAS_Client::setCasServerCACert PHP Method

setCasServerCACert() public method

Set the CA certificate of the CAS server.
public setCasServerCACert ( string $cert, boolean $validate_cn ) : void
$cert string the PEM certificate file name of the CA that emited the cert of the server
$validate_cn boolean valiate CN of the CAS server certificate
return void
    public function setCasServerCACert($cert, $validate_cn)
    {
        // Argument validation
        if (gettype($cert) != 'string') {
            throw new CAS_TypeMismatchException($cert, '$cert', 'string');
        }
        if (gettype($validate_cn) != 'boolean') {
            throw new CAS_TypeMismatchException($validate_cn, '$validate_cn', 'boolean');
        }
        if (!file_exists($cert) && $this->_requestImplementation !== 'CAS_TestHarness_DummyRequest') {
            throw new CAS_InvalidArgumentException("Certificate file does not exist " . $this->_requestImplementation);
        }
        $this->_cas_server_ca_cert = $cert;
        $this->_cas_server_cn_validate = $validate_cn;
    }

Usage Example

 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     //     	phpCAS::setDebug(dirname(__FILE__).'/../test.log');
     // 		error_reporting(E_ALL);
     CAS_GracefullTerminationException::throwInsteadOfExiting();
     $_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');
     /*********************************************************
      * Enumerate our responses
      *********************************************************/
     // Set up our response.
     $response = new CAS_TestHarness_BasicResponse('https', 'cas.example.edu', '/cas/serviceValidate');
     $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:authenticationSuccess>\n        <cas:user>jsmith</cas:user>\n    </cas:authenticationSuccess>\n</cas:serviceResponse>\n");
     CAS_TestHarness_DummyRequest::addResponse($response);
 }
All Usage Examples Of CAS_Client::setCasServerCACert
CAS_Client