1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Proxy controller class. |
4
|
|
|
* |
5
|
|
|
* @version 1.2.0 |
6
|
|
|
* @since 1.2.0 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Cassava\CAS\Controller; |
10
|
|
|
|
11
|
|
|
use Cassava\CAS; |
12
|
|
|
use Cassava\Exception\GeneralException; |
13
|
|
|
use Cassava\Exception\RequestException; |
14
|
|
|
use Cassava\Exception\TicketException; |
15
|
|
|
use Cassava\Plugin; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Implements CAS proxy ticket generation. |
19
|
|
|
* |
20
|
|
|
* `/proxy` provides proxy tickets to services that have acquired proxy-granting tickets and |
21
|
|
|
* will be proxying authentication to back-end services. |
22
|
|
|
* |
23
|
|
|
* The following HTTP request parameters must be provided: |
24
|
|
|
* |
25
|
|
|
* - `pgt` (required): The proxy-granting ticket (PGT) acquired by the service during |
26
|
|
|
* service ticket (ST) or proxy ticket (PT) validation. |
27
|
|
|
* - `targetService` (required): The service identifier of the back-end service. Note that not |
28
|
|
|
* all back-end services are web services so this service identifier will not always be a URL. |
29
|
|
|
* However, the service identifier specified here must match the "service" parameter specified |
30
|
|
|
* to `/proxyValidate` upon validation of the proxy ticket. |
31
|
|
|
* |
32
|
|
|
* @since 1.2.0 |
33
|
|
|
*/ |
34
|
|
|
class ProxyController extends ValidateController { |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Valid ticket types. |
38
|
|
|
* |
39
|
|
|
* `/proxy` checks the validity of the proxy-granting ticket passed. |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
protected $validTicketTypes = array( |
44
|
|
|
CAS\Ticket::TYPE_PGT, |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Handles proxy ticket generation requests. |
49
|
|
|
* |
50
|
|
|
* This method attempts to set a `Content-Type: text/xml` HTTP response header. |
51
|
|
|
* |
52
|
|
|
* @param array $request Request arguments. |
53
|
|
|
* @return string Response XML string. |
54
|
|
|
*/ |
55
|
|
|
public function handleRequest( $request ) { |
56
|
|
|
$pgt = isset( $request['pgt'] ) ? $request['pgt'] : ''; |
57
|
|
|
$targetService = isset( $request['targetService'] ) ? $request['targetService'] : ''; |
58
|
|
|
|
59
|
|
|
$response = new CAS\Response\ProxyResponse; |
60
|
|
|
|
61
|
|
|
try { |
62
|
|
|
$ticket = $this->validateRequest( $pgt, $targetService ); |
63
|
|
|
$proxyTicket = new CAS\Ticket( CAS\Ticket::TYPE_PT, $ticket->user, $targetService ); |
64
|
|
|
|
65
|
|
|
$response->setTicket( $proxyTicket ); |
66
|
|
|
} |
67
|
|
|
catch ( GeneralException $exception ) { |
68
|
|
|
$response->setError( $exception->getErrorInstance(), 'proxyFailure' ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$this->server->setResponseContentType( 'text/xml' ); |
72
|
|
|
|
73
|
|
|
return $response->prepare(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Validates a proxy ticket, returning a ticket object, or throws an exception. |
78
|
|
|
* |
79
|
|
|
* @param string $ticket Service or proxy ticket. |
80
|
|
|
* @param string $service Service URI. |
81
|
|
|
* @return \Cassava\CAS\Ticket Valid ticket object associated with request. |
82
|
|
|
* |
83
|
|
|
* @throws \Cassava\Exception\RequestException |
84
|
|
|
* @throws \Cassava\Exception\TicketException |
85
|
|
|
*/ |
86
|
|
|
public function validateRequest( $ticket = '', $service = '' ) { |
87
|
|
|
try { |
88
|
|
|
return parent::validateRequest( $ticket, $service ); |
89
|
|
|
|
90
|
|
|
} catch ( TicketException $exception ) { |
91
|
|
|
throw new TicketException( $exception->getMessage(), |
92
|
|
|
TicketException::ERROR_BAD_PGT ); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|