Skip to content
Browse files

#14 more style corrections

  • Loading branch information...
1 parent b607f6d commit d0c5ecf2762d0290d32986e0ec7c10dbfdaf66a9 @jfritschi jfritschi committed Dec 16, 2011
View
1 .gitignore
@@ -3,3 +3,4 @@ utils/build.properties
utils/dist/
utils/tmp/
utils/starting_HEAD
+/.settings
View
198 source/CAS/ProxiedService/Abstract.php
@@ -4,105 +4,135 @@
* 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 5
+ *
+ * @file CAS/ProxiedService/Abstract.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 class implements common methods for ProxiedService implementations included
* with phpCAS.
+ *
+ * @class CAS_ProxiedService_Abstract
+ * @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_ProxiedService_Abstract
- implements CAS_ProxiedService, CAS_ProxiedService_Testable
+implements CAS_ProxiedService, CAS_ProxiedService_Testable
{
-
- /**
- * The proxy ticket that can be used when making service requests.
- * @var string $_proxyTicket;
- */
- private $_proxyTicket;
-
- /**
- * Register a proxy ticket with the Proxy that it can use when making requests.
- *
- * @param string $proxyTicket
- * @return void
- * @throws InvalidArgumentException If the $proxyTicket is invalid.
- * @throws CAS_OutOfSequenceException If called after a proxy ticket has already been initialized/set.
- */
- public function setProxyTicket ($proxyTicket) {
- if (empty($proxyTicket))
- throw new CAS_InvalidArgumentException("Trying to initialize with an empty proxy ticket.");
- if (!empty($this->_proxyTicket))
- throw new CAS_OutOfSequenceException('Already initialized, cannot change the proxy ticket.');
-
- $this->_proxyTicket = $proxyTicket;
- }
-
- /**
- * Answer the proxy ticket to be used when making requests.
- *
- * @return string
- * @throws CAS_OutOfSequenceException If called before a proxy ticket has already been initialized/set.
- */
- protected function getProxyTicket () {
- if (empty($this->_proxyTicket))
- throw new CAS_OutOfSequenceException('No proxy ticket yet. Call $this->initializeProxyTicket() to aquire the proxy ticket.');
-
- return $this->_proxyTicket;
- }
-
- /**
- * @var CAS_Client $_casClient;
- */
- private $_casClient;
-
- /**
- * Use a particular CAS_Client->initializeProxiedService() rather than the
- * static phpCAS::initializeProxiedService().
- *
- * This method should not be called in standard operation, but is needed for unit
- * testing.
- *
- * @param CAS_Client $casClient
- * @return void
- * @throws CAS_OutOfSequenceException If called after a proxy ticket has already been initialized/set.
- */
- public function setCasClient (CAS_Client $casClient) {
- if (!empty($this->_proxyTicket))
- throw new CAS_OutOfSequenceException('Already initialized, cannot change the CAS_Client.');
-
- $this->_casClient = $casClient;
- }
-
- /**
- * Fetch our proxy ticket.
- *
- * Descendent classes should call this method once their service URL is available
- * to initialize their proxy ticket.
- *
- * @return void
- * @throws CAS_OutOfSequenceException If called after a proxy ticket has already been initialized.
- */
- protected function initializeProxyTicket() {
- if (!empty($this->_proxyTicket))
- throw new CAS_OutOfSequenceException('Already initialized, cannot initialize again.');
-
- // Allow usage of a particular CAS_Client for unit testing.
- if (empty($this->_casClient))
- phpCAS::initializeProxiedService($this);
- else
- $this->_casClient->initializeProxiedService($this);
- }
-
+
+ /**
+ * The proxy ticket that can be used when making service requests.
+ * @var string $_proxyTicket;
+ */
+ private $_proxyTicket;
+
+ /**
+ * Register a proxy ticket with the Proxy that it can use when making requests.
+ *
+ * @param string $proxyTicket proxy ticket
+ *
+ * @return void
+ * @throws InvalidArgumentException If the $proxyTicket is invalid.
+ * @throws CAS_OutOfSequenceException If called after a proxy ticket has already been initialized/set.
+ */
+ public function setProxyTicket ($proxyTicket)
+ {
+ if (empty($proxyTicket)) {
+ throw new CAS_InvalidArgumentException("Trying to initialize with an empty proxy ticket.");
+ }
+ if (!empty($this->_proxyTicket)) {
+ throw new CAS_OutOfSequenceException('Already initialized, cannot change the proxy ticket.');
+ }
+ $this->_proxyTicket = $proxyTicket;
+ }
+
+ /**
+ * Answer the proxy ticket to be used when making requests.
+ *
+ * @return string
+ * @throws CAS_OutOfSequenceException If called before a proxy ticket has
+ * already been initialized/set.
+ */
+ protected function getProxyTicket ()
+ {
+ if (empty($this->_proxyTicket)) {
+ throw new CAS_OutOfSequenceException('No proxy ticket yet. Call $this->initializeProxyTicket() to aquire the proxy ticket.');
+ }
+
+ return $this->_proxyTicket;
+ }
+
+ /**
+ * @var CAS_Client $_casClient;
+ */
+ private $_casClient;
+
+ /**
+ * Use a particular CAS_Client->initializeProxiedService() rather than the
+ * static phpCAS::initializeProxiedService().
+ *
+ * This method should not be called in standard operation, but is needed for unit
+ * testing.
+ *
+ * @param CAS_Client $casClient cas client
+ *
+ * @return void
+ * @throws CAS_OutOfSequenceException If called after a proxy ticket has
+ * already been initialized/set.
+ */
+ public function setCasClient (CAS_Client $casClient)
+ {
+ if (!empty($this->_proxyTicket)) {
+ throw new CAS_OutOfSequenceException('Already initialized, cannot change the CAS_Client.');
+ }
+
+ $this->_casClient = $casClient;
+ }
+
+ /**
+ * Fetch our proxy ticket.
+ *
+ * Descendent classes should call this method once their service URL is available
+ * to initialize their proxy ticket.
+ *
+ * @return void
+ * @throws CAS_OutOfSequenceException If called after a proxy ticket has
+ * already been initialized.
+ */
+ protected function initializeProxyTicket()
+ {
+ if (!empty($this->_proxyTicket)) {
+ throw new CAS_OutOfSequenceException('Already initialized, cannot initialize again.');
+ }
+ // Allow usage of a particular CAS_Client for unit testing.
+ if (empty($this->_casClient)) {
+ phpCAS::initializeProxiedService($this);
+ } else {
+ $this->_casClient->initializeProxiedService($this);
+ }
+ }
+
}
+?>
View
23 source/CAS/ProxiedService/Exception.php
@@ -4,26 +4,43 @@
* 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 5
+ *
+ * @file CAS/ProxiedService/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 communicating with a proxied service.
+ *
+ * @class CAS_ProxiedService_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_ProxiedService_Exception
extends Exception
implements CAS_Exception
{
}
+?>
View
35 source/CAS/ProxiedService/Http.php
@@ -4,39 +4,57 @@
* 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 5
+ *
+ * @file CAS/ProxiedService/Http.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 methods that clients should use for configuring, sending,
* and receiving proxied HTTP requests.
+ *
+ * @class CAS_ProxiedService_Http
+ * @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_ProxiedService_Http {
-
+interface CAS_ProxiedService_Http
+{
+
/*********************************************************
* Configure the Request
*********************************************************/
/**
* Set the URL of the Request
*
- * @param string $url
+ * @param string $url Url to set
+ *
* @return void
* @throws CAS_OutOfSequenceException If called after the Request has been sent.
*/
public function setUrl ($url);
-
+
/*********************************************************
* 2. Send the Request
*********************************************************/
@@ -68,5 +86,6 @@ public function getResponseHeaders ();
* @throws CAS_OutOfSequenceException If called before the Request has been sent.
*/
public function getResponseBody ();
-
+
}
+?>
View
575 source/CAS/ProxiedService/Http/Abstract.php
@@ -4,288 +4,329 @@
* 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 5
+ *
+ * @file CAS/ProxiedService/Http/Abstract.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 class implements common methods for ProxiedService implementations included
* with phpCAS.
+ *
+ * @class CAS_ProxiedService_Http_Abstract
+ * @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_ProxiedService_Http_Abstract
- extends CAS_ProxiedService_Abstract
- implements CAS_ProxiedService_Http
+extends CAS_ProxiedService_Abstract
+implements CAS_ProxiedService_Http
{
- /**
- * The HTTP request mechanism talking to the target service.
- *
- * @var CAS_Request_RequestInterface $_requestHandler
- */
- protected $_requestHandler;
-
- /**
- * The storage mechanism for cookies set by the target service.
- *
- * @var CAS_CookieJar $_cookieJar
- */
- private $_cookieJar;
-
- /**
- * Constructor.
- *
- * @param CAS_Request_RequestInterface $requestHandler
- * @param CAS_CookieJar $cookieJar
- * @return void
- */
- public function __construct (CAS_Request_RequestInterface $requestHandler, CAS_CookieJar $cookieJar) {
- $this->_requestHandler = $requestHandler;
- $this->_cookieJar = $cookieJar;
- }
-
- /**
- * The target service url.
- * @var string $_url;
- */
- private $_url;
-
- /**
- * Answer a service identifier (URL) for whom we should fetch a proxy ticket.
- *
- * @return string
- * @throws Exception If no service url is available.
- */
- public function getServiceUrl () {
- if (empty($this->_url))
- throw new CAS_ProxiedService_Exception('No URL set via '.get_class($this).'->setUrl($url).');
-
- return $this->_url;
- }
-
- /*********************************************************
- * Configure the Request
- *********************************************************/
-
- /**
- * Set the URL of the Request
- *
- * @param string $url
- * @return void
- * @throws CAS_OutOfSequenceException If called after the Request has been sent.
- */
- public function setUrl ($url) {
- if ($this->hasBeenSent())
- throw new CAS_OutOfSequenceException('Cannot set the URL, request already sent.');
- if (!is_string($url))
- throw new CAS_InvalidArgumentException('$url must be a string.');
-
- $this->_url = $url;
- }
-
- /*********************************************************
- * 2. Send the Request
- *********************************************************/
-
- /**
- * Perform the request.
- *
- * @return void
- * @throws CAS_OutOfSequenceException If called multiple times.
- * @throws CAS_ProxyTicketException If there is a proxy-ticket failure.
- * The code of the Exception will be one of:
- * PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE
- * PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE
- * PHPCAS_SERVICE_PT_FAILURE
- * @throws CAS_ProxiedService_Exception If there is a failure sending the request to the target service.
- */
- public function send () {
- if ($this->hasBeenSent())
- throw new CAS_OutOfSequenceException('Cannot send, request already sent.');
-
- phpCAS::traceBegin();
-
- // Get our proxy ticket and append it to our URL.
- $this->initializeProxyTicket();
- $url = $this->getServiceUrl();
- if ( strstr($url,'?') === FALSE ) {
- $url = $url.'?ticket='.$this->getProxyTicket();
- } else {
- $url = $url.'&ticket='.$this->getProxyTicket();
- }
-
- try {
- $this->makeRequest($url);
- } catch (Exception $e) {
- phpCAS::traceEnd();
- throw $e;
- }
- }
-
- /**
- * Indicator of the number of requests (including redirects performed.
- *
- * @var int $_numRequests;
- */
- private $_numRequests = 0;
-
- /**
- * The response headers.
- *
- * @var array $_responseHeaders;
- */
- private $_responseHeaders = array();
-
- /**
- * The response status code.
- *
- * @var string $_responseStatusCode;
- */
- private $_responseStatusCode = '';
-
- /**
- * The response headers.
- *
- * @var string $_responseBody;
- */
- private $_responseBody = '';
-
- /**
- * Build and perform a request, following redirects
- *
- * @param string $url
- * @return void
- * @throws CAS_ProxyTicketException If there is a proxy-ticket failure.
- * The code of the Exception will be one of:
- * PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE
- * PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE
- * PHPCAS_SERVICE_PT_FAILURE
- * @throws CAS_ProxiedService_Exception If there is a failure sending the request to the target service.
- */
- protected function makeRequest ($url) {
- // Verify that we are not in a redirect loop
- $this->_numRequests++;
- if ($this->_numRequests > 4) {
- $message = 'Exceeded the maximum number of redirects (3) in proxied service request.';
- phpCAS::trace($message);
- throw new CAS_ProxiedService_Exception($message);
- }
-
- // Create a new request.
- $request = clone $this->_requestHandler;
- $request->setUrl($url);
-
- // Add any cookies to the request.
- $request->addCookies($this->_cookieJar->getCookies($url));
-
- // Add any other parts of the request needed by concrete classes
- $this->populateRequest($request);
-
- // Perform the request.
- phpCAS::trace('Performing proxied service request to \''.$url.'\'');
- if (!$request->send()) {
- $message = 'Could not perform proxied service request to URL`'.$url.'\'. '.$request->getErrorMessage();
- phpCAS::trace($message);
- throw new CAS_ProxiedService_Exception($message);
- }
-
- // Store any cookies from the response;
- $this->_cookieJar->storeCookies($url, $request->getResponseHeaders());
-
- // Follow any redirects
- if ($redirectUrl = $this->getRedirectUrl($request->getResponseHeaders())) {
- phpCAS :: trace('Found redirect:'.$redirectUrl);
- $this->makeRequest($redirectUrl);
- } else {
-
- $this->_responseHeaders = $request->getResponseHeaders();
- $this->_responseBody = $request->getResponseBody();
- $this->_responseStatusCode = $request->getResponseStatusCode();
- }
- }
-
- /**
- * Add any other parts of the request needed by concrete classes
- *
- * @param CAS_Request_RequestInterface $request
- * @return void
- */
- abstract protected function populateRequest (CAS_Request_RequestInterface $request);
-
- /**
- * Answer a redirect URL if a redirect header is found, otherwise null.
- *
- * @param array $responseHeaders
- * @return string or null
- */
- private function getRedirectUrl (array $responseHeaders) {
- // Check for the redirect after authentication
- foreach($responseHeaders as $header){
- if (preg_match('/^(Location:|URI:)\s*([^\s]+.*)$/', $header, $matches)) {
- return trim(array_pop($matches));
- }
- }
- return null;
- }
-
- /*********************************************************
- * 3. Access the response
- *********************************************************/
-
- /**
- * Answer true if our request has been sent yet.
- *
- * @return boolean
- */
- protected function hasBeenSent () {
- return ($this->_numRequests > 0);
- }
-
- /**
- * 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->hasBeenSent())
- throw new CAS_OutOfSequenceException('Cannot access response, request not sent yet.');
-
- return $this->_responseHeaders;
- }
-
- /**
- * Answer HTTP status code of the response
- *
- * @return integer
- * @throws CAS_OutOfSequenceException If called before the Request has been sent.
- */
- public function getResponseStatusCode () {
- if (!$this->hasBeenSent())
- throw new CAS_OutOfSequenceException('Cannot access response, request not sent yet.');
-
- return $this->_responseStatusCode;
- }
-
- /**
- * Answer the body of response.
- *
- * @return string
- * @throws CAS_OutOfSequenceException If called before the Request has been sent.
- */
- public function getResponseBody () {
- if (!$this->hasBeenSent())
- throw new CAS_OutOfSequenceException('Cannot access response, request not sent yet.');
-
- return $this->_responseBody;
- }
-
+ /**
+ * The HTTP request mechanism talking to the target service.
+ *
+ * @var CAS_Request_RequestInterface $requestHandler
+ */
+ protected $requestHandler;
+
+ /**
+ * The storage mechanism for cookies set by the target service.
+ *
+ * @var CAS_CookieJar $_cookieJar
+ */
+ private $_cookieJar;
+
+ /**
+ * Constructor.
+ *
+ * @param CAS_Request_RequestInterface $requestHandler request handler object
+ * @param CAS_CookieJar $cookieJar cookieJar object
+ *
+ * @return void
+ */
+ public function __construct (CAS_Request_RequestInterface $requestHandler, CAS_CookieJar $cookieJar)
+ {
+ $this->requestHandler = $requestHandler;
+ $this->_cookieJar = $cookieJar;
+ }
+
+ /**
+ * The target service url.
+ * @var string $_url;
+ */
+ private $_url;
+
+ /**
+ * Answer a service identifier (URL) for whom we should fetch a proxy ticket.
+ *
+ * @return string
+ * @throws Exception If no service url is available.
+ */
+ public function getServiceUrl ()
+ {
+ if (empty($this->_url)) {
+ throw new CAS_ProxiedService_Exception('No URL set via '.get_class($this).'->setUrl($url).');
+ }
+
+ return $this->_url;
+ }
+
+ /*********************************************************
+ * 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->hasBeenSent()) {
+ throw new CAS_OutOfSequenceException('Cannot set the URL, request already sent.');
+ }
+ if (!is_string($url)) {
+ throw new CAS_InvalidArgumentException('$url must be a string.');
+ }
+
+ $this->_url = $url;
+ }
+
+ /*********************************************************
+ * 2. Send the Request
+ *********************************************************/
+
+ /**
+ * Perform the request.
+ *
+ * @return void
+ * @throws CAS_OutOfSequenceException If called multiple times.
+ * @throws CAS_ProxyTicketException If there is a proxy-ticket failure.
+ * The code of the Exception will be one of:
+ * PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE
+ * PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE
+ * PHPCAS_SERVICE_PT_FAILURE
+ * @throws CAS_ProxiedService_Exception If there is a failure sending the
+ * request to the target service.
+ */
+ public function send ()
+ {
+ if ($this->hasBeenSent()) {
+ throw new CAS_OutOfSequenceException('Cannot send, request already sent.');
+ }
+
+ phpCAS::traceBegin();
+
+ // Get our proxy ticket and append it to our URL.
+ $this->initializeProxyTicket();
+ $url = $this->getServiceUrl();
+ if (strstr($url, '?') === false) {
+ $url = $url.'?ticket='.$this->getProxyTicket();
+ } else {
+ $url = $url.'&ticket='.$this->getProxyTicket();
+ }
+
+ try {
+ $this->makeRequest($url);
+ } catch (Exception $e) {
+ phpCAS::traceEnd();
+ throw $e;
+ }
+ }
+
+ /**
+ * Indicator of the number of requests (including redirects performed.
+ *
+ * @var int $_numRequests;
+ */
+ private $_numRequests = 0;
+
+ /**
+ * The response headers.
+ *
+ * @var array $_responseHeaders;
+ */
+ private $_responseHeaders = array();
+
+ /**
+ * The response status code.
+ *
+ * @var string $_responseStatusCode;
+ */
+ private $_responseStatusCode = '';
+
+ /**
+ * The response headers.
+ *
+ * @var string $_responseBody;
+ */
+ private $_responseBody = '';
+
+ /**
+ * Build and perform a request, following redirects
+ *
+ * @param string $url url for the request
+ *
+ * @return void
+ * @throws CAS_ProxyTicketException If there is a proxy-ticket failure.
+ * The code of the Exception will be one of:
+ * PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE
+ * PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE
+ * PHPCAS_SERVICE_PT_FAILURE
+ * @throws CAS_ProxiedService_Exception If there is a failure sending the
+ * request to the target service.
+ */
+ protected function makeRequest ($url)
+ {
+ // Verify that we are not in a redirect loop
+ $this->_numRequests++;
+ if ($this->_numRequests > 4) {
+ $message = 'Exceeded the maximum number of redirects (3) in proxied service request.';
+ phpCAS::trace($message);
+ throw new CAS_ProxiedService_Exception($message);
+ }
+
+ // Create a new request.
+ $request = clone $this->requestHandler;
+ $request->setUrl($url);
+
+ // Add any cookies to the request.
+ $request->addCookies($this->_cookieJar->getCookies($url));
+
+ // Add any other parts of the request needed by concrete classes
+ $this->populateRequest($request);
+
+ // Perform the request.
+ phpCAS::trace('Performing proxied service request to \''.$url.'\'');
+ if (!$request->send()) {
+ $message = 'Could not perform proxied service request to URL`'.$url.'\'. '.$request->getErrorMessage();
+ phpCAS::trace($message);
+ throw new CAS_ProxiedService_Exception($message);
+ }
+
+ // Store any cookies from the response;
+ $this->_cookieJar->storeCookies($url, $request->getResponseHeaders());
+
+ // Follow any redirects
+ if ($redirectUrl = $this->_getRedirectUrl($request->getResponseHeaders())) {
+ phpCAS :: trace('Found redirect:'.$redirectUrl);
+ $this->makeRequest($redirectUrl);
+ } else {
+
+ $this->_responseHeaders = $request->getResponseHeaders();
+ $this->_responseBody = $request->getResponseBody();
+ $this->_responseStatusCode = $request->getResponseStatusCode();
+ }
+ }
+
+ /**
+ * Add any other parts of the request needed by concrete classes
+ *
+ * @param CAS_Request_RequestInterface $request request interface object
+ *
+ * @return void
+ */
+ abstract protected function populateRequest (CAS_Request_RequestInterface $request);
+
+ /**
+ * Answer a redirect URL if a redirect header is found, otherwise null.
+ *
+ * @param array $responseHeaders response header to extract a redirect from
+ *
+ * @return string or null
+ */
+ private function _getRedirectUrl (array $responseHeaders)
+ {
+ // Check for the redirect after authentication
+ foreach ($responseHeaders as $header) {
+ if (preg_match('/^(Location:|URI:)\s*([^\s]+.*)$/', $header, $matches)) {
+ return trim(array_pop($matches));
+ }
+ }
+ return null;
+ }
+
+ /*********************************************************
+ * 3. Access the response
+ *********************************************************/
+
+ /**
+ * Answer true if our request has been sent yet.
+ *
+ * @return boolean
+ */
+ protected function hasBeenSent ()
+ {
+ return ($this->_numRequests > 0);
+ }
+
+ /**
+ * 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->hasBeenSent()) {
+ throw new CAS_OutOfSequenceException('Cannot access response, request not sent yet.');
+ }
+
+ return $this->_responseHeaders;
+ }
+
+ /**
+ * Answer HTTP status code of the response
+ *
+ * @return integer
+ * @throws CAS_OutOfSequenceException If called before the Request has been sent.
+ */
+ public function getResponseStatusCode ()
+ {
+ if (!$this->hasBeenSent()) {
+ throw new CAS_OutOfSequenceException('Cannot access response, request not sent yet.');
+ }
+
+ return $this->_responseStatusCode;
+ }
+
+ /**
+ * Answer the body of response.
+ *
+ * @return string
+ * @throws CAS_OutOfSequenceException If called before the Request has been sent.
+ */
+ public function getResponseBody ()
+ {
+ if (!$this->hasBeenSent()) {
+ throw new CAS_OutOfSequenceException('Cannot access response, request not sent yet.');
+ }
+
+ return $this->_responseBody;
+ }
+
}
+?>
View
54 source/CAS/ProxiedService/Http/Get.php
@@ -4,25 +4,34 @@
* 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 5
+ *
+ * @file CAS/ProxiedService/Http/Get.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 class is used to make proxied service requests via the HTTP GET method.
*
* Usage Example:
- *
+ *
* try {
* $service = phpCAS::getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_GET);
* $service->setUrl('http://www.example.com/path/');
@@ -32,14 +41,14 @@
* else
* // The service responded with an error code 404, 500, etc.
* throw new Exception('The service responded with an error.');
- *
+ *
* } catch (CAS_ProxyTicketException $e) {
* if ($e->getCode() == PHPCAS_SERVICE_PT_FAILURE)
* return "Your login has timed out. You need to log in again.";
* else
* // Other proxy ticket errors are from bad request format (shouldn't happen)
* // or CAS server failure (unlikely) so lets just stop if we hit those.
- * throw $e;
+ * throw $e;
* } catch (CAS_ProxiedService_Exception $e) {
* // Something prevented the service request from being sent or received.
* // We didn't even get a valid error response (404, 500, etc), so this
@@ -48,21 +57,28 @@
* throw $e;
* }
*
+ * @class CAS_ProxiedService_Http_Get
+ * @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_ProxiedService_Http_Get
- extends CAS_ProxiedService_Http_Abstract
+extends CAS_ProxiedService_Http_Abstract
{
-
- /**
- * Add any other parts of the request needed by concrete classes
- *
- * @param CAS_Request_RequestInterface $request
- * @return void
- */
- protected function populateRequest (CAS_Request_RequestInterface $request) {
- // do nothing, since the URL has already been sent and that is our
- // only data.
- }
-
+ /**
+ * Add any other parts of the request needed by concrete classes
+ *
+ * @param CAS_Request_RequestInterface $request request interface
+ *
+ * @return void
+ */
+ protected function populateRequest (CAS_Request_RequestInterface $request)
+ {
+ // do nothing, since the URL has already been sent and that is our
+ // only data.
+ }
}
+?>
View
158 source/CAS/ProxiedService/Http/Post.php
@@ -4,25 +4,34 @@
* 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 5
+ *
+ * @file CAS/ProxiedService/Http/Post.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 class is used to make proxied service requests via the HTTP POST method.
*
* Usage Example:
- *
+ *
* try {
* $service = phpCAS::getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_POST);
* $service->setUrl('http://www.example.com/path/');
@@ -34,85 +43,102 @@
* else
* // The service responded with an error code 404, 500, etc.
* throw new Exception('The service responded with an error.');
- *
+ *
* } catch (CAS_ProxyTicketException $e) {
* if ($e->getCode() == PHPCAS_SERVICE_PT_FAILURE)
* return "Your login has timed out. You need to log in again.";
* else
* // Other proxy ticket errors are from bad request format (shouldn't happen)
* // or CAS server failure (unlikely) so lets just stop if we hit those.
- * throw $e;
+ * throw $e;
* } catch (CAS_ProxiedService_Exception $e) {
* // Something prevented the service request from being sent or received.
* // We didn't even get a valid error response (404, 500, etc), so this
* // might be caused by a network error or a DNS resolution failure.
* // We could handle it in some way, but for now we will just stop.
* throw $e;
* }
+ *
+ * @class CAS_ProxiedService_Http_Post
+ * @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_ProxiedService_Http_Post
- extends CAS_ProxiedService_Http_Abstract
+extends CAS_ProxiedService_Http_Abstract
{
- /**
- * The content-type of this request
- *
- * @var string $_contentType
- */
- private $_contentType;
-
- /**
- * The body of the this request
- *
- * @var string $_body
- */
- private $_body;
-
- /**
- * Set the content type of this POST request.
- *
- * @param string $contentType
- * @return void
- * @throws CAS_OutOfSequenceException If called after the Request has been sent.
- */
- public function setContentType ($contentType) {
- if ($this->hasBeenSent())
- throw new CAS_OutOfSequenceException('Cannot set the content type, request already sent.');
-
- $this->_contentType = $contentType;
- }
+ /**
+ * The content-type of this request
+ *
+ * @var string $_contentType
+ */
+ private $_contentType;
+
+ /**
+ * The body of the this request
+ *
+ * @var string $_body
+ */
+ private $_body;
+
+ /**
+ * Set the content type of this POST request.
+ *
+ * @param string $contentType content type
+ *
+ * @return void
+ * @throws CAS_OutOfSequenceException If called after the Request has been sent.
+ */
+ public function setContentType ($contentType)
+ {
+ if ($this->hasBeenSent()) {
+ throw new CAS_OutOfSequenceException('Cannot set the content type, request already sent.');
+ }
+
+ $this->_contentType = $contentType;
+ }
+
+ /**
+ * Set the body of this POST request.
+ *
+ * @param string $body body to set
+ *
+ * @return void
+ * @throws CAS_OutOfSequenceException If called after the Request has been sent.
+ */
+ public function setBody ($body)
+ {
+ if ($this->hasBeenSent()) {
+ throw new CAS_OutOfSequenceException('Cannot set the body, request already sent.');
+ }
+
+ $this->_body = $body;
+ }
+
+ /**
+ * Add any other parts of the request needed by concrete classes
+ *
+ * @param CAS_Request_RequestInterface $request request interface class
+ *
+ * @return void
+ */
+ protected function populateRequest (CAS_Request_RequestInterface $request)
+ {
+ if (empty($this->_contentType) && !empty($this->_body)) {
+ throw new CAS_ProxiedService_Exception("If you pass a POST body, you must specify a content type via ".get_class($this).'->setContentType($contentType).');
+ }
+
+ $request->makePost();
+ if (!empty($this->_body)) {
+ $request->addHeader('Content-Type: '.$this->_contentType);
+ $request->addHeader('Content-Length: '.strlen($this->_body));
+ $request->setPostBody($this->_body);
+ }
+ }
- /**
- * Set the body of this POST request.
- *
- * @param string $body
- * @return void
- * @throws CAS_OutOfSequenceException If called after the Request has been sent.
- */
- public function setBody ($body) {
- if ($this->hasBeenSent())
- throw new CAS_OutOfSequenceException('Cannot set the body, request already sent.');
-
- $this->_body = $body;
- }
-
- /**
- * Add any other parts of the request needed by concrete classes
- *
- * @param CAS_Request_RequestInterface $request
- * @return void
- */
- protected function populateRequest (CAS_Request_RequestInterface $request) {
- if (empty($this->_contentType) && !empty($this->_body))
- throw new CAS_ProxiedService_Exception("If you pass a POST body, you must specify a content type via ".get_class($this).'->setContentType($contentType).');
-
- $request->makePost();
- if (!empty($this->_body)) {
- $request->addHeader('Content-Type: '.$this->_contentType);
- $request->addHeader('Content-Length: '.strlen($this->_body));
- $request->setPostBody($this->_body);
- }
- }
-
}
+?>
View
432 source/CAS/ProxiedService/Imap.php
@@ -4,215 +4,257 @@
* 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 5
+ *
+ * @file CAS/ProxiedService/Imap.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 access to a proxy-authenticated IMAP stream
+ *
+ * @class CAS_ProxiedService_Imap
+ * @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_ProxiedService_Imap
- extends CAS_ProxiedService_Abstract
+extends CAS_ProxiedService_Abstract
{
-
- /**
- * The username to send via imap_open.
- *
- * @var string $_username;
- */
- private $_username;
-
- /**
- * Constructor.
- *
- * @param string $username
- * @return void
- */
- public function __construct ($username) {
- if (!is_string($username) || !strlen($username))
- throw new CAS_InvalidArgumentException('Invalid username.');
-
- $this->_username = $username;
- }
-
- /**
- * The target service url.
- * @var string $_url;
- */
- private $_url;
-
- /**
- * Answer a service identifier (URL) for whom we should fetch a proxy ticket.
- *
- * @return string
- * @throws Exception If no service url is available.
- */
- public function getServiceUrl () {
- if (empty($this->_url))
- throw new CAS_ProxiedService_Exception('No URL set via '.get_class($this).'->getServiceUrl($url).');
-
- return $this->_url;
- }
-
- /*********************************************************
- * Configure the Stream
- *********************************************************/
-
- /**
- * Set the URL of the service to pass to CAS for proxy-ticket retrieval.
- *
- * @param string $url
- * @return void
- * @throws CAS_OutOfSequenceException If called after the stream has been opened.
- */
- public function setServiceUrl ($url) {
- if ($this->hasBeenOpened())
- throw new CAS_OutOfSequenceException('Cannot set the URL, stream already opened.');
- if (!is_string($url) || !strlen($url))
- throw new CAS_InvalidArgumentException('Invalid url.');
-
- $this->_url = $url;
- }
-
- /**
- * The mailbox to open. See the $mailbox parameter of imap_open().
- *
- * @var string $_mailbox
- */
- private $_mailbox;
-
- /**
- * Set the mailbox to open. See the $mailbox parameter of imap_open().
- *
- * @param string $mailbox
- * @return void
- * @throws CAS_OutOfSequenceException If called after the stream has been opened.
- */
- public function setMailbox ($mailbox) {
- if ($this->hasBeenOpened())
- throw new CAS_OutOfSequenceException('Cannot set the mailbox, stream already opened.');
- if (!is_string($mailbox) || !strlen($mailbox))
- throw new CAS_InvalidArgumentException('Invalid mailbox.');
-
- $this->_mailbox = $mailbox;
- }
-
- /**
- * A bit mask of options to pass to imap_open() as the $options parameter.
- *
- * @var int $_options
- */
- private $_options = NULL;
-
- /**
- * Set the options for opening the stream. See the $options parameter of imap_open().
- *
- * @param int $options
- * @return void
- * @throws CAS_OutOfSequenceException If called after the stream has been opened.
- */
- public function setOptions ($options) {
- if ($this->hasBeenOpened())
- throw new CAS_OutOfSequenceException('Cannot set options, stream already opened.');
- if (!is_int($options))
- throw new CAS_InvalidArgumentException('Invalid options.');
-
- $this->_options = $options;
- }
-
- /*********************************************************
- * 2. Open the stream
- *********************************************************/
-
- /**
- * Open the IMAP stream (similar to imap_open()).
- *
- * @return resource Returns an IMAP stream on success
- * @throws CAS_OutOfSequenceException If called multiple times.
- * @throws CAS_ProxyTicketException If there is a proxy-ticket failure.
- * The code of the Exception will be one of:
- * PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE
- * PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE
- * PHPCAS_SERVICE_PT_FAILURE
- * @throws CAS_ProxiedService_Exception If there is a failure sending the request to the target service. */
- public function open () {
- if ($this->hasBeenOpened())
- throw new CAS_OutOfSequenceException('Stream already opened.');
- if (empty($this->_mailbox))
- throw new CAS_ProxiedService_Exception('You must specify a mailbox via '.get_class($this).'->setMailbox($mailbox)');
-
- phpCAS::traceBegin();
-
- // Get our proxy ticket and append it to our URL.
- $this->initializeProxyTicket();
- phpCAS::trace('opening IMAP mailbox `'.$this->_mailbox.'\'...');
- $this->_stream = @imap_open($this->_mailbox, $this->_username, $this->getProxyTicket(), $this->_options);
- if ($this->_stream) {
- phpCAS::trace('ok');
- } else {
- phpCAS::trace('could not open mailbox');
- // @todo add localization integration.
- $message = 'IMAP Error: '.$url.' '. var_export(imap_errors(),TRUE);
- phpCAS::trace($message);
- throw new CAS_ProxiedService_Exception($message);
- }
-
- phpCAS::traceEnd();
- return $this->_stream;
- }
-
- /**
- * Answer true if our request has been sent yet.
- *
- * @return boolean
- */
- protected function hasBeenOpened () {
- return !empty($this->_stream);
- }
-
- /*********************************************************
- * 3. Access the result
- *********************************************************/
- /**
- * The IMAP stream
- *
- * @var resource $_stream
- */
- private $_stream;
-
- /**
- * Answer the IMAP stream
- *
- * @return resource
- */
- public function getStream () {
- if (!$this->hasBeenOpened())
- throw new CAS_OutOfSequenceException('Cannot access stream, not opened yet.');
-
- return $this->_stream;
- }
-
- /**
- * CAS_Client::serviceMail() needs to return the proxy ticket for some reason,
- * so this method provides access to it.
- *
- * @return string
- * @throws CAS_OutOfSequenceException If called before the stream has been opened.
- */
- public function getImapProxyTicket () {
- if (!$this->hasBeenOpened())
- throw new CAS_OutOfSequenceException('Cannot access errors, stream not opened yet.');
-
- return $this->getProxyTicket();
- }
+
+ /**
+ * The username to send via imap_open.
+ *
+ * @var string $_username;
+ */
+ private $_username;
+
+ /**
+ * Constructor.
+ *
+ * @param string $username Username
+ *
+ * @return void
+ */
+ public function __construct ($username)
+ {
+ if (!is_string($username) || !strlen($username)) {
+ throw new CAS_InvalidArgumentException('Invalid username.');
+ }
+
+ $this->_username = $username;
+ }
+
+ /**
+ * The target service url.
+ * @var string $_url;
+ */
+ private $_url;
+
+ /**
+ * Answer a service identifier (URL) for whom we should fetch a proxy ticket.
+ *
+ * @return string
+ * @throws Exception If no service url is available.
+ */
+ public function getServiceUrl ()
+ {
+ if (empty($this->_url)) {
+ throw new CAS_ProxiedService_Exception('No URL set via '.get_class($this).'->getServiceUrl($url).');
+ }
+
+ return $this->_url;
+ }
+
+ /*********************************************************
+ * Configure the Stream
+ *********************************************************/
+
+ /**
+ * Set the URL of the service to pass to CAS for proxy-ticket retrieval.
+ *
+ * @param string $url Url to set
+ *
+ * @return void
+ * @throws CAS_OutOfSequenceException If called after the stream has been opened.
+ */
+ public function setServiceUrl ($url)
+ {
+ if ($this->hasBeenOpened()) {
+ throw new CAS_OutOfSequenceException('Cannot set the URL, stream already opened.');
+ }
+ if (!is_string($url) || !strlen($url)) {
+ throw new CAS_InvalidArgumentException('Invalid url.');
+ }
+
+ $this->_url = $url;
+ }
+
+ /**
+ * The mailbox to open. See the $mailbox parameter of imap_open().
+ *
+ * @var string $_mailbox
+ */
+ private $_mailbox;
+
+ /**
+ * Set the mailbox to open. See the $mailbox parameter of imap_open().
+ *
+ * @param string $mailbox Mailbox to set
+ *
+ * @return void
+ * @throws CAS_OutOfSequenceException If called after the stream has been opened.
+ */
+ public function setMailbox ($mailbox)
+ {
+ if ($this->hasBeenOpened()) {
+ throw new CAS_OutOfSequenceException('Cannot set the mailbox, stream already opened.');
+ }
+ if (!is_string($mailbox) || !strlen($mailbox)) {
+ throw new CAS_InvalidArgumentException('Invalid mailbox.');
+ }
+
+ $this->_mailbox = $mailbox;
+ }
+
+ /**
+ * A bit mask of options to pass to imap_open() as the $options parameter.
+ *
+ * @var int $_options
+ */
+ private $_options = null;
+
+ /**
+ * Set the options for opening the stream. See the $options parameter of
+ * imap_open().
+ *
+ * @param int $options Options for the stream
+ *
+ * @return void
+ * @throws CAS_OutOfSequenceException If called after the stream has been opened.
+ */
+ public function setOptions ($options)
+ {
+ if ($this->hasBeenOpened()) {
+ throw new CAS_OutOfSequenceException('Cannot set options, stream already opened.');
+ }
+ if (!is_int($options)) {
+ throw new CAS_InvalidArgumentException('Invalid options.');
+ }
+
+ $this->_options = $options;
+ }
+
+ /*********************************************************
+ * 2. Open the stream
+ *********************************************************/
+
+ /**
+ * Open the IMAP stream (similar to imap_open()).
+ *
+ * @return resource Returns an IMAP stream on success
+ * @throws CAS_OutOfSequenceException If called multiple times.
+ * @throws CAS_ProxyTicketException If there is a proxy-ticket failure.
+ * The code of the Exception will be one of:
+ * PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE
+ * PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE
+ * PHPCAS_SERVICE_PT_FAILURE
+ * @throws CAS_ProxiedService_Exception If there is a failure sending the request to the target service. */
+ public function open ()
+ {
+ if ($this->hasBeenOpened()) {
+ throw new CAS_OutOfSequenceException('Stream already opened.');
+ }
+ if (empty($this->_mailbox)) {
+ throw new CAS_ProxiedService_Exception('You must specify a mailbox via '.get_class($this).'->setMailbox($mailbox)');
+ }
+
+ phpCAS::traceBegin();
+
+ // Get our proxy ticket and append it to our URL.
+ $this->initializeProxyTicket();
+ phpCAS::trace('opening IMAP mailbox `'.$this->_mailbox.'\'...');
+ $this->_stream = @imap_open($this->_mailbox, $this->_username, $this->getProxyTicket(), $this->_options);
+ if ($this->_stream) {
+ phpCAS::trace('ok');
+ } else {
+ phpCAS::trace('could not open mailbox');
+ // @todo add localization integration.
+ $message = 'IMAP Error: '.$url.' '. var_export(imap_errors(), true);
+ phpCAS::trace($message);
+ throw new CAS_ProxiedService_Exception($message);
+ }
+
+ phpCAS::traceEnd();
+ return $this->_stream;
+ }
+
+ /**
+ * Answer true if our request has been sent yet.
+ *
+ * @return boolean
+ */
+ protected function hasBeenOpened ()
+ {
+ return !empty($this->_stream);
+ }
+
+ /*********************************************************
+ * 3. Access the result
+ *********************************************************/
+ /**
+ * The IMAP stream
+ *
+ * @var resource $_stream
+ */
+ private $_stream;
+
+ /**
+ * Answer the IMAP stream
+ *
+ * @return resource
+ */
+ public function getStream ()
+ {
+ if (!$this->hasBeenOpened()) {
+ throw new CAS_OutOfSequenceException('Cannot access stream, not opened yet.');
+ }
+ return $this->_stream;
+ }
+
+ /**
+ * CAS_Client::serviceMail() needs to return the proxy ticket for some reason,
+ * so this method provides access to it.
+ *
+ * @return string
+ * @throws CAS_OutOfSequenceException If called before the stream has been
+ * opened.
+ */
+ public function getImapProxyTicket ()
+ {
+ if (!$this->hasBeenOpened()) {
+ throw new CAS_OutOfSequenceException('Cannot access errors, stream not opened yet.');
+ }
+ return $this->getProxyTicket();
+ }
}
+?>
View
56 source/CAS/ProxiedService/Testable.php
@@ -4,18 +4,27 @@
* 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 5
+ *
+ * @file CAS/ProxiedService/Testabel.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
*/
/**
@@ -35,21 +44,30 @@
* else
* $this->casClient->initializeProxiedService($this);
* }
- *
+ *
+ * @class CAS_ProxiedService_Testabel
+ * @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_ProxiedService_Testable {
-
- /**
- * Use a particular CAS_Client->initializeProxiedService() rather than the
- * static phpCAS::initializeProxiedService().
- *
- * This method should not be called in standard operation, but is needed for unit
- * testing.
- *
- * @param CAS_Client $casClient
- * @return void
- * @throws CAS_OutOfSequenceException If called after a proxy ticket has already been initialized/set.
- */
- public function setCasClient (CAS_Client $casClient);
-
+interface CAS_ProxiedService_Testable
+{
+
+ /**
+ * Use a particular CAS_Client->initializeProxiedService() rather than the
+ * static phpCAS::initializeProxiedService().
+ *
+ * This method should not be called in standard operation, but is needed for unit
+ * testing.
+ *
+ * @param CAS_Client $casClient Cas client object
+ *
+ * @return void
+ * @throws CAS_OutOfSequenceException If called after a proxy ticket has already been initialized/set.
+ */
+ public function setCasClient (CAS_Client $casClient);
+
}
+?>
View
162 source/CAS/ProxyChain/AllowedList.php
@@ -4,90 +4,116 @@
* 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 5
+ *
+ * @file CAS/ProxyChain/AllowedList.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
*/
/**
* ProxyChain is a container for storing chains of valid proxies that can
* be used to validate proxied requests to a service
+ *
+ * @class CAS_ProxyChain_AllowedList
+ * @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_ProxyChain_AllowedList {
-
- private $_chains = array();
-
- /**
- * Check whether proxies are allowed by configuration
- */
- public function isProxyingAllowed(){
- return (count($this->_chains) > 0);
- }
-
- /**
- * Add a chain of proxies to the list of possible chains
- * @param array $chain
- */
- public function allowProxyChain(CAS_ProxyChain_Interface $chain) {
- $this->_chains[] = $chain;
- }
-
- /**
- *
- * Check if the proxies found in the response match the allowed proxies
- * @param array $proxies
- * @return boolean whether the proxies match the allowed proxies
- */
- public function isProxyListAllowed(array $proxies){
- phpCAS::traceBegin();
- if(empty($proxies)){
- phpCAS::trace("No proxies were found in the response");
- phpCAS::traceEnd(true);
- return true;
- }elseif(!$this->isProxyingAllowed()){
- phpCAS::trace("Proxies are not allowed");
- phpCAS::traceEnd(false);
- return false;
- }else{
- $res = $this->contains($proxies);
- phpCAS::traceEnd($res);
- return $res;
- }
- }
-
- /**
- *
- * Validate the proxies from the proxy ticket validation against the
- * chains that were definded.
- * @param array $list List of proxies from the proxy ticket validation.
- * @return if any chain fully matches the supplied list
- */
- public function contains(array $list){
- phpCAS::traceBegin();
- $count = 0;
- foreach ($this->_chains as $chain) {
- phpCAS::trace("Checking chain ". $count++);
- if ($chain->matches($list)) {
- phpCAS::traceEnd(true);
- return true;
- }
- }
- phpCAS::trace("No proxy chain matches.");
- phpCAS::traceEnd(false);
- return false;
- }
-
-}
+class CAS_ProxyChain_AllowedList
+{
+
+ private $_chains = array();
+
+ /**
+ * Check whether proxies are allowed by configuration
+ *
+ * @return boolean
+ */
+ public function isProxyingAllowed()
+ {
+ return (count($this->_chains) > 0);
+ }
+ /**
+ * Add a chain of proxies to the list of possible chains
+ *
+ * @param CAS_ProxyChain_Interface $chain A chain of proxies
+ *
+ * @return void
+ */
+ public function allowProxyChain(CAS_ProxyChain_Interface $chain)
+ {
+ $this->_chains[] = $chain;
+ }
+
+ /**
+ * Check if the proxies found in the response match the allowed proxies
+ *
+ * @param array $proxies list of proxies to check
+ *
+ * @return boolean whether the proxies match the allowed proxies
+ */
+ public function isProxyListAllowed(array $proxies)
+ {
+ phpCAS::traceBegin();
+ if (empty($proxies)) {
+ phpCAS::trace("No proxies were found in the response");
+ phpCAS::traceEnd(true);
+ return true;
+ } elseif (!$this->isProxyingAllowed()) {
+ phpCAS::trace("Proxies are not allowed");
+ phpCAS::traceEnd(false);
+ return false;
+ } else {
+ $res = $this->contains($proxies);
+ phpCAS::traceEnd($res);
+ return $res;
+ }
+ }
+
+ /**
+ * Validate the proxies from the proxy ticket validation against the
+ * chains that were definded.
+ *
+ * @param array $list List of proxies from the proxy ticket validation.
+ *
+ * @return if any chain fully matches the supplied list
+ */
+ public function contains(array $list)
+ {
+ phpCAS::traceBegin();
+ $count = 0;
+ foreach ($this->_chains as $chain) {
+ phpCAS::trace("Checking chain ". $count++);
+ if ($chain->matches($list)) {
+ phpCAS::traceEnd(true);
+ return true;
+ }
+ }
+ phpCAS::trace("No proxy chain matches.");
+ phpCAS::traceEnd(false);
+ return false;
+ }
+}
?>
View
56 source/CAS/ProxyChain/Any.php
@@ -4,43 +4,61 @@
* 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 5
+ *
+ * @file CAS/ProxyChain/Any.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
*/
/**
* A proxy-chain definition that will match any list of proxies.
*
- * Use this class for quick testing or in certain production screnarios you might want to
- * allow allow any other valid service to proxy your service.
+ * Use this class for quick testing or in certain production screnarios you
+ * might want to allow allow any other valid service to proxy your service.
*
- * THIS CLASS IS HOWEVER NOT RECOMMENDED FOR PRODUCTION AND HAS SECURITY
+ * THIS CLASS IS HOWEVER NOT RECOMMENDED FOR PRODUCTION AND HAS SECURITY
* IMPLICATIONS: YOU ARE ALLOWING ANY SERVICE TO ACT ON BEHALF OF A USER
* ON THIS SERVICE.
+ *
+ * @class CAS_ProxyChain_Any
+ * @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_ProxyChain_Any
- implements CAS_ProxyChain_Interface
+implements CAS_ProxyChain_Interface
{
-
- /**
- * Match a list of proxies.
- *
- * @param array $list The list of proxies in front of this service.
- * @return boolean
- */
- public function matches(array $list) {
- phpCAS::trace("Using CAS_ProxyChain_Any. No proxy validation is performed.");
- return true;
- }
-
+
+ /**
+ * Match a list of proxies.
+ *
+ * @param array $list The list of proxies in front of this service.
+ *
+ * @return boolean
+ */
+ public function matches(array $list)
+ {
+ phpCAS::trace("Using CAS_ProxyChain_Any. No proxy validation is performed.");
+ return true;
+ }
+
}
View
44 source/CAS/ProxyChain/Interface.php
@@ -4,32 +4,50 @@
* 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 5
+ *
+ * @file CAS/ProxyChain/Interface.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 interface for classes that define a list of allowed proxies in front of
* the current application.
+ *
+ * @class CAS_ProxyChain_Interface
+ * @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_ProxyChain_Interface {
-
- /**
- * Match a list of proxies.
- *
- * @param array $list The list of proxies in front of this service.
- * @return boolean
- */
- public function matches(array $list);
-
+interface CAS_ProxyChain_Interface
+{
+
+ /**
+ * Match a list of proxies.
+ *
+ * @param array $list The list of proxies in front of this service.
+ *
+ * @return boolean
+ */
+ public function matches(array $list);
+
}
View
45 source/CAS/ProxyChain/Trusted.php
@@ -16,25 +16,44 @@
* 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 5
+ *
+ * @file CAS/ProxyChain/Trusted.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
*/
/**
- * A proxy-chain definition that defines a chain up to a trusted proxy and delegates
- * the resposibility of validating the rest of the chain to that trusted proxy.
+ * A proxy-chain definition that defines a chain up to a trusted proxy and
+ * delegates the resposibility of validating the rest of the chain to that
+ * trusted proxy.
+ *
+ * @class CAS_ProxyChain_Trusted
+ * @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_ProxyChain_Trusted
- extends CAS_ProxyChain
- implements CAS_ProxyChain_Interface
+extends CAS_ProxyChain
+implements CAS_ProxyChain_Interface
{
- /**
- * Validate the size of the the list as compared to our chain.
- *
- * @param array $list
- * @return boolean
- */
- protected function isSizeValid (array $list) {
- return (sizeof($this->chain) <= sizeof($list));
- }
+ /**
+ * Validate the size of the the list as compared to our chain.
+ *
+ * @param array $list list of proxies
+ *
+ * @return boolean
+ */
+ protected function isSizeValid (array $list)
+ {
+ return (sizeof($this->chain) <= sizeof($list));
+ }
}
View
575 source/CAS/Request/AbstractRequest.php
@@ -4,281 +4,336 @@
* 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 5
+ *
+ * @file CAS/Request/AbstractRequest.php
+ * @category Authentication
+ * @package PhpCAS
+ * @author Adam Franco <afranco@middlebury.edu>
+