001: /* Copyright 2006 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.security.provider.cas;
007:
008: import org.jasig.portal.PortalException;
009:
010: import edu.yale.its.tp.cas.client.CASReceipt;
011:
012: /**
013: * Represents an exceptional condition encountered while attempting to
014: * acquire a CAS Proxy Ticket.
015: *
016: * This exception evolved from edu.yale.its.tp.portal.security.CASProxyTicketAcquisitionException
017: * as distributed in the Yale uPortal CAS security provider distribution version 3.0.0.
018: */
019: public class CasProxyTicketAcquisitionException extends PortalException {
020:
021: private static final long serialVersionUID = 1L;
022:
023: /**
024: * The service for which a proxy ticket could not be acquired.
025: */
026: private final String service;
027:
028: /**
029: * CASReceipt provding background about the interaction with the CAS server
030: * that did not produce a proxy granting ticket.
031: */
032: private final CASReceipt receipt;
033:
034: /**
035: * The pgtiou that was unsuccessfully presented for obtaining a proxy
036: * ticket. This field will be null when the constructor supplies a
037: * CASReceipt instead of a pgtiou. The CASReceipt contains the pgtiou.
038: */
039: private final String pgtIou;
040:
041: /**
042: * Exception thrown when cannot obtain proxy ticket for a given service using the given receipt.
043: * @param serviceArg - service for which a PT was requested
044: * @param receiptArg - receipt the pgtIou of which was being used to obtain the PT.
045: */
046: public CasProxyTicketAcquisitionException(String serviceArg,
047: CASReceipt receiptArg) {
048: super ("Could not obtain proxy ticket for service ["
049: + serviceArg + "] using credentials [" + receiptArg
050: + "]");
051: this .service = serviceArg;
052: this .receipt = receiptArg;
053: this .pgtIou = null;
054: }
055:
056: /**
057: * Exception thrown when cannot obtain proxy ticket for a given service using the given receipt.
058: * @param serviceArg - service for which a PT was requested
059: * @param receiptArg - receipt the pgtIou of which was being used to obtain the PT.
060: * @param cause - underlying throwable causing the error condition
061: */
062: public CasProxyTicketAcquisitionException(String serviceArg,
063: CASReceipt receiptArg, Throwable cause) {
064: super ("Could not obtain proxy ticket for service ["
065: + serviceArg + "] using credentials [" + receiptArg
066: + "].", cause);
067: this .service = serviceArg;
068: this .receipt = receiptArg;
069: this .pgtIou = null;
070: }
071:
072: /**
073: * Exception thrown when cannot obtain proxy ticket for a given service using the given pgtIou.
074: * @param serviceArg - service for which a PT was requested.
075: * @param pgtIouArg - the pgtIou for the PGT which was to be used to obtain the PT.
076: */
077: public CasProxyTicketAcquisitionException(String serviceArg,
078: String pgtIouArg) {
079: super ("Could not obtain proxy ticket for service ["
080: + serviceArg + "] using credentials [" + pgtIouArg
081: + "]");
082: this .service = serviceArg;
083: this .pgtIou = pgtIouArg;
084: this .receipt = null;
085: }
086:
087: /**
088: * Exception thrown when cannot obtain proxy ticket for a given service using the given pgtIou.
089: * @param serviceArg - service for which a PT was requested.
090: * @param pgtIouArg - the pgtIou for the PGT which was to be used to obtain the PT.
091: * @param cause - underlying cause of the error condition
092: */
093: public CasProxyTicketAcquisitionException(String serviceArg,
094: String pgtIouArg, Throwable cause) {
095: super ("Could not obtain proxy ticket for service ["
096: + serviceArg + "] using credentials [" + pgtIouArg
097: + "]", cause);
098: this .service = serviceArg;
099: this .pgtIou = pgtIouArg;
100: this .receipt = null;
101: }
102:
103: /**
104: * Get the CASReceipt if present, null otherwise.
105: * CASReceipts convey information about a CAS authentication and can provide
106: * useful diagnostic context for understanding the failure to acquire a
107: * proxy granting ticket represented by this exception.
108: * The CASReceipt may not be available depending upon the context with which
109: * this exception was initialized, so this method may return null.
110: * @return the CASReceipt or null.
111: */
112: public CASReceipt getReceipt() {
113: return this .receipt;
114: }
115:
116: /**
117: * Get the identifer of the service service for which the portal was trying
118: * to obtain a Proxy Ticket when this exception was generated.
119: * @return the service.
120: */
121: public String getService() {
122: return this .service;
123: }
124:
125: /**
126: * Get the PgtIou.
127: * The pgtiou may have been set explicitly in the constructor or this method
128: * may read it from the stored CASReceipt.
129: * @return the pgtiou.
130: */
131: public String getPgtIou() {
132:
133: if (this.pgtIou != null) {
134: return this.pgtIou;
135: } else if (this.receipt != null) {
136: return this.receipt.getPgtIou();
137: }
138:
139: return null;
140: }
141: }
|