01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package edu.yale.its.tp.cas.ticket;
17:
18: import java.util.ArrayList;
19: import java.util.List;
20:
21: /**
22: * Represents a CAS proxy-granting ticket (PGT), used to retrieve proxy tickets (PTs). Note that we extend TicketGrantingTicket;
23: * this doesn't mean we can act as a TGC: a TicketCache for TGCs will never store a PGT.
24: */
25: public class ProxyGrantingTicket extends TicketGrantingTicket {
26:
27: // *********************************************************************
28: // Private, ticket state
29:
30: /**
31: * A PGT is constructed with a ServiceTicket (potentially a ProxyTicket). We store this ticket to inherit ticket expiration.
32: */
33: private ServiceTicket parent;
34:
35: /**
36: * A PGT is also consturcted with the ID of the proxy. In CAS 2.0.1, this ID corresponds to the callback URL to which the PGT's
37: * ID is sent.
38: */
39: private String proxyId;
40:
41: // *********************************************************************
42: // Constructor
43:
44: /** Constructs a new, immutable ProxyGrantingTicket. */
45: public ProxyGrantingTicket(ServiceTicket parent, String proxyId) {
46: super (parent.getUsername());
47: this .parent = parent;
48: this .proxyId = proxyId;
49: }
50:
51: // *********************************************************************
52: // Public interface
53:
54: /** Retrieves the ticket's username. */
55: public String getUsername() {
56: return parent.getUsername();
57: }
58:
59: /** Returns the ticket that was exchanged for this ProxyGrantingTicket. */
60: public ServiceTicket getParent() {
61: return parent;
62: }
63:
64: /**
65: * Returns the identifier for the service to whom this ticket will grant proxy tickets.
66: */
67: public String getProxyService() {
68: return proxyId;
69: }
70:
71: /** Retrieves trust chain. */
72: public List getProxies() {
73: List l = new ArrayList();
74: l.add(getProxyService());
75: if (parent.getGrantor() instanceof ProxyGrantingTicket) {
76: ProxyGrantingTicket p = (ProxyGrantingTicket) parent
77: .getGrantor();
78: l.addAll(p.getProxies());
79: }
80: return l;
81: }
82:
83: /**
84: * Returns true if the ticket (or any ticket in its grantor chain) is expired, false otherwise.
85: */
86: public boolean isExpired() {
87: return super.isExpired() || parent.getGrantor().isExpired();
88: }
89: }
|