001: /*
002: * $Id: Conditions.java,v 1.3 2007/01/08 16:05:59 shyam_rao Exp $
003: */
004:
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://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
025: */
026:
027: package com.sun.xml.wss.saml.assertion.saml20.jaxb20;
028:
029: import com.sun.xml.wss.saml.SAMLException;
030: import com.sun.xml.wss.logging.LogDomainConstants;
031: import com.sun.xml.wss.saml.internal.saml20.jaxb20.ConditionsType;
032: import com.sun.xml.wss.saml.util.SAML20JAXBUtil;
033: import java.util.GregorianCalendar;
034: import java.util.List;
035: import java.util.logging.Logger;
036:
037: import javax.xml.bind.JAXBContext;
038: import javax.xml.datatype.DatatypeConfigurationException;
039: import javax.xml.datatype.DatatypeFactory;
040:
041: /**
042: * The validity of an <code>Assertion</code> MAY be subject to a set of
043: * <code>Conditions</code>. Each <code>Condition</code> evaluates to a value that
044: * is Valid, Invalid or Indeterminate.
045: */
046: public class Conditions extends ConditionsType implements
047: com.sun.xml.wss.saml.Conditions {
048:
049: protected static final Logger log = Logger.getLogger(
050: LogDomainConstants.WSS_API_DOMAIN,
051: LogDomainConstants.WSS_API_DOMAIN_BUNDLE);
052:
053: /**
054: Constructor taking in nothing (SAML spec allows it)
055: */
056: public Conditions() {
057: super ();
058: }
059:
060: private void setConditionOrAudienceRestrictionOrOneTimeUse(
061: List condition) {
062: this .conditionOrAudienceRestrictionOrOneTimeUse = condition;
063: }
064:
065: /**
066: * Constructs an instance of <code>Conditions</code>.
067: *
068: * @param notBefore specifies the earliest time instant at which the
069: * assertion is valid.
070: * @param notOnOrAfter specifies the time instant at which the assertion
071: * has expired.
072: * @param condition
073: * @param ar the <code>AudienceRestrictionCondition</code> to be
074: * added. Can be null, if no audience restriction.
075: * @param doNotCacheCnd
076: * @exception SAMLException if there is a problem in input data and it
077: * cannot be processed correctly.
078: */
079: public Conditions(GregorianCalendar notBefore,
080: GregorianCalendar notOnOrAfter, List condition, List ar,
081: List oneTimeUse, List proxyRestriction) {
082:
083: DatatypeFactory factory = null;
084: try {
085: factory = DatatypeFactory.newInstance();
086: } catch (DatatypeConfigurationException e) {
087: factory = null;
088: }
089:
090: if (factory != null) {
091: setNotBefore(factory.newXMLGregorianCalendar(notBefore));
092: setNotOnOrAfter(factory
093: .newXMLGregorianCalendar(notOnOrAfter));
094: }
095:
096: if (condition != null) {
097: setConditionOrAudienceRestrictionOrOneTimeUse(condition);
098: } else if (ar != null) {
099: setConditionOrAudienceRestrictionOrOneTimeUse(ar);
100: } else if (oneTimeUse != null) {
101: setConditionOrAudienceRestrictionOrOneTimeUse(oneTimeUse);
102: } else if (proxyRestriction != null) {
103: setConditionOrAudienceRestrictionOrOneTimeUse(proxyRestriction);
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 = SAML20JAXBUtil.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: }
|