001: /*
002: * $Id: RequestedProofTokenImpl.java,v 1.1 2007/08/23 12:40:56 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.bind.JAXBContext;
032: import javax.xml.bind.JAXBElement;
033: import javax.xml.bind.JAXBException;
034:
035: import com.sun.xml.ws.api.security.trust.WSTrustException;
036:
037: import com.sun.xml.ws.security.trust.elements.str.SecurityTokenReference;
038:
039: import java.net.URI;
040: import java.net.URISyntaxException;
041:
042: import com.sun.xml.ws.security.trust.WSTrustConstants;
043: import com.sun.xml.ws.security.trust.impl.wssx.bindings.ObjectFactory;
044:
045: import com.sun.xml.ws.security.trust.elements.BinarySecret;
046: import com.sun.xml.ws.security.trust.elements.RequestedProofToken;
047: import com.sun.xml.ws.security.trust.impl.wssx.bindings.RequestedProofTokenType;
048: import com.sun.xml.ws.security.trust.impl.wssx.bindings.BinarySecretType;
049:
050: import com.sun.xml.ws.security.secext10.SecurityTokenReferenceType;
051:
052: /**
053: * @author Manveen Kaur
054: */
055: public class RequestedProofTokenImpl extends RequestedProofTokenType
056: implements RequestedProofToken {
057:
058: private String tokenType;
059: private URI computedKey;
060: private BinarySecret secret;
061: private SecurityTokenReference str;
062:
063: public RequestedProofTokenImpl() {
064: // empty constructor
065: }
066:
067: public RequestedProofTokenImpl(String proofTokenType) {
068: setProofTokenType(proofTokenType);
069: }
070:
071: public RequestedProofTokenImpl(RequestedProofTokenType rptType) {
072: JAXBElement obj = (JAXBElement) rptType.getAny();
073: String local = obj.getName().getLocalPart();
074: if (local.equalsIgnoreCase("ComputedKey")) {
075: try {
076: setComputedKey(new URI((String) obj.getValue()));
077: } catch (URISyntaxException ex) {
078: throw new RuntimeException(ex);
079: }
080: } else if (local.equalsIgnoreCase("BinarySecret")) {
081: BinarySecretType bsType = (BinarySecretType) obj.getValue();
082: setBinarySecret(new BinarySecretImpl(bsType));
083: } else {
084: throw new UnsupportedOperationException(
085: "Unsupported requested proof token: " + local);
086: }
087: }
088:
089: public String getProofTokenType() {
090: return tokenType;
091: }
092:
093: public void setProofTokenType(String proofTokenType) {
094: if (!(proofTokenType
095: .equalsIgnoreCase(RequestedProofToken.BINARY_SECRET_TYPE)
096: || proofTokenType
097: .equalsIgnoreCase(RequestedProofToken.COMPUTED_KEY_TYPE)
098: || proofTokenType
099: .equalsIgnoreCase(RequestedProofToken.ENCRYPTED_KEY_TYPE)
100: || proofTokenType
101: .equalsIgnoreCase(RequestedProofToken.CUSTOM_TYPE) || proofTokenType
102: .equalsIgnoreCase(RequestedProofToken.TOKEN_REF_TYPE)))
103: // make this a WSTrustException?
104: throw new RuntimeException("Invalid tokenType");
105: tokenType = proofTokenType;
106: }
107:
108: public void setSecurityTokenReference(
109: SecurityTokenReference reference) {
110: if (reference != null) {
111: str = reference;
112: JAXBElement<SecurityTokenReferenceType> strElement = (new com.sun.xml.ws.security.secext10.ObjectFactory())
113: .createSecurityTokenReference((SecurityTokenReferenceType) reference);
114: setAny(strElement);
115: }
116: setProofTokenType(RequestedProofToken.TOKEN_REF_TYPE);
117: }
118:
119: public SecurityTokenReference getSecurityTokenReference() {
120: return str;
121: }
122:
123: public void setComputedKey(URI computedKey) {
124: if (computedKey != null) {
125: String ckString = computedKey.toString();
126: if (!(ckString.equalsIgnoreCase(WSTrustConstants.CK_HASH) || (ckString
127: .equalsIgnoreCase(WSTrustConstants.CK_PSHA1)))) {
128: throw new RuntimeException("Invalid computedKeyURI");
129: }
130: this .computedKey = computedKey;
131: JAXBElement<String> ckElement = (new ObjectFactory())
132: .createComputedKey(computedKey.toString());
133: setAny(ckElement);
134: }
135: setProofTokenType(RequestedProofToken.COMPUTED_KEY_TYPE);
136: }
137:
138: public URI getComputedKey() {
139: return computedKey;
140: }
141:
142: public void setBinarySecret(BinarySecret secret) {
143: if (secret != null) {
144: this .secret = secret;
145: JAXBElement<BinarySecretType> bsElement = (new ObjectFactory())
146: .createBinarySecret((BinarySecretType) secret);
147: setAny(bsElement);
148: }
149: setProofTokenType(RequestedProofToken.BINARY_SECRET_TYPE);
150: }
151:
152: public BinarySecret getBinarySecret() {
153: return secret;
154: }
155:
156: public static RequestedProofTokenType fromElement(
157: org.w3c.dom.Element element) throws WSTrustException {
158: try {
159: JAXBContext jc = JAXBContext
160: .newInstance("com.sun.xml.ws.security.trust.impl.wssx.elements");
161: javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
162: return (RequestedProofTokenType) u.unmarshal(element);
163: } catch (Exception ex) {
164: throw new WSTrustException(ex.getMessage(), ex);
165: }
166: }
167:
168: }
|