70 $this->_cookieJar = $cookieJar;
87 if (empty($this->_url)) {
89 'No URL set via ' . get_class($this) .
'->setUrl($url).'
112 'Cannot set the URL, request already sent.'
115 if (!is_string(
$url)) {
143 'Cannot send, request already sent.'
152 if (strstr(
$url,
'?') ===
false) {
160 }
catch (Exception
$e) {
211 $this->_numRequests++;
212 if ($this->_numRequests > 4) {
213 $message =
'Exceeded the maximum number of redirects (3) in proxied service request.';
220 $request->setUrl(
$url);
223 $request->addCookies($this->_cookieJar->getCookies(
$url));
230 if (!$request->send()) {
231 $message =
'Could not perform proxied service request to URL`'
232 .
$url .
'\'.
' . $request->getErrorMessage();
233 phpCAS::trace($message);
234 throw new CAS_ProxiedService_Exception($message);
237 // Store any cookies from the response;
238 $this->_cookieJar->storeCookies($url, $request->getResponseHeaders());
240 // Follow any redirects
241 if ($redirectUrl = $this->getRedirectUrl($request->getResponseHeaders())
243 phpCAS::trace('Found redirect:
' . $redirectUrl);
244 $this->makeRequest($redirectUrl);
246 $this->_responseHeaders = $request->getResponseHeaders();
247 $this->_responseBody = $request->getResponseBody();
248 $this->_responseStatusCode = $request->getResponseStatusCode();
259 abstract protected function populateRequest(
260 CAS_Request_RequestInterface $request
270 protected function getRedirectUrl(array $responseHeaders)
272 // Check for the redirect after authentication
273 foreach ($responseHeaders as $header) {
274 if (preg_match('/^(Location:|URI:)\s*([^\s]+.*)$/
', $header, $matches)
276 return trim(array_pop($matches));
291 protected function hasBeenSent()
293 return ($this->_numRequests > 0);
302 public function getResponseHeaders()
304 if (!$this->hasBeenSent()) {
305 throw new CAS_OutOfSequenceException(
306 'Cannot access response, request not sent yet.
'
310 return $this->_responseHeaders;
319 public function getResponseStatusCode()
321 if (!$this->hasBeenSent()) {
322 throw new CAS_OutOfSequenceException(
323 'Cannot access response, request not sent yet.
'
327 return $this->_responseStatusCode;
336 public function getResponseBody()
338 if (!$this->hasBeenSent()) {
339 throw new CAS_OutOfSequenceException(
340 'Cannot access response, request not sent yet.
'
344 return $this->_responseBody;
353 public function getCookies()
355 return $this->_cookieJar->getCookies($this->getServiceUrl());
This class provides access to service cookies and handles parsing of response headers to pull out coo...
An exception for terminatinating execution or to throw for unit testing.
Exception that denotes invalid arguments were passed.
This class defines Exceptions that should be thrown when the sequence of operations is invalid.
This class implements common methods for ProxiedService implementations included with phpCAS.
initializeProxyTicket()
Fetch our proxy ticket.
getProxyTicket()
Answer the proxy ticket to be used when making requests.
An Exception for problems communicating with a proxied service.
This class implements common methods for ProxiedService implementations included with phpCAS.
$requestHandler
The HTTP request mechanism talking to the target service.
$_numRequests
Indicator of the number of requests (including redirects performed.
send()
Perform the request.
makeRequest($url)
Build and perform a request, following redirects.
hasBeenSent()
Answer true if our request has been sent yet.
setUrl($url)
Set the URL of the Request.
$_responseStatusCode
The response status code.
$_responseBody
The response headers.
__construct(CAS_Request_RequestInterface $requestHandler, CAS_CookieJar $cookieJar)
Constructor.
getServiceUrl()
Answer a service identifier (URL) for whom we should fetch a proxy ticket.
$_cookieJar
The storage mechanism for cookies set by the target service.
populateRequest(CAS_Request_RequestInterface $request)
Add any other parts of the request needed by concrete classes.
$_url
The target service url.
$_responseHeaders
The response headers.
static trace($str)
This method is used to log something in debug mode.
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode.
This interface defines methods that clients should use for configuring, sending, and receiving proxie...
This interface defines a class library for performing web requests.