001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: /*
021: * $Id: Conditions.java,v 1.5 2007/01/08 16:06:06 shyam_rao Exp $
022: */
023:
024: /*
025: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
026: * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
027: */
028:
029: package com.sun.xml.wss.saml.assertion.saml11.jaxb20;
030:
031: import com.sun.xml.wss.saml.SAMLException;
032: import com.sun.xml.wss.logging.LogDomainConstants;
033: import com.sun.xml.wss.saml.internal.saml11.jaxb20.ConditionsType;
034: import com.sun.xml.wss.saml.util.SAMLJAXBUtil;
035: import java.util.GregorianCalendar;
036: import java.util.List;
037: import java.util.logging.Logger;
038:
039: import javax.xml.bind.JAXBContext;
040: import javax.xml.datatype.DatatypeConfigurationException;
041: import javax.xml.datatype.DatatypeFactory;
042:
043: /**
044: * The validity of an <code>Assertion</code> MAY be subject to a set of
045: * <code>Conditions</code>. Each <code>Condition</code> evaluates to a value that
046: * is Valid, Invalid or Indeterminate.
047: */
048: public class Conditions extends ConditionsType implements
049: com.sun.xml.wss.saml.Conditions {
050:
051: protected static final Logger log = Logger.getLogger(
052: LogDomainConstants.WSS_API_DOMAIN,
053: LogDomainConstants.WSS_API_DOMAIN_BUNDLE);
054:
055: /**
056: Constructor taking in nothing (SAML spec allows it)
057: */
058: public Conditions() {
059: super ();
060: }
061:
062: private void setaudienceRestrictionConditionOrDoNotCacheConditionOrCondition(
063: List condition) {
064: this .audienceRestrictionConditionOrDoNotCacheConditionOrCondition = condition;
065: }
066:
067: /**
068: * Constructs an instance of <code>Conditions</code>.
069: *
070: * @param notBefore specifies the earliest time instant at which the
071: * assertion is valid.
072: * @param notOnOrAfter specifies the time instant at which the assertion
073: * has expired.
074: * @param condition
075: * @param arc the <code>AudienceRestrictionCondition</code> to be
076: * added. Can be null, if no audience restriction.
077: * @param doNotCacheCnd
078: * @exception SAMLException if there is a problem in input data and it
079: * cannot be processed correctly.
080: */
081: public Conditions(GregorianCalendar notBefore,
082: GregorianCalendar notOnOrAfter, List condition, List arc,
083: List doNotCacheCnd) {
084:
085: DatatypeFactory factory = null;
086: try {
087: factory = DatatypeFactory.newInstance();
088: } catch (DatatypeConfigurationException e) {
089: factory = null;
090: }
091:
092: if (factory != null) {
093: setNotBefore(factory.newXMLGregorianCalendar(notBefore));
094: setNotOnOrAfter(factory
095: .newXMLGregorianCalendar(notOnOrAfter));
096: }
097:
098: if (condition != null) {
099: setaudienceRestrictionConditionOrDoNotCacheConditionOrCondition(condition);
100: } else if (arc != null) {
101: setaudienceRestrictionConditionOrDoNotCacheConditionOrCondition(arc);
102: } else if (doNotCacheCnd != null) {
103: setaudienceRestrictionConditionOrDoNotCacheConditionOrCondition(doNotCacheCnd);
104: }
105: }
106:
107: /**
108: * Constructs a <code>Conditions</code> element from an existing XML block.
109: *
110: * @param conditionsElement A <code>org.w3c.dom.Element</code> representing
111: * DOM tree for <code>Conditions</code> object
112: * @exception SAMLException if it could not process the Element properly,
113: * implying that there is an error in the sender or in the
114: * element definition.
115: */
116: public static ConditionsType fromElement(org.w3c.dom.Element element)
117: throws SAMLException {
118: try {
119: JAXBContext jc = SAMLJAXBUtil.getJAXBContext();
120:
121: javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
122: return (ConditionsType) u.unmarshal(element);
123: } catch (Exception ex) {
124: throw new SAMLException(ex.getMessage());
125: }
126: }
127: }
|