public function __construct($server_version, $proxy, $server_hostname, $server_port, $server_uri, $changeSessionID = true)
{
// Argument validation
if (gettype($server_version) != 'string') {
throw new CAS_TypeMismatchException($server_version, '$server_version', 'string');
}
if (gettype($proxy) != 'boolean') {
throw new CAS_TypeMismatchException($proxy, '$proxy', 'boolean');
}
if (gettype($server_hostname) != 'string') {
throw new CAS_TypeMismatchException($server_hostname, '$server_hostname', 'string');
}
if (gettype($server_port) != 'integer') {
throw new CAS_TypeMismatchException($server_port, '$server_port', 'integer');
}
if (gettype($server_uri) != 'string') {
throw new CAS_TypeMismatchException($server_uri, '$server_uri', 'string');
}
if (gettype($changeSessionID) != 'boolean') {
throw new CAS_TypeMismatchException($changeSessionID, '$changeSessionID', 'boolean');
}
phpCAS::traceBegin();
// true : allow to change the session_id(), false session_id won't be
// change and logout won't be handle because of that
$this->_setChangeSessionID($changeSessionID);
// skip Session Handling for logout requests and if don't want it'
if (session_id() == "" && !$this->_isLogoutRequest()) {
session_start();
phpCAS::trace("Starting a new session " . session_id());
}
// Only for debug purposes
if ($this->isSessionAuthenticated()) {
phpCAS::trace("Session is authenticated as: " . $_SESSION['phpCAS']['user']);
} else {
phpCAS::trace("Session is not authenticated");
}
// are we in proxy mode ?
$this->_proxy = $proxy;
// Make cookie handling available.
if ($this->isProxy()) {
if (!isset($_SESSION['phpCAS'])) {
$_SESSION['phpCAS'] = array();
}
if (!isset($_SESSION['phpCAS']['service_cookies'])) {
$_SESSION['phpCAS']['service_cookies'] = array();
}
$this->_serviceCookieJar = new CAS_CookieJar($_SESSION['phpCAS']['service_cookies']);
}
//check version
switch ($server_version) {
case CAS_VERSION_1_0:
if ($this->isProxy()) {
phpCAS::error('CAS proxies are not supported in CAS ' . $server_version);
}
break;
case CAS_VERSION_2_0:
case CAS_VERSION_3_0:
break;
case SAML_VERSION_1_1:
break;
default:
phpCAS::error('this version of CAS (`' . $server_version . '\') is not supported by phpCAS ' . phpCAS::getVersion());
}
$this->_server['version'] = $server_version;
// check hostname
if (empty($server_hostname) || !preg_match('/[\\.\\d\\-abcdefghijklmnopqrstuvwxyz]*/', $server_hostname)) {
phpCAS::error('bad CAS server hostname (`' . $server_hostname . '\')');
}
$this->_server['hostname'] = $server_hostname;
// check port
if ($server_port == 0 || !is_int($server_port)) {
phpCAS::error('bad CAS server port (`' . $server_hostname . '\')');
}
$this->_server['port'] = $server_port;
// check URI
if (!preg_match('/[\\.\\d\\-_abcdefghijklmnopqrstuvwxyz\\/]*/', $server_uri)) {
phpCAS::error('bad CAS server URI (`' . $server_uri . '\')');
}
// add leading and trailing `/' and remove doubles
if (strstr($server_uri, '?') === false) {
$server_uri .= '/';
}
$server_uri = preg_replace('/\\/\\//', '/', '/' . $server_uri);
$this->_server['uri'] = $server_uri;
// set to callback mode if PgtIou and PgtId CGI GET parameters are provided
if ($this->isProxy()) {
$this->_setCallbackMode(!empty($_GET['pgtIou']) && !empty($_GET['pgtId']));
}
if ($this->_isCallbackMode()) {
//callback mode: check that phpCAS is secured
if (!$this->_isHttps()) {
phpCAS::error('CAS proxies must be secured to use phpCAS; PGT\'s will not be received from the CAS server');
}
} else {
//normal mode: get ticket and remove it from CGI parameters for
// developers
$ticket = isset($_GET['ticket']) ? $_GET['ticket'] : null;
if (preg_match('/^[SP]T-/', $ticket)) {
phpCAS::trace('Ticket \'' . $ticket . '\' found');
$this->setTicket($ticket);
unset($_GET['ticket']);
} else {
if (!empty($ticket)) {
//ill-formed ticket, halt
phpCAS::error('ill-formed ticket found in the URL (ticket=`' . htmlentities($ticket) . '\')');
}
}
}
phpCAS::traceEnd();
}