phpCAS::setCasServerCACert PHP Method

setCasServerCACert() public static method

Set the certificate of the CAS server CA and if the CN should be properly verified.
public static setCasServerCACert ( string $cert, boolean $validate_cn = true ) : void
$cert string CA certificate file name
$validate_cn boolean Validate CN in certificate (default true)
return void
    public static function setCasServerCACert($cert, $validate_cn = true)
    {
        phpCAS::traceBegin();
        phpCAS::_validateClientExists();
        try {
            self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
        } catch (Exception $e) {
            phpCAS::error(get_class($e) . ': ' . $e->getMessage());
        }
        phpCAS::traceEnd();
    }

Usage Example

function check_cas_result($config)
{
    require_once dirname(__DIR__) . '/vendor/autoload.php';
    try {
        $cas_version = $config->cas_version ? $config->cas_version : CAS_VERSION_2_0;
        // phpCAS::setDebug();
        phpCAS::client($cas_version, $config->cashostname, (int) $config->casport, $config->casbaseuri, false);
        // don't automatically clear tickets from the url, we're taking care of that
        phpCAS::setNoClearTicketsFromUrl();
        // if a certificate is provided, use it, otherwise don't
        if ($config->cas_server_ca_cert_path != "") {
            // here we sould set the server certificate for production
            // '/etc/pki/tls/certs/DigiCertCA.crt'
            phpCAS::setCasServerCACert($config->cas_server_ca_cert_path);
        } else {
            // if you want to skip ssl verification
            if ($config->cas_server_no_validation) {
                phpCAS::setNoCasServerValidation();
            }
        }
        // check authentication; returns true/false
        if (phpCAS::checkAuthentication()) {
            // grab username
            $NetUsername = phpCAS::getUser();
            return $NetUsername;
        } else {
            return false;
        }
    } catch (Exception $e) {
        error_log("CAS ERROR: " . $e->getMessage());
        register_error($e->getMessage());
        return false;
    }
}
All Usage Examples Of phpCAS::setCasServerCACert