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 in
005: * compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://glassfish.dev.java.net/public/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 Notice in each file and include the License file
014: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
015: * If applicable, add the following below the CDDL Header,
016: * with the fields enclosed by brackets [] replaced by
017: * you own identifying information:
018: * "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
021: */
022:
023: package com.sun.xml.ws.security.opt.impl.keyinfo;
024:
025: import com.sun.xml.ws.security.opt.api.SecurityElementWriter;
026: import com.sun.xml.ws.security.opt.api.SecurityHeaderElement;
027: import com.sun.xml.ws.security.opt.impl.util.JAXBUtil;
028: import com.sun.xml.wss.saml.Assertion;
029: import java.io.OutputStream;
030: import java.util.HashMap;
031: import javax.xml.bind.JAXBContext;
032: import javax.xml.bind.JAXBException;
033: import javax.xml.bind.Marshaller;
034: import javax.xml.stream.XMLStreamException;
035: import javax.xml.stream.XMLStreamReader;
036: import javax.xml.stream.XMLStreamWriter;
037:
038: import com.sun.xml.ws.api.SOAPVersion;
039:
040: /**
041: *
042: * @author K.Venugopal@sun.com
043: */
044: public class SAMLToken implements SecurityHeaderElement,
045: SecurityElementWriter {
046: private Assertion samlToken = null;
047: private JAXBContext jxbContext = null;
048: private SOAPVersion soapVersion = null;
049:
050: /** Creates a new instance of SAMLToken */
051: public SAMLToken(Assertion assertion, JAXBContext jxbContext,
052: SOAPVersion soapVersion) {
053: this .samlToken = assertion;
054: this .jxbContext = jxbContext;
055: this .soapVersion = soapVersion;
056:
057: }
058:
059: public boolean refersToSecHdrWithId(String id) {
060: throw new UnsupportedOperationException();
061: }
062:
063: public String getId() {
064: return samlToken.getAssertionID();
065: }
066:
067: public void setId(String id) {
068: throw new UnsupportedOperationException();
069: }
070:
071: public String getNamespaceURI() {
072: throw new UnsupportedOperationException();
073: }
074:
075: public String getLocalPart() {
076: throw new UnsupportedOperationException();
077: }
078:
079: public XMLStreamReader readHeader() throws XMLStreamException {
080: throw new UnsupportedOperationException();
081: }
082:
083: public void writeTo(XMLStreamWriter streamWriter)
084: throws XMLStreamException {
085: try {
086: Marshaller marshaller = jxbContext.createMarshaller();
087: if (SOAPVersion.SOAP_11 == soapVersion) {
088: marshaller.setProperty(
089: "com.sun.xml.bind.namespacePrefixMapper",
090: JAXBUtil.prefixMapper11);
091: } else {
092: marshaller.setProperty(
093: "com.sun.xml.bind.namespacePrefixMapper",
094: JAXBUtil.prefixMapper12);
095: }
096: marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
097: marshaller.setProperty("com.sun.xml.bind.xmlDeclaration",
098: false);
099: marshaller.marshal(samlToken, streamWriter);
100:
101: } catch (javax.xml.bind.PropertyException pe) {
102: throw new XMLStreamException(
103: "Error occurred while setting security marshaller properties",
104: pe);
105: } catch (JAXBException je) {
106: throw new XMLStreamException(
107: "Error occurred while marshalling SAMLAssertion",
108: je);
109: }
110: }
111:
112: public void writeTo(XMLStreamWriter streamWriter, HashMap props)
113: throws XMLStreamException {
114: }
115:
116: public void writeTo(OutputStream os) {
117: }
118:
119: }
|