001: /*
002: * $Id: SamlAssertionHeaderBlock.java,v 1.4 2007/01/08 09:28:48 ashutoshshahi 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.core;
028:
029: import java.util.logging.Logger;
030: import javax.xml.parsers.ParserConfigurationException;
031: import javax.xml.soap.SOAPElement;
032:
033: import org.w3c.dom.Document;
034: import org.w3c.dom.Element;
035:
036: import com.sun.xml.wss.impl.misc.SecurityHeaderBlockImpl;
037: import com.sun.xml.wss.logging.LogDomainConstants;
038: import com.sun.xml.wss.impl.XMLUtil;
039: import com.sun.xml.wss.XWSSecurityException;
040:
041: /**
042: * The schema definition for a SAML <code>Assertion</code> is as follows:
043: * <xmp>
044: * <element name="Assertion" type="saml:AssertionType"/>
045: * <complexType name="AssertionType">
046: * <sequence>
047: * <element ref="saml:Conditions" minOccurs="0"/>
048: * <element ref="saml:Advice" minOccurs="0"/>
049: * <choice maxOccurs="unbounded">
050: * <element ref="saml:Statement"/>
051: * <element ref="saml:SubjectStatement"/>
052: * <element ref="saml:AuthenticationStatement"/>
053: * <element ref="saml:AuthorizationDecisionStatement"/>
054: * <element ref="saml:AttributeStatement"/>
055: * </choice>
056: * <element ref="ds:Signature" minOccurs="0"/>
057: * </sequence>
058: * <attribute name="MajorVersion" type="integer" use="required"/>
059: * <attribute name="MinorVersion" type="integer" use="required"/>
060: * <attribute name="AssertionID" type="saml:IDType" use="required"/>
061: * <attribute name="Issuer" type="string" use="required"/>
062: * <attribute name="IssueInstant" type="dateTime" use="required"/>
063: * </complexType>
064: * </xmp>
065: *
066: * @author Axl Mattheus
067: */
068: public class SamlAssertionHeaderBlock extends SecurityHeaderBlockImpl
069: implements SecurityToken {
070: private static Logger log = Logger.getLogger(
071: LogDomainConstants.WSS_API_DOMAIN,
072: LogDomainConstants.WSS_API_DOMAIN_BUNDLE);
073:
074: /**
075: *
076: * @param element
077: * @return
078: * @throws XWSSecurityException
079: */
080: public static SecurityHeaderBlock fromSoapElement(
081: SOAPElement element) throws XWSSecurityException {
082: return SecurityHeaderBlockImpl.fromSoapElement(element,
083: SamlAssertionHeaderBlock.class);
084: }
085:
086: private Document contextDocument_ = null;
087: private Element delegateAssertion_ = null;
088:
089: /**
090: * Constructs code>SamlAssertionHeaderBlock</code> from an existing SAML
091: * <code>Assertion</code>.
092: *
093: * @param assertion
094: * @throws XWSSecurityException
095: */
096: public SamlAssertionHeaderBlock(Element assertion, Document doc)
097: throws XWSSecurityException {
098: if (null != assertion) {
099: delegateAssertion_ = assertion;
100: contextDocument_ = doc;
101: } else {
102: throw new XWSSecurityException("Assertion may not be null.");
103: }
104: }
105:
106: /**
107: * Constructs a SAML <code>Assertion</code> header block from an existing
108: * <code>SOAPElement</code>.
109: *
110: * @param element an existing SAML assertion element.
111: * @throws XWSSecurityException when the element is not a valid template
112: * for a SAML <code>Assertion</code>.
113: */
114: public SamlAssertionHeaderBlock(SOAPElement element)
115: throws XWSSecurityException {
116: contextDocument_ = element.getOwnerDocument();
117:
118: delegateAssertion_ = element;
119:
120: setSOAPElement(element);
121: }
122:
123: /* (non-Javadoc)
124: * @see com.sun.xml.wss.SecurityHeaderBlock#getAsSoapElement()
125: */
126: public SOAPElement getAsSoapElement() throws XWSSecurityException {
127:
128: // uncomment after making SamlAssertionHeaderBlock like others (using a dirty flag).
129: if (delegateElement != null) {
130: return delegateElement;
131: }
132:
133: if (null == contextDocument_) {
134: try {
135: contextDocument_ = XMLUtil.newDocument();
136: } catch (ParserConfigurationException e) {
137: throw new XWSSecurityException(e);
138: }
139: }
140:
141: try {
142: SOAPElement se = (SOAPElement) contextDocument_.importNode(
143: delegateAssertion_, true);
144: setSOAPElement(se);
145:
146: } catch (Exception e) {
147: throw new XWSSecurityException(e);
148: }
149:
150: return super .getAsSoapElement();
151: }
152:
153: /**
154: * @return
155: */
156: public Document getContextDocument() {
157: return contextDocument_;
158: }
159:
160: /**
161: * @return
162: */
163: public Element getDelegateAssertion() {
164: return delegateAssertion_;
165: }
166:
167: /**
168: * Set the signature for the Request.
169: *
170: * @param elem <code>ds:Signature</code> element.
171: * @return A boolean value: true if the operation succeeds; false otherwise.
172: */
173: /*public boolean setSignature(Element elem) {
174: try {
175: JAXBContext jc =
176: JAXBContext.newInstance("com.sun.xml.wss.saml.internal");
177: javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
178: delegateAssertion_.setSignature((SignatureType)u.unmarshal(elem));
179: return true;
180: } catch ( Exception ex) {
181: return false;
182: }
183: }*/
184:
185: }
|