All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.xml.ws.security.trust.impl.wssx.elements.BinarySecretImpl Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0, which is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

/*
 * $Id: BinarySecretImpl.java,v 1.2 2010-10-21 15:37:04 snajper Exp $
 */

package com.sun.xml.ws.security.trust.impl.wssx.elements;

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;

import com.sun.xml.ws.api.security.trust.WSTrustException;

import com.sun.xml.ws.security.trust.impl.wssx.bindings.BinarySecretType;

import com.sun.xml.ws.security.trust.elements.BinarySecret;

import java.util.Base64;

/**
 *
 * @author WS-Trust Implementation Team
 */
public class BinarySecretImpl extends BinarySecretType implements BinarySecret {

   public BinarySecretImpl(byte[] rawValue, String type) {
        setRawValue(rawValue);
        setType(type);

    }

    public BinarySecretImpl(BinarySecretType bsType){
        this(bsType.getValue(), bsType.getType());

    }

    /**
     * Constructs a BinarySecret element from
     * an existing XML block.
     *
     * @param element
     *        org.w3c.dom.Element representing DOM tree
     *        for BinarySecret object.
     * @exception WSTrustException if it could not process the
     *            org.w3c.dom.Element properly, implying that
     *            there is an error in the sender or in the element definition.
     */
    public static BinarySecretType fromElement(org.w3c.dom.Element element)
        throws WSTrustException {
        try {
            JAXBContext jc =
                JAXBContext.newInstance("com.sun.xml.ws.security.trust.impl.bindings");
            jakarta.xml.bind.Unmarshaller u = jc.createUnmarshaller();
            return (BinarySecretType)((JAXBElement)u.unmarshal(element)).getValue();
        } catch (Exception ex) {
            throw new WSTrustException(ex.getMessage(), ex);
        }
    }

     @Override
     public byte[] getRawValue() {
        return super.getValue();
     }


     @Override
     public String getTextValue() {
        return Base64.getMimeEncoder().encodeToString(getRawValue());
     }

     @Override
     public void setRawValue(byte[] rawText) {
        setValue(rawText);
     }

     @Override
     public void setTextValue(String encodedText) {
         try {
             setValue(Base64.getMimeDecoder().decode(encodedText));
         } catch (IllegalArgumentException de) {
             throw new RuntimeException("Error while decoding " +
                                        de.getMessage());
         }
     }

 /*    public void setType(String type) {
        if (!(this.ASYMMETRIC_KEY_TYPE.equalsIgnoreCase(type)
              || this.NONCE_KEY_TYPE.equalsIgnoreCase(type)
              || this.SYMMETRIC_KEY_TYPE.equalsIgnoreCase(type))) {
            throw new RuntimeException("Invalid BinarySecret Type: " + type);
        }

        setType(type);

     }

     public String getType(){
         return this.type;
     }
     */

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy