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: /*
024: * SOAPUtil.java
025: *
026: * Created on July 24, 2006, 4:21 PM
027: *
028: * To change this template, choose Tools | Template Manager
029: * and open the template in the editor.
030: */
031:
032: package com.sun.xml.ws.security.opt.impl.util;
033:
034: import com.sun.xml.wss.impl.WssSoapFaultException;
035: import javax.xml.namespace.QName;
036: import com.sun.xml.ws.security.opt.api.keyinfo.BinarySecurityToken;
037: import com.sun.xml.wss.XWSSecurityException;
038: import java.security.cert.X509Certificate;
039: import java.security.cert.CertificateFactory;
040: import java.io.ByteArrayInputStream;
041:
042: /**
043: *
044: * @author ashutosh.shahi@sun.com
045: */
046:
047: public class SOAPUtil {
048:
049: /** Creates a new instance of SOAPUtil */
050: public SOAPUtil() {
051:
052: }
053:
054: public static String getIdFromFragmentRef(String ref) {
055: char start = ref.charAt(0);
056: if (start == '#') {
057: return ref.substring(1);
058: }
059: return ref;
060: }
061:
062: public static X509Certificate getCertificateFromToken(
063: BinarySecurityToken bst) throws XWSSecurityException {
064: X509Certificate cert = null;
065: byte[] data = bst.getTokenValue();
066: try {
067: CertificateFactory certFact = CertificateFactory
068: .getInstance("X.509");
069: cert = (X509Certificate) certFact
070: .generateCertificate(new ByteArrayInputStream(data));
071: } catch (Exception e) {
072: throw new XWSSecurityException(
073: "Unable to create X509Certificate from data");
074: }
075: return cert;
076: }
077:
078: /**
079: * Create and initialize a WssSoapFaultException.
080: */
081:
082: public static WssSoapFaultException newSOAPFaultException(
083: String faultstring, Throwable th) {
084: WssSoapFaultException sfe = new WssSoapFaultException(null,
085: faultstring, null, null);
086: sfe.initCause(th);
087: return sfe;
088: }
089:
090: /**
091: * Create and initialize a WssSoapFaultException.
092: */
093: public static WssSoapFaultException newSOAPFaultException(
094: QName faultCode, String faultstring, Throwable th) {
095:
096: WssSoapFaultException sfe = new WssSoapFaultException(
097: faultCode, faultstring, null, null);
098: sfe.initCause(th);
099: return sfe;
100: }
101: }
|