001: /*
002: * $Id: BinarySecretImpl.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 javax.xml.namespace.QName;
036:
037: import javax.xml.bind.annotation.XmlAccessType;
038: import javax.xml.bind.annotation.XmlRootElement;
039: import javax.xml.bind.annotation.XmlType;
040: import javax.xml.bind.annotation.XmlAttribute;
041: import javax.xml.bind.annotation.XmlAccessorType;
042:
043: import com.sun.xml.ws.api.security.trust.WSTrustException;
044:
045: import com.sun.xml.ws.security.trust.impl.wssx.bindings.BinarySecretType;
046:
047: import com.sun.xml.ws.security.trust.elements.BinarySecret;
048:
049: import com.sun.org.apache.xml.internal.security.utils.Base64;
050: import com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException;
051:
052: /**
053: *
054: * @author WS-Trust Implementation Team
055: */
056: public class BinarySecretImpl extends BinarySecretType implements
057: BinarySecret {
058:
059: public BinarySecretImpl(byte[] rawValue, String type) {
060: setRawValue(rawValue);
061: setType(type);
062:
063: }
064:
065: public BinarySecretImpl(BinarySecretType bsType) {
066: this (bsType.getValue(), bsType.getType());
067:
068: }
069:
070: /**
071: * Constructs a <code>BinarySecret</code> element from
072: * an existing XML block.
073: *
074: * @param lifetimeElement A
075: * <code>org.w3c.dom.Element</code> representing DOM tree
076: * for <code>BinarySecret</code> object.
077: * @exception WSTrustException if it could not process the
078: * <code>org.w3c.dom.Element</code> properly, implying that
079: * there is an error in the sender or in the element definition.
080: */
081: public static BinarySecretType fromElement(
082: org.w3c.dom.Element element) throws WSTrustException {
083: try {
084: JAXBContext jc = JAXBContext
085: .newInstance("com.sun.xml.ws.security.trust.impl.bindings");
086: javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
087: return (BinarySecretType) ((JAXBElement) u
088: .unmarshal(element)).getValue();
089: } catch (Exception ex) {
090: throw new WSTrustException(ex.getMessage(), ex);
091: }
092: }
093:
094: public byte[] getRawValue() {
095: return super .getValue();
096: }
097:
098: public String getTextValue() {
099: return Base64.encode(getRawValue());
100: }
101:
102: public void setRawValue(byte[] rawText) {
103: setValue(rawText);
104: }
105:
106: public void setTextValue(String encodedText) {
107: try {
108: setValue(Base64.decode(encodedText));
109: } catch (Base64DecodingException de) {
110: throw new RuntimeException("Error while decoding "
111: + de.getMessage());
112: }
113: }
114:
115: /* public void setType(String type) {
116: if (!(this.ASYMMETRIC_KEY_TYPE.equalsIgnoreCase(type)
117: || this.NONCE_KEY_TYPE.equalsIgnoreCase(type)
118: || this.SYMMETRIC_KEY_TYPE.equalsIgnoreCase(type))) {
119: throw new RuntimeException("Invalid BinarySecret Type: " + type);
120: }
121:
122: setType(type);
123:
124: }
125:
126: public String getType(){
127: return this.type;
128: }
129: */
130:
131: }
|