001: /*
002: * $Id: RequestedSecurityTokenImpl.java,v 1.1 2007/08/23 12:40:55 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.ws.security.trust.impl.wssx.elements;
028:
029: import org.w3c.dom.Element;
030:
031: import javax.xml.namespace.QName;
032: import javax.xml.bind.JAXBContext;
033: import javax.xml.bind.JAXBElement;
034: import javax.xml.bind.JAXBException;
035:
036: //import com.sun.xml.security.core.xenc.EncryptedDataType;
037:
038: import com.sun.xml.ws.security.Token;
039: import com.sun.xml.ws.api.security.trust.WSTrustException;
040: import com.sun.xml.ws.security.trust.GenericToken;
041: import com.sun.xml.ws.security.trust.WSTrustElementFactory;
042: import com.sun.xml.ws.security.trust.elements.RequestedSecurityToken;
043: import com.sun.xml.ws.security.trust.impl.wssx.bindings.RequestedSecurityTokenType;
044: import com.sun.xml.ws.security.secconv.WSSCConstants;
045: import com.sun.xml.ws.security.secconv.impl.wssx.elements.SecurityContextTokenImpl;
046: import com.sun.xml.ws.security.secconv.impl.wssx.bindings.SecurityContextTokenType;
047:
048: import com.sun.xml.wss.saml.assertion.saml11.jaxb20.Assertion;
049: import com.sun.xml.wss.saml.internal.saml11.jaxb20.AssertionType;
050:
051: /**
052: * Implementation for the RequestedSecurityToken.
053: *
054: * @author Manveen Kaur
055: */
056: public class RequestedSecurityTokenImpl extends
057: RequestedSecurityTokenType implements RequestedSecurityToken {
058:
059: Token containedToken = null;
060:
061: private final static QName SecurityContextToken_QNAME = new QName(
062: "http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512",
063: "SecurityContextToken");
064:
065: private final static QName SAML11_Assertion_QNAME = new QName(
066: "urn:oasis:names:tc:SAML:1.0:assertion", "Assertion");
067:
068: private final static QName EncryptedData_QNAME = new QName(
069: "http://www.w3.org/2001/04/xmlenc#", "EncryptedData");
070:
071: /**
072: * Empty default constructor.
073: */
074: public RequestedSecurityTokenImpl() {
075: }
076:
077: public RequestedSecurityTokenImpl(
078: RequestedSecurityTokenType rdstType) {
079: Object rdst = rdstType.getAny();
080: if (rdst instanceof JAXBElement) {
081: JAXBElement<Object> rdstEle = (JAXBElement) rdst;
082: QName name = rdstEle.getName();
083: if (SecurityContextToken_QNAME.equals(name)) {
084: SecurityContextTokenType sctType = (SecurityContextTokenType) rdstEle
085: .getValue();
086: setToken(new SecurityContextTokenImpl(sctType));
087: }/*else if(EncryptedData_QNAME.equals(name)){
088: EncryptedDataType edType = (EncryptedDataType)rdstEle.getValue();
089: setToken(edType);
090: }else if(SAML11_Assertion_QNAME.equals(name)){
091: AssertionType assertionType = (AssertionType)rdstEle.getValue();
092: setToken(new Assertion(assertionType));
093: }*/
094: else {
095: setAny(rdstEle);
096: containedToken = new GenericToken((Element) rdstEle
097: .getValue());
098: }
099: } else {
100: setToken(new GenericToken((Element) rdst));
101: }
102: }
103:
104: public RequestedSecurityTokenImpl(Token token) {
105: setToken(token);
106: }
107:
108: /**
109: * Constructs a <code>RequestedSecurityToken</code> element from
110: * an existing XML block.
111: *
112: * @param requestedSecurityTokenElement A
113: * <code>org.w3c.dom.Element</code> representing DOM tree
114: * for <code>RequestedSecurityToken</code> object.
115: * @exception WSTrustException if it could not process the
116: * <code>org.w3c.dom.Element</code> properly, implying that
117: * there is an error in the sender or in the element definition.
118: */
119: public static RequestedSecurityTokenType fromElement(
120: org.w3c.dom.Element element) throws WSTrustException {
121: try {
122: JAXBContext jc = WSTrustElementFactory.getContext();
123: javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
124: return (RequestedSecurityTokenType) (((JAXBElement<RequestedSecurityTokenType>) u
125: .unmarshal(element)).getValue());
126: } catch (Exception ex) {
127: throw new WSTrustException(ex.getMessage(), ex);
128: }
129: }
130:
131: /*
132: * Return the security token contained in the RequestedSecurityToken.
133: */
134: public Token getToken() {
135: return containedToken;
136: }
137:
138: public void setToken(Token token) {
139: if (token != null) {
140: String tokenType = token.getType();
141: if (WSSCConstants.SECURITY_CONTEXT_TOKEN.equals(tokenType)) {
142: JAXBElement<SecurityContextTokenType> sctElement = (new com.sun.xml.ws.security.secconv.impl.wssx.bindings.ObjectFactory())
143: .createSecurityContextToken((SecurityContextTokenType) token);
144: setAny(sctElement);
145: } else {
146: Element element = (Element) token.getTokenValue();
147: setAny(element);
148: }
149: }
150: containedToken = token;
151: }
152: }
|