001/** 002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 003 * 004 * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved 005 * 006 * The contents of this file are subject to the terms 007 * of the Common Development and Distribution License 008 * (the License). You may not use this file except in 009 * compliance with the License. 010 * 011 * You can obtain a copy of the License at 012 * https://opensso.dev.java.net/public/CDDLv1.0.html or 013 * opensso/legal/CDDLv1.0.txt 014 * See the License for the specific language governing 015 * permission and limitations under the License. 016 * 017 * When distributing Covered Code, include this CDDL 018 * Header Notice in each file and include the License file 019 * at opensso/legal/CDDLv1.0.txt. 020 * If applicable, add the following below the CDDL Header, 021 * with the fields enclosed by brackets [] replaced by 022 * your own identifying information: 023 * "Portions Copyrighted [year] [name of copyright owner]" 024 * 025 * $Id: DoNotCacheCondition.java,v 1.3 2008/06/25 05:47:32 qcheng Exp $ 026 * 027 */ 028 029package com.sun.identity.saml.assertion; 030 031import com.sun.identity.saml.common.SAMLUtilsCommon; 032import com.sun.identity.saml.common.SAMLConstants; 033import com.sun.identity.saml.common.SAMLException; 034import com.sun.identity.saml.common.SAMLRequesterException; 035import org.w3c.dom.Element; 036 037/** 038 *This is an implementation of the abstract <code>Condition</code> class, which 039 *specifes that the assertion this <code>DoNotCacheCondition</code> is part of, 040 *is the new element in SAML 1.1, that allows an assertion party to express 041 *that an assertion should not be cached by the relying party for future use. 042 *In another word, such an assertion is meant only for "one-time" use by the 043 *relying party. 044 * 045 * @supported.all.api 046 */ 047public class DoNotCacheCondition extends Condition { 048 private SAMLConstants sc; 049 050 /** 051 * Constructs a new <code>DoNotCacheCondition</code>. 052 * 053 */ 054 public DoNotCacheCondition() { 055 } 056 057 /** 058 * Constructs a <code>DoNotCacheCondition</code> element from 059 * an existing XML block. 060 * 061 * @param doNotCacheConditionElement A 062 * <code>org.w3c.dom.Element</code> representing DOM tree 063 * for <code>DoNotCacheCondition</code> object. 064 * @exception SAMLException if it could not process the 065 * <code>org.w3c.dom.Element</code> properly, implying that 066 * there is an error in the sender or in the element definition. 067 */ 068 public DoNotCacheCondition( 069 org.w3c.dom.Element doNotCacheConditionElement) 070 throws SAMLException 071 { 072 Element elt = (Element)doNotCacheConditionElement; 073 String eltName = elt.getLocalName(); 074 if (eltName == null) { 075 if (SAMLUtilsCommon.debug.messageEnabled()) { 076 SAMLUtilsCommon.debug.message("DoNotCacheCondition: " 077 + "null condition "); 078 } 079 throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString( 080 "nullInput")); 081 } 082 if (!(eltName.equals("DoNotCacheCondition"))) { 083 if (!(eltName.equals("Condition"))) { 084 if (SAMLUtilsCommon.debug.messageEnabled()) { 085 SAMLUtilsCommon.debug.message("DoNotCacheCondition: " 086 + "unsupported condition "); 087 } 088 throw new SAMLRequesterException( 089 SAMLUtilsCommon.bundle.getString( 090 "unsupportedCondition")); 091 } 092 } 093 if (eltName.equals("Condition")) { // seems like extension type 094 String type = elt.getAttribute("xsi:type"); 095 if (!(type.equals("DoNotCacheCondition"))) { 096 if (SAMLUtilsCommon.debug.messageEnabled()) { 097 SAMLUtilsCommon.debug.message( 098 "DoNotCacheCondition: invalid condition"); 099 } 100 throw new SAMLRequesterException( 101 SAMLUtilsCommon.bundle.getString("invalidElement")); 102 } 103 } 104 } 105 106 /** 107 * Creates a String representation of the element. 108 * 109 * @return A string containing the valid XML for this element 110 * By default name space name is prepended to the element name 111 * example <code><saml:DoNotCacheCondition></code>. 112 */ 113 public java.lang.String toString() { 114 // call toString() with includeNS true by default and declareNS false 115 String xml = this.toString(true, false); 116 return xml; 117 } 118 119 /** 120 * Returns a String representation of the 121 * <code><DoNotCacheCondition></code> element. 122 * 123 * @param includeNS Determines whether or not the namespace qualifier is 124 * prepended to the Element when converted 125 * @param declareNS Determines whether or not the namespace is declared 126 * within the Element. 127 * @return A string containing the valid XML for this element 128 */ 129 public java.lang.String toString(boolean includeNS, boolean declareNS) { 130 StringBuffer xml = new StringBuffer(300); 131 String o = SAMLUtilsCommon.makeStartElementTagXML( 132 "DoNotCacheCondition", includeNS, declareNS); 133 xml.append(o); 134 135 o = SAMLUtilsCommon.makeEndElementTagXML( 136 "DoNotCacheCondition",includeNS); 137 xml.append(o); 138 return xml.toString(); 139 } 140 141 /** 142 * Evaluates the Conditions 143 * A method which can be overridden by a plug-in maybe which provides 144 * means of evaluating this condition 145 * 146 * @return evaluation state. 147 */ 148 public int evaluate() { 149 return Condition.INDETERMINATE; 150 } 151 152} 153