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: package com.sun.xml.wss;
024:
025: import java.io.InputStream;
026: import javax.security.auth.callback.CallbackHandler;
027:
028: /**
029: *<code>XWSSProcessorFactory</code> is a factory for creating XWSSProcessor
030: * Objects.
031: * An XWSSProcessor Object can be used for
032: *<UL>
033: * <LI> Securing an outbound <code>SOAPMessage</Code>
034: * <LI> Verifying the security in an inbound <code>SOAPMessage</code>
035: *</UL>
036: */
037: public abstract class XWSSProcessorFactory {
038:
039: public static final String XWSS_PROCESSOR_FACTORY_PROPERTY = "com.sun.xml.wss.XWSSProcessorFactory";
040:
041: public static final String DEFAULT_XWSS_PROCESSOR_FACTORY = "com.sun.xml.wss.impl.misc.XWSSProcessorFactory2_0Impl";
042:
043: /**
044: * Creates a new instance of <code>XWSSProcessorFactory</code>
045: *
046: * @return a new instance of <code>XWSSProcessorFactory</code>
047: *
048: * @exception XWSSecurityException if there was an error in creating the
049: * the <code>XWSSProcessorFactory</code>
050: */
051: public static XWSSProcessorFactory newInstance()
052: throws XWSSecurityException {
053:
054: ClassLoader classLoader;
055: try {
056: classLoader = Thread.currentThread()
057: .getContextClassLoader();
058: } catch (Exception x) {
059: throw new XWSSecurityException(x.toString(), x);
060: }
061:
062: // Use the system property first
063: try {
064: String systemProp = System
065: .getProperty(XWSS_PROCESSOR_FACTORY_PROPERTY);
066: if (systemProp != null) {
067: return (XWSSProcessorFactory) newInstance(systemProp,
068: classLoader);
069: } else {
070: return (XWSSProcessorFactory) newInstance(
071: DEFAULT_XWSS_PROCESSOR_FACTORY, classLoader);
072: }
073: } catch (SecurityException se) {
074: throw new XWSSecurityException(se.toString(), se);
075: }
076: }
077:
078: /**
079: * Creates a new instance of <code>XWSSProcessor</code>
080: *
081: * @param securityConfiguration an <code>InputStream</code>
082: * for the <code>SecurityConfiguration</code> XML to be used
083: * by the <code>XWSSProcessor</code>
084: *
085: * @param handler a JAAS <code>CallbackHandler</code> to be used by
086: * the <code>XWSSProcessor</code> for Key and other Security
087: * information retrieval
088: *
089: * @return a new instance of <code>XWSSProcessor</code>
090: *
091: * @exception XWSSecurityException if there was an error in creating the
092: * the <code>XWSSProcessor</code>
093: */
094: public abstract XWSSProcessor createProcessorForSecurityConfiguration(
095: InputStream securityConfiguration, CallbackHandler handler)
096: throws XWSSecurityException;
097:
098: /**
099: * Creates a new instance of <code>XWSSProcessor</code>
100: *
101: * @param securityConfiguration an <code>InputStream</code>
102: * for the <code>JAXRPCSecurityConfiguration</code> XML to be used
103: * by the <code>XWSSProcessor</code>
104: *
105: * @return a new instance of <code>XWSSProcessor</code>
106: *
107: * @exception XWSSecurityException if there was an error in creating the
108: * the <code>XWSSProcessor</code>
109: public abstract XWSSProcessor createForApplicationSecurityConfiguration(
110: InputStream securityConfiguration) throws XWSSecurityException;
111: */
112:
113: private static Object newInstance(String className,
114: ClassLoader classLoader) throws XWSSecurityException {
115: try {
116: Class spiClass;
117: if (classLoader == null) {
118: spiClass = Class.forName(className);
119: } else {
120: spiClass = classLoader.loadClass(className);
121: }
122: return spiClass.newInstance();
123: } catch (ClassNotFoundException x) {
124: throw new XWSSecurityException("Processor Factory "
125: + className + " not found", x);
126: } catch (Exception x) {
127: throw new XWSSecurityException("Processor Factory "
128: + className + " could not be instantiated: " + x, x);
129: }
130: }
131:
132: }
|