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/ProxyChain.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 * A normal proxy-chain definition that lists each level of the chain as either
32 * a string or regular expression.
34 * @class CAS_ProxyChain
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
43 implements CAS_ProxyChain_Interface
46 protected $chain = array();
49 * A chain is an array of strings or regexp strings that will be matched
50 * against. Regexp will be matched with preg_match and strings will be
51 * matched from the beginning. A string must fully match the beginning of
52 * an proxy url. So you can define a full domain as acceptable or go further
54 * Proxies have to be defined in reverse from the service to the user. If a
55 * user hits service A get proxied via B to service C the list of acceptable
56 * proxies on C would be array(B,A);
58 * @param array $chain A chain of proxies
60 public function __construct(array $chain)
62 $this->chain = array_values($chain); // Ensure that we have an indexed array
66 * Match a list of proxies.
68 * @param array $list The list of proxies in front of this service.
72 public function matches(array $list)
74 $list = array_values($list); // Ensure that we have an indexed array
75 if ($this->isSizeValid($list)) {
77 foreach ($this->chain as $i => $search) {
78 $proxy_url = $list[$i];
79 if (preg_match('/^\/.*\/[ixASUXu]*$/s', $search)) {
80 if (preg_match($search, $proxy_url)) {
81 phpCAS::trace("Found regexp " . $search . " matching " . $proxy_url);
83 phpCAS::trace("No regexp match " . $search . " != " . $proxy_url);
88 if (strncasecmp($search, $proxy_url, strlen($search)) == 0) {
89 phpCAS::trace("Found string " . $search . " matching " . $proxy_url);
91 phpCAS::trace("No match " . $search . " != " . $proxy_url);
98 phpCAS::trace("Proxy chain matches");
102 phpCAS::trace("Proxy chain skipped: size mismatch");
108 * Validate the size of the the list as compared to our chain.
110 * @param array $list List of proxies
114 protected function isSizeValid (array $list)
116 return (sizeof($this->chain) == sizeof($list));