4 * Licensed to Jasig under one or more contributor license
5 * agreements. See the NOTICE file distributed with this work for
6 * additional information regarding copyright ownership.
8 * Jasig licenses this file to you under the Apache License,
9 * Version 2.0 (the "License"); you may not use this file except in
10 * compliance with the License. You may obtain a copy of the License at:
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * @file CAS/ProxiedService/Abstract.php
23 * @category Authentication
25 * @author Adam Franco <afranco@middlebury.edu>
26 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
27 * @link https://wiki.jasig.org/display/CASC/phpCAS
31 * This class implements common methods for ProxiedService implementations included
34 * @class CAS_ProxiedService_Abstract
35 * @category Authentication
37 * @author Adam Franco <afranco@middlebury.edu>
38 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
39 * @link https://wiki.jasig.org/display/CASC/phpCAS
41 abstract class CAS_ProxiedService_Abstract
42 implements CAS_ProxiedService, CAS_ProxiedService_Testable
46 * The proxy ticket that can be used when making service requests.
47 * @var string $_proxyTicket;
49 private $_proxyTicket;
52 * Register a proxy ticket with the Proxy that it can use when making requests.
54 * @param string $proxyTicket proxy ticket
57 * @throws InvalidArgumentException If the $proxyTicket is invalid.
58 * @throws CAS_OutOfSequenceException If called after a proxy ticket has already been initialized/set.
60 public function setProxyTicket ($proxyTicket)
62 if (empty($proxyTicket)) {
63 throw new CAS_InvalidArgumentException("Trying to initialize with an empty proxy ticket.");
65 if (!empty($this->_proxyTicket)) {
66 throw new CAS_OutOfSequenceException('Already initialized, cannot change the proxy ticket.');
68 $this->_proxyTicket = $proxyTicket;
72 * Answer the proxy ticket to be used when making requests.
75 * @throws CAS_OutOfSequenceException If called before a proxy ticket has
76 * already been initialized/set.
78 protected function getProxyTicket ()
80 if (empty($this->_proxyTicket)) {
81 throw new CAS_OutOfSequenceException('No proxy ticket yet. Call $this->initializeProxyTicket() to aquire the proxy ticket.');
84 return $this->_proxyTicket;
88 * @var CAS_Client $_casClient;
93 * Use a particular CAS_Client->initializeProxiedService() rather than the
94 * static phpCAS::initializeProxiedService().
96 * This method should not be called in standard operation, but is needed for unit
99 * @param CAS_Client $casClient cas client
102 * @throws CAS_OutOfSequenceException If called after a proxy ticket has
103 * already been initialized/set.
105 public function setCasClient (CAS_Client $casClient)
107 if (!empty($this->_proxyTicket)) {
108 throw new CAS_OutOfSequenceException('Already initialized, cannot change the CAS_Client.');
111 $this->_casClient = $casClient;
115 * Fetch our proxy ticket.
117 * Descendent classes should call this method once their service URL is available
118 * to initialize their proxy ticket.
121 * @throws CAS_OutOfSequenceException If called after a proxy ticket has
122 * already been initialized.
124 protected function initializeProxyTicket()
126 if (!empty($this->_proxyTicket)) {
127 throw new CAS_OutOfSequenceException('Already initialized, cannot initialize again.');
129 // Allow usage of a particular CAS_Client for unit testing.
130 if (empty($this->_casClient)) {
131 phpCAS::initializeProxiedService($this);
133 $this->_casClient->initializeProxiedService($this);