mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
New version of PHPCAS
This commit is contained in:
380
include/phpCAS/CAS/Request/AbstractRequest.php
Normal file
380
include/phpCAS/CAS/Request/AbstractRequest.php
Normal file
@@ -0,0 +1,380 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Licensed to Jasig under one or more contributor license
|
||||
* agreements. See the NOTICE file distributed with this work for
|
||||
* additional information regarding copyright ownership.
|
||||
*
|
||||
* Jasig licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* PHP Version 7
|
||||
*
|
||||
* @file CAS/Request/AbstractRequest.php
|
||||
* @category Authentication
|
||||
* @package PhpCAS
|
||||
* @author Adam Franco <afranco@middlebury.edu>
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://wiki.jasig.org/display/CASC/phpCAS
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides support for performing web-requests via curl
|
||||
*
|
||||
* @class CAS_Request_AbstractRequest
|
||||
* @category Authentication
|
||||
* @package PhpCAS
|
||||
* @author Adam Franco <afranco@middlebury.edu>
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://wiki.jasig.org/display/CASC/phpCAS
|
||||
*/
|
||||
abstract class CAS_Request_AbstractRequest
|
||||
implements CAS_Request_RequestInterface
|
||||
{
|
||||
|
||||
protected $url = null;
|
||||
protected $cookies = array();
|
||||
protected $headers = array();
|
||||
protected $isPost = false;
|
||||
protected $postBody = null;
|
||||
protected $caCertPath = null;
|
||||
protected $validateCN = true;
|
||||
private $_sent = false;
|
||||
private $_responseHeaders = array();
|
||||
private $_responseBody = null;
|
||||
private $_errorMessage = '';
|
||||
|
||||
/*********************************************************
|
||||
* Configure the Request
|
||||
*********************************************************/
|
||||
|
||||
/**
|
||||
* Set the URL of the Request
|
||||
*
|
||||
* @param string $url Url to set
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function setUrl ($url)
|
||||
{
|
||||
if ($this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has already been sent cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a cookie to the request.
|
||||
*
|
||||
* @param string $name Name of entry
|
||||
* @param string $value value of entry
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function addCookie ($name, $value)
|
||||
{
|
||||
if ($this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has already been sent cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
|
||||
$this->cookies[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an array of cookies to the request.
|
||||
* The cookie array is of the form
|
||||
* array('cookie_name' => 'cookie_value', 'cookie_name2' => cookie_value2')
|
||||
*
|
||||
* @param array $cookies cookies to add
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function addCookies (array $cookies)
|
||||
{
|
||||
if ($this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has already been sent cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
|
||||
$this->cookies = array_merge($this->cookies, $cookies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a header string to the request.
|
||||
*
|
||||
* @param string $header Header to add
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function addHeader ($header)
|
||||
{
|
||||
if ($this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has already been sent cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
|
||||
$this->headers[] = $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an array of header strings to the request.
|
||||
*
|
||||
* @param array $headers headers to add
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function addHeaders (array $headers)
|
||||
{
|
||||
if ($this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has already been sent cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
|
||||
$this->headers = array_merge($this->headers, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the request a POST request rather than the default GET request.
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function makePost ()
|
||||
{
|
||||
if ($this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has already been sent cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
|
||||
$this->isPost = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a POST body to the request
|
||||
*
|
||||
* @param string $body body to add
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function setPostBody ($body)
|
||||
{
|
||||
if ($this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has already been sent cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
if (!$this->isPost) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Cannot add a POST body to a GET request, use makePost() first.'
|
||||
);
|
||||
}
|
||||
|
||||
$this->postBody = $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the path to an SSL CA certificate to validate the server with.
|
||||
*
|
||||
* @param string $caCertPath path to cert
|
||||
* @param bool $validate_cn valdiate CN of certificate
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function setSslCaCert ($caCertPath,$validate_cn=true)
|
||||
{
|
||||
if ($this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has already been sent cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
$this->caCertPath = $caCertPath;
|
||||
$this->validateCN = $validate_cn;
|
||||
}
|
||||
|
||||
/*********************************************************
|
||||
* 2. Send the Request
|
||||
*********************************************************/
|
||||
|
||||
/**
|
||||
* Perform the request.
|
||||
*
|
||||
* @return bool TRUE on success, FALSE on failure.
|
||||
* @throws CAS_OutOfSequenceException If called multiple times.
|
||||
*/
|
||||
public function send ()
|
||||
{
|
||||
if ($this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has already been sent cannot send again.'
|
||||
);
|
||||
}
|
||||
if (is_null($this->url) || !$this->url) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'A url must be specified via setUrl() before the request can be sent.'
|
||||
);
|
||||
}
|
||||
$this->_sent = true;
|
||||
return $this->sendRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the request and store the results.
|
||||
*
|
||||
* @return bool TRUE on success, FALSE on failure.
|
||||
*/
|
||||
abstract protected function sendRequest ();
|
||||
|
||||
/**
|
||||
* Store the response headers.
|
||||
*
|
||||
* @param array $headers headers to store
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function storeResponseHeaders (array $headers)
|
||||
{
|
||||
$this->_responseHeaders = array_merge($this->_responseHeaders, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a single response header to our array.
|
||||
*
|
||||
* @param string $header header to store
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function storeResponseHeader ($header)
|
||||
{
|
||||
$this->_responseHeaders[] = $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the response body.
|
||||
*
|
||||
* @param string $body body to store
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function storeResponseBody ($body)
|
||||
{
|
||||
$this->_responseBody = $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a string to our error message.
|
||||
*
|
||||
* @param string $message message to add
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function storeErrorMessage ($message)
|
||||
{
|
||||
$this->_errorMessage .= $message;
|
||||
}
|
||||
|
||||
/*********************************************************
|
||||
* 3. Access the response
|
||||
*********************************************************/
|
||||
|
||||
/**
|
||||
* Answer the headers of the response.
|
||||
*
|
||||
* @return array An array of header strings.
|
||||
* @throws CAS_OutOfSequenceException If called before the Request has been sent.
|
||||
*/
|
||||
public function getResponseHeaders ()
|
||||
{
|
||||
if (!$this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has not been sent yet. Cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
return $this->_responseHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer HTTP status code of the response
|
||||
*
|
||||
* @return int
|
||||
* @throws CAS_OutOfSequenceException If called before the Request has been sent.
|
||||
* @throws CAS_Request_Exception if the response did not contain a status code
|
||||
*/
|
||||
public function getResponseStatusCode ()
|
||||
{
|
||||
if (!$this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has not been sent yet. Cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
|
||||
if (!preg_match(
|
||||
'/HTTP\/[0-9.]+\s+([0-9]+)\s*(.*)/',
|
||||
$this->_responseHeaders[0], $matches
|
||||
)
|
||||
) {
|
||||
throw new CAS_Request_Exception(
|
||||
'Bad response, no status code was found in the first line.'
|
||||
);
|
||||
}
|
||||
|
||||
return intval($matches[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer the body of response.
|
||||
*
|
||||
* @return string
|
||||
* @throws CAS_OutOfSequenceException If called before the Request has been sent.
|
||||
*/
|
||||
public function getResponseBody ()
|
||||
{
|
||||
if (!$this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has not been sent yet. Cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
|
||||
return $this->_responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer a message describing any errors if the request failed.
|
||||
*
|
||||
* @return string
|
||||
* @throws CAS_OutOfSequenceException If called before the Request has been sent.
|
||||
*/
|
||||
public function getErrorMessage ()
|
||||
{
|
||||
if (!$this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has not been sent yet. Cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
return $this->_errorMessage;
|
||||
}
|
||||
}
|
||||
147
include/phpCAS/CAS/Request/CurlMultiRequest.php
Normal file
147
include/phpCAS/CAS/Request/CurlMultiRequest.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Licensed to Jasig under one or more contributor license
|
||||
* agreements. See the NOTICE file distributed with this work for
|
||||
* additional information regarding copyright ownership.
|
||||
*
|
||||
* Jasig licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* PHP Version 7
|
||||
*
|
||||
* @file CAS/Request/AbstractRequest.php
|
||||
* @category Authentication
|
||||
* @package PhpCAS
|
||||
* @author Adam Franco <afranco@middlebury.edu>
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://wiki.jasig.org/display/CASC/phpCAS
|
||||
*/
|
||||
|
||||
/**
|
||||
* This interface defines a class library for performing multiple web requests
|
||||
* in batches. Implementations of this interface may perform requests serially
|
||||
* or in parallel.
|
||||
*
|
||||
* @class CAS_Request_CurlMultiRequest
|
||||
* @category Authentication
|
||||
* @package PhpCAS
|
||||
* @author Adam Franco <afranco@middlebury.edu>
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://wiki.jasig.org/display/CASC/phpCAS
|
||||
*/
|
||||
class CAS_Request_CurlMultiRequest
|
||||
implements CAS_Request_MultiRequestInterface
|
||||
{
|
||||
private $_requests = array();
|
||||
private $_sent = false;
|
||||
|
||||
/*********************************************************
|
||||
* Add Requests
|
||||
*********************************************************/
|
||||
|
||||
/**
|
||||
* Add a new Request to this batch.
|
||||
* Note, implementations will likely restrict requests to their own concrete
|
||||
* class hierarchy.
|
||||
*
|
||||
* @param CAS_Request_RequestInterface $request reqest to add
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
* @throws CAS_InvalidArgumentException If passed a Request of the wrong
|
||||
* implmentation.
|
||||
*/
|
||||
public function addRequest (CAS_Request_RequestInterface $request)
|
||||
{
|
||||
if ($this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has already been sent cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
if (!$request instanceof CAS_Request_CurlRequest) {
|
||||
throw new CAS_InvalidArgumentException(
|
||||
'As a CAS_Request_CurlMultiRequest, I can only work with CAS_Request_CurlRequest objects.'
|
||||
);
|
||||
}
|
||||
|
||||
$this->_requests[] = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the number of requests added to this batch.
|
||||
*
|
||||
* @return int number of request elements
|
||||
* @throws CAS_OutOfSequenceException if the request has already been sent
|
||||
*/
|
||||
public function getNumRequests()
|
||||
{
|
||||
if ($this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has already been sent cannot '.__METHOD__
|
||||
);
|
||||
}
|
||||
return count($this->_requests);
|
||||
}
|
||||
|
||||
/*********************************************************
|
||||
* 2. Send the Request
|
||||
*********************************************************/
|
||||
|
||||
/**
|
||||
* Perform the request. After sending, all requests will have their
|
||||
* responses poulated.
|
||||
*
|
||||
* @return bool TRUE on success, FALSE on failure.
|
||||
* @throws CAS_OutOfSequenceException If called multiple times.
|
||||
*/
|
||||
public function send ()
|
||||
{
|
||||
if ($this->_sent) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'Request has already been sent cannot send again.'
|
||||
);
|
||||
}
|
||||
if (!count($this->_requests)) {
|
||||
throw new CAS_OutOfSequenceException(
|
||||
'At least one request must be added via addRequest() before the multi-request can be sent.'
|
||||
);
|
||||
}
|
||||
|
||||
$this->_sent = true;
|
||||
|
||||
// Initialize our handles and configure all requests.
|
||||
$handles = array();
|
||||
$multiHandle = curl_multi_init();
|
||||
foreach ($this->_requests as $i => $request) {
|
||||
$handle = $request->initAndConfigure();
|
||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
|
||||
$handles[$i] = $handle;
|
||||
curl_multi_add_handle($multiHandle, $handle);
|
||||
}
|
||||
|
||||
// Execute the requests in parallel.
|
||||
do {
|
||||
curl_multi_exec($multiHandle, $running);
|
||||
} while ($running > 0);
|
||||
|
||||
// Populate all of the responses or errors back into the request objects.
|
||||
foreach ($this->_requests as $i => $request) {
|
||||
$buf = curl_multi_getcontent($handles[$i]);
|
||||
$request->_storeResponseBody($buf);
|
||||
curl_multi_remove_handle($multiHandle, $handles[$i]);
|
||||
curl_close($handles[$i]);
|
||||
}
|
||||
|
||||
curl_multi_close($multiHandle);
|
||||
}
|
||||
}
|
||||
198
include/phpCAS/CAS/Request/CurlRequest.php
Normal file
198
include/phpCAS/CAS/Request/CurlRequest.php
Normal file
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Licensed to Jasig under one or more contributor license
|
||||
* agreements. See the NOTICE file distributed with this work for
|
||||
* additional information regarding copyright ownership.
|
||||
*
|
||||
* Jasig licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* PHP Version 7
|
||||
*
|
||||
* @file CAS/Request/CurlRequest.php
|
||||
* @category Authentication
|
||||
* @package PhpCAS
|
||||
* @author Adam Franco <afranco@middlebury.edu>
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://wiki.jasig.org/display/CASC/phpCAS
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides support for performing web-requests via curl
|
||||
*
|
||||
* @class CAS_Request_CurlRequest
|
||||
* @category Authentication
|
||||
* @package PhpCAS
|
||||
* @author Adam Franco <afranco@middlebury.edu>
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://wiki.jasig.org/display/CASC/phpCAS
|
||||
*/
|
||||
class CAS_Request_CurlRequest
|
||||
extends CAS_Request_AbstractRequest
|
||||
implements CAS_Request_RequestInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Set additional curl options
|
||||
*
|
||||
* @param array $options option to set
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCurlOptions (array $options)
|
||||
{
|
||||
$this->_curlOptions = $options;
|
||||
}
|
||||
private $_curlOptions = array();
|
||||
|
||||
/**
|
||||
* Send the request and store the results.
|
||||
*
|
||||
* @return bool true on success, false on failure.
|
||||
*/
|
||||
protected function sendRequest ()
|
||||
{
|
||||
phpCAS::traceBegin();
|
||||
|
||||
/*********************************************************
|
||||
* initialize the CURL session
|
||||
*********************************************************/
|
||||
$ch = $this->initAndConfigure();
|
||||
|
||||
/*********************************************************
|
||||
* Perform the query
|
||||
*********************************************************/
|
||||
$buf = curl_exec($ch);
|
||||
if ( $buf === false ) {
|
||||
phpCAS::trace('curl_exec() failed');
|
||||
$this->storeErrorMessage(
|
||||
'CURL error #'.curl_errno($ch).': '.curl_error($ch)
|
||||
);
|
||||
$res = false;
|
||||
} else {
|
||||
$this->storeResponseBody($buf);
|
||||
phpCAS::trace("Response Body: \n".$buf."\n");
|
||||
$res = true;
|
||||
|
||||
}
|
||||
// close the CURL session
|
||||
curl_close($ch);
|
||||
|
||||
phpCAS::traceEnd($res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to initialize our cURL handle and configure the request.
|
||||
* This method should NOT be used outside of the CurlRequest or the
|
||||
* CurlMultiRequest.
|
||||
*
|
||||
* @return resource|false The cURL handle on success, false on failure
|
||||
*/
|
||||
public function initAndConfigure()
|
||||
{
|
||||
/*********************************************************
|
||||
* initialize the CURL session
|
||||
*********************************************************/
|
||||
$ch = curl_init($this->url);
|
||||
|
||||
curl_setopt_array($ch, $this->_curlOptions);
|
||||
|
||||
/*********************************************************
|
||||
* Set SSL configuration
|
||||
*********************************************************/
|
||||
if ($this->caCertPath) {
|
||||
if ($this->validateCN) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
|
||||
curl_setopt($ch, CURLOPT_CAINFO, $this->caCertPath);
|
||||
phpCAS::trace('CURL: Set CURLOPT_CAINFO ' . $this->caCertPath);
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
}
|
||||
|
||||
/*********************************************************
|
||||
* Configure curl to capture our output.
|
||||
*********************************************************/
|
||||
// return the CURL output into a variable
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
// get the HTTP header with a callback
|
||||
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, '_curlReadHeaders'));
|
||||
|
||||
/*********************************************************
|
||||
* Add cookie headers to our request.
|
||||
*********************************************************/
|
||||
if (count($this->cookies)) {
|
||||
$cookieStrings = array();
|
||||
foreach ($this->cookies as $name => $val) {
|
||||
$cookieStrings[] = $name.'='.$val;
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_COOKIE, implode(';', $cookieStrings));
|
||||
}
|
||||
|
||||
/*********************************************************
|
||||
* Add any additional headers
|
||||
*********************************************************/
|
||||
if (count($this->headers)) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
|
||||
}
|
||||
|
||||
/*********************************************************
|
||||
* Flag and Body for POST requests
|
||||
*********************************************************/
|
||||
if ($this->isPost) {
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postBody);
|
||||
}
|
||||
|
||||
/*********************************************************
|
||||
* Set User Agent
|
||||
*********************************************************/
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'phpCAS/' . phpCAS::getVersion());
|
||||
|
||||
return $ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the response body.
|
||||
* This method should NOT be used outside of the CurlRequest or the
|
||||
* CurlMultiRequest.
|
||||
*
|
||||
* @param string $body body to stor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function _storeResponseBody ($body)
|
||||
{
|
||||
$this->storeResponseBody($body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method for capturing the headers from a curl request.
|
||||
*
|
||||
* @param resource $ch handle of curl
|
||||
* @param string $header header
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function _curlReadHeaders ($ch, $header)
|
||||
{
|
||||
$this->storeResponseHeader($header);
|
||||
return strlen($header);
|
||||
}
|
||||
}
|
||||
45
include/phpCAS/CAS/Request/Exception.php
Normal file
45
include/phpCAS/CAS/Request/Exception.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Licensed to Jasig under one or more contributor license
|
||||
* agreements. See the NOTICE file distributed with this work for
|
||||
* additional information regarding copyright ownership.
|
||||
*
|
||||
* Jasig licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* PHP Version 7
|
||||
*
|
||||
* @file CAS/Request/Exception.php
|
||||
* @category Authentication
|
||||
* @package PhpCAS
|
||||
* @author Adam Franco <afranco@middlebury.edu>
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://wiki.jasig.org/display/CASC/phpCAS
|
||||
*/
|
||||
|
||||
/**
|
||||
* An Exception for problems performing requests
|
||||
*
|
||||
* @class CAS_Request_Exception
|
||||
* @category Authentication
|
||||
* @package PhpCAS
|
||||
* @author Adam Franco <afranco@middlebury.edu>
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://wiki.jasig.org/display/CASC/phpCAS
|
||||
*/
|
||||
class CAS_Request_Exception
|
||||
extends Exception
|
||||
implements CAS_Exception
|
||||
{
|
||||
|
||||
}
|
||||
83
include/phpCAS/CAS/Request/MultiRequestInterface.php
Normal file
83
include/phpCAS/CAS/Request/MultiRequestInterface.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Licensed to Jasig under one or more contributor license
|
||||
* agreements. See the NOTICE file distributed with this work for
|
||||
* additional information regarding copyright ownership.
|
||||
*
|
||||
* Jasig licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* PHP Version 7
|
||||
*
|
||||
* @file CAS/Request/MultiRequestInterface.php
|
||||
* @category Authentication
|
||||
* @package PhpCAS
|
||||
* @author Adam Franco <afranco@middlebury.edu>
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://wiki.jasig.org/display/CASC/phpCAS
|
||||
*/
|
||||
|
||||
/**
|
||||
* This interface defines a class library for performing multiple web requests
|
||||
* in batches. Implementations of this interface may perform requests serially
|
||||
* or in parallel.
|
||||
*
|
||||
* @class CAS_Request_MultiRequestInterface
|
||||
* @category Authentication
|
||||
* @package PhpCAS
|
||||
* @author Adam Franco <afranco@middlebury.edu>
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://wiki.jasig.org/display/CASC/phpCAS
|
||||
*/
|
||||
interface CAS_Request_MultiRequestInterface
|
||||
{
|
||||
|
||||
/*********************************************************
|
||||
* Add Requests
|
||||
*********************************************************/
|
||||
|
||||
/**
|
||||
* Add a new Request to this batch.
|
||||
* Note, implementations will likely restrict requests to their own concrete
|
||||
* class hierarchy.
|
||||
*
|
||||
* @param CAS_Request_RequestInterface $request request interface
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been
|
||||
* sent.
|
||||
* @throws CAS_InvalidArgumentException If passed a Request of the wrong
|
||||
* implmentation.
|
||||
*/
|
||||
public function addRequest (CAS_Request_RequestInterface $request);
|
||||
|
||||
/**
|
||||
* Retrieve the number of requests added to this batch.
|
||||
*
|
||||
* @return int number of request elements
|
||||
*/
|
||||
public function getNumRequests ();
|
||||
|
||||
/*********************************************************
|
||||
* 2. Send the Request
|
||||
*********************************************************/
|
||||
|
||||
/**
|
||||
* Perform the request. After sending, all requests will have their
|
||||
* responses poulated.
|
||||
*
|
||||
* @return bool TRUE on success, FALSE on failure.
|
||||
* @throws CAS_OutOfSequenceException If called multiple times.
|
||||
*/
|
||||
public function send ();
|
||||
}
|
||||
179
include/phpCAS/CAS/Request/RequestInterface.php
Normal file
179
include/phpCAS/CAS/Request/RequestInterface.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Licensed to Jasig under one or more contributor license
|
||||
* agreements. See the NOTICE file distributed with this work for
|
||||
* additional information regarding copyright ownership.
|
||||
*
|
||||
* Jasig licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* PHP Version 7
|
||||
*
|
||||
* @file CAS/Request/RequestInterface.php
|
||||
* @category Authentication
|
||||
* @package PhpCAS
|
||||
* @author Adam Franco <afranco@middlebury.edu>
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://wiki.jasig.org/display/CASC/phpCAS
|
||||
*/
|
||||
|
||||
/**
|
||||
* This interface defines a class library for performing web requests.
|
||||
*
|
||||
* @class CAS_Request_RequestInterface
|
||||
* @category Authentication
|
||||
* @package PhpCAS
|
||||
* @author Adam Franco <afranco@middlebury.edu>
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
|
||||
* @link https://wiki.jasig.org/display/CASC/phpCAS
|
||||
*/
|
||||
interface CAS_Request_RequestInterface
|
||||
{
|
||||
|
||||
/*********************************************************
|
||||
* Configure the Request
|
||||
*********************************************************/
|
||||
|
||||
/**
|
||||
* Set the URL of the Request
|
||||
*
|
||||
* @param string $url url to set
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function setUrl ($url);
|
||||
|
||||
/**
|
||||
* Add a cookie to the request.
|
||||
*
|
||||
* @param string $name name of cookie
|
||||
* @param string $value value of cookie
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function addCookie ($name, $value);
|
||||
|
||||
/**
|
||||
* Add an array of cookies to the request.
|
||||
* The cookie array is of the form
|
||||
* array('cookie_name' => 'cookie_value', 'cookie_name2' => cookie_value2')
|
||||
*
|
||||
* @param array $cookies cookies to add
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function addCookies (array $cookies);
|
||||
|
||||
/**
|
||||
* Add a header string to the request.
|
||||
*
|
||||
* @param string $header header to add
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function addHeader ($header);
|
||||
|
||||
/**
|
||||
* Add an array of header strings to the request.
|
||||
*
|
||||
* @param array $headers headers to add
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function addHeaders (array $headers);
|
||||
|
||||
/**
|
||||
* Make the request a POST request rather than the default GET request.
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function makePost ();
|
||||
|
||||
/**
|
||||
* Add a POST body to the request
|
||||
*
|
||||
* @param string $body body to add
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function setPostBody ($body);
|
||||
|
||||
|
||||
/**
|
||||
* Specify the path to an SSL CA certificate to validate the server with.
|
||||
*
|
||||
* @param string $caCertPath path to cert file
|
||||
* @param boolean $validate_cn validate CN of SSL certificate
|
||||
*
|
||||
* @return void
|
||||
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
|
||||
*/
|
||||
public function setSslCaCert ($caCertPath, $validate_cn = true);
|
||||
|
||||
|
||||
|
||||
/*********************************************************
|
||||
* 2. Send the Request
|
||||
*********************************************************/
|
||||
|
||||
/**
|
||||
* Perform the request.
|
||||
*
|
||||
* @return bool TRUE on success, FALSE on failure.
|
||||
* @throws CAS_OutOfSequenceException If called multiple times.
|
||||
*/
|
||||
public function send ();
|
||||
|
||||
/*********************************************************
|
||||
* 3. Access the response
|
||||
*********************************************************/
|
||||
|
||||
/**
|
||||
* Answer the headers of the response.
|
||||
*
|
||||
* @return array An array of header strings.
|
||||
* @throws CAS_OutOfSequenceException If called before the Request has been sent.
|
||||
*/
|
||||
public function getResponseHeaders ();
|
||||
|
||||
/**
|
||||
* Answer HTTP status code of the response
|
||||
*
|
||||
* @return int
|
||||
* @throws CAS_OutOfSequenceException If called before the Request has been sent.
|
||||
*/
|
||||
public function getResponseStatusCode ();
|
||||
|
||||
/**
|
||||
* Answer the body of response.
|
||||
*
|
||||
* @return string
|
||||
* @throws CAS_OutOfSequenceException If called before the Request has been sent.
|
||||
*/
|
||||
public function getResponseBody ();
|
||||
|
||||
/**
|
||||
* Answer a message describing any errors if the request failed.
|
||||
*
|
||||
* @return string
|
||||
* @throws CAS_OutOfSequenceException If called before the Request has been sent.
|
||||
*/
|
||||
public function getErrorMessage ();
|
||||
}
|
||||
Reference in New Issue
Block a user