ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1051881 - in /webservices/wss4j/trunk: pom.xml src/main/java/org/apache/ws/security/WSSConfig.java src/test/java/org/apache/ws/security/handler/CustomActionProcessorTest.java
Date Wed, 22 Dec 2010 13:06:02 GMT
Author: coheigea
Date: Wed Dec 22 13:06:02 2010
New Revision: 1051881

URL: http://svn.apache.org/viewvc?rev=1051881&view=rev
Log:
[WSS-232] - Changed default Action and Processors to be stored as Class instances instead
of Strings
 - This avoids having to load the classes each time they're loaded.

Modified:
    webservices/wss4j/trunk/pom.xml
    webservices/wss4j/trunk/src/main/java/org/apache/ws/security/WSSConfig.java
    webservices/wss4j/trunk/src/test/java/org/apache/ws/security/handler/CustomActionProcessorTest.java

Modified: webservices/wss4j/trunk/pom.xml
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/pom.xml?rev=1051881&r1=1051880&r2=1051881&view=diff
==============================================================================
--- webservices/wss4j/trunk/pom.xml (original)
+++ webservices/wss4j/trunk/pom.xml Wed Dec 22 13:06:02 2010
@@ -370,6 +370,12 @@
             <scope>compile</scope>
         </dependency>
         <dependency>
+            <groupId>org.opensaml</groupId>
+            <artifactId>opensaml</artifactId>
+            <version>${opensaml.version}</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>${junit.version}</version>
@@ -394,12 +400,6 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.opensaml</groupId>
-            <artifactId>opensaml</artifactId>
-            <version>${opensaml.version}</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>commons-codec</groupId>
             <artifactId>commons-codec</artifactId>
             <version>1.3</version>

Modified: webservices/wss4j/trunk/src/main/java/org/apache/ws/security/WSSConfig.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/main/java/org/apache/ws/security/WSSConfig.java?rev=1051881&r1=1051880&r2=1051881&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/main/java/org/apache/ws/security/WSSConfig.java (original)
+++ webservices/wss4j/trunk/src/main/java/org/apache/ws/security/WSSConfig.java Wed Dec 22
13:06:02 2010
@@ -53,46 +53,41 @@ public class WSSConfig {
     /**
      * The default collection of actions supported by the toolkit.
      */
-    private static final Map<Integer, String> DEFAULT_ACTIONS;
+    private static final Map<Integer, Class<?>> DEFAULT_ACTIONS;
     static {
-        final Map<Integer, String> tmp = new HashMap<Integer, String>();
+        final Map<Integer, Class<?>> tmp = new HashMap<Integer, Class<?>>();
         try {
             tmp.put(
                 new Integer(WSConstants.UT),
-                org.apache.ws.security.action.UsernameTokenAction.class.getName()
+                org.apache.ws.security.action.UsernameTokenAction.class
             );
             tmp.put(
                 new Integer(WSConstants.ENCR),
-                org.apache.ws.security.action.EncryptionAction.class.getName()
+                org.apache.ws.security.action.EncryptionAction.class
             );
             tmp.put(
                 new Integer(WSConstants.SIGN),
-                org.apache.ws.security.action.SignatureAction.class.getName()
+                org.apache.ws.security.action.SignatureAction.class
             );
-            //
-            // Note that all actions/processors with dependencies on opensaml are
-            // registered as Strings. This is so that applications that do not use
-            // saml do not have to have the opensaml jar available.
-            //
             tmp.put(
                 new Integer(WSConstants.ST_SIGNED),
-                "org.apache.ws.security.action.SAMLTokenSignedAction"
+                org.apache.ws.security.action.SAMLTokenSignedAction.class
             );
             tmp.put(
                 new Integer(WSConstants.ST_UNSIGNED),
-                "org.apache.ws.security.action.SAMLTokenUnsignedAction"
+                org.apache.ws.security.action.SAMLTokenUnsignedAction.class
             );
             tmp.put(
                 new Integer(WSConstants.TS),
-                org.apache.ws.security.action.TimestampAction.class.getName()
+                org.apache.ws.security.action.TimestampAction.class
             );
             tmp.put(
                 new Integer(WSConstants.UT_SIGN),
-                org.apache.ws.security.action.UsernameTokenSignedAction.class.getName()
+                org.apache.ws.security.action.UsernameTokenSignedAction.class
             );
             tmp.put(
                 new Integer(WSConstants.SC),
-                org.apache.ws.security.action.SignatureConfirmationAction.class.getName()
+                org.apache.ws.security.action.SignatureConfirmationAction.class
             );
         } catch (final Throwable t) {
             if (log.isDebugEnabled()) {
@@ -105,41 +100,41 @@ public class WSSConfig {
     /**
      * The default collection of processors supported by the toolkit
      */
-    private static final Map<QName, String> DEFAULT_PROCESSORS;
+    private static final Map<QName, Class<?>> DEFAULT_PROCESSORS;
     static {
-        final Map<QName, String> tmp = new HashMap<QName, String>();
+        final Map<QName, Class<?>> tmp = new HashMap<QName, Class<?>>();
         try {
             tmp.put(
                 WSSecurityEngine.SAML_TOKEN,
-                "org.apache.ws.security.processor.SAMLTokenProcessor"
+                org.apache.ws.security.processor.SAMLTokenProcessor.class
             );
             tmp.put(
                 WSSecurityEngine.ENCRYPTED_KEY,
-                org.apache.ws.security.processor.EncryptedKeyProcessor.class.getName()
+                org.apache.ws.security.processor.EncryptedKeyProcessor.class
             );
             tmp.put(
                 WSSecurityEngine.SIGNATURE,
-                org.apache.ws.security.processor.SignatureProcessor.class.getName()
+                org.apache.ws.security.processor.SignatureProcessor.class
             );
             tmp.put(
                 WSSecurityEngine.TIMESTAMP,
-                org.apache.ws.security.processor.TimestampProcessor.class.getName()
+                org.apache.ws.security.processor.TimestampProcessor.class
             );
             tmp.put(
                 WSSecurityEngine.USERNAME_TOKEN,
-                org.apache.ws.security.processor.UsernameTokenProcessor.class.getName()
+                org.apache.ws.security.processor.UsernameTokenProcessor.class
             );
             tmp.put(
                 WSSecurityEngine.REFERENCE_LIST,
-                org.apache.ws.security.processor.ReferenceListProcessor.class.getName()
+                org.apache.ws.security.processor.ReferenceListProcessor.class
             );
             tmp.put(
                 WSSecurityEngine.SIGNATURE_CONFIRMATION,
-                org.apache.ws.security.processor.SignatureConfirmationProcessor.class.getName()
+                org.apache.ws.security.processor.SignatureConfirmationProcessor.class
             );
             tmp.put(
                 WSSecurityEngine.DERIVED_KEY_TOKEN_05_02,
-                org.apache.ws.security.processor.DerivedKeyTokenProcessor.class.getName()
+                org.apache.ws.security.processor.DerivedKeyTokenProcessor.class
             );
             tmp.put(
                 WSSecurityEngine.DERIVED_KEY_TOKEN_05_12,
@@ -147,7 +142,7 @@ public class WSSConfig {
             );
             tmp.put(
                 WSSecurityEngine.SECURITY_CONTEXT_TOKEN_05_02,
-                org.apache.ws.security.processor.SecurityContextTokenProcessor.class.getName()
+                org.apache.ws.security.processor.SecurityContextTokenProcessor.class
             );
             tmp.put(
                 WSSecurityEngine.SECURITY_CONTEXT_TOKEN_05_12,
@@ -155,11 +150,11 @@ public class WSSConfig {
             );
             tmp.put(
                 WSSecurityEngine.BINARY_TOKEN,
-                org.apache.ws.security.processor.BinarySecurityTokenProcessor.class.getName()
+                org.apache.ws.security.processor.BinarySecurityTokenProcessor.class
             );
             tmp.put(
                 WSSecurityEngine.ENCRYPTED_DATA,
-                org.apache.ws.security.processor.EncryptedDataProcessor.class.getName()
+                org.apache.ws.security.processor.EncryptedDataProcessor.class
             );
         } catch (final Throwable t) {
             if (log.isDebugEnabled()) {
@@ -264,18 +259,22 @@ public class WSSConfig {
     protected Map<String, String> jceProvider = new HashMap<String, String>();
 
     /**
-     * The known actions. This map is of the form <Integer, String> or <Integer,
Action>. 
+     * The known actions. This map is of the form <Integer, Class<?>> or 
+     * <Integer, Action>. 
      * The known actions are initialized from a set of defaults,
      * but the list may be modified via the setAction operations.
      */
-    private final Map actionMap = new HashMap(DEFAULT_ACTIONS);
+    private final Map<Integer, Object> actionMap = 
+        new HashMap<Integer, Object>(DEFAULT_ACTIONS);
 
     /**
-     * The known processors. This map is of the form <String, String> or <String,Processor>.
+     * The known processors. This map is of the form <QName, Class<?>> or
+     * <QName, Processor>.
      * The known processors are initialized from a set of defaults,
      * but the list may be modified via the setProcessor operations.
      */
-    private final Map processorMap = new HashMap(DEFAULT_PROCESSORS);
+    private final Map<QName, Object> processorMap = 
+        new HashMap<QName, Object>(DEFAULT_PROCESSORS);
     
     /**
      * a static boolean flag that determines whether default JCE providers
@@ -498,19 +497,22 @@ public class WSSConfig {
     public void setIdAllocator(WsuIdAllocator idAllocator) {
         this.idAllocator = idAllocator;
     }
-
+    
     /**
-     * Associate an action name with a specific action code.
+     * Associate an action instance with a specific action code.
      *
      * This operation allows applications to supply their own
      * actions for well-known operations.
+     * 
+     * Please note that the Action object does NOT get class-loaded per invocation, and so
+     * it is up to the implementing class to ensure that it is thread-safe.
      */
-    public String setAction(int code, String action) {
-        Object previousAction = actionMap.put(new Integer(code), action);
-        if (previousAction instanceof String) {
-            return (String)previousAction;
-        } else if (previousAction instanceof Action){
-            return previousAction.getClass().getName();
+    public Class<?> setAction(int code, Action action) {
+        Object result = actionMap.put(new Integer(code), action);
+        if (result instanceof Class<?>) {
+            return (Class<?>)result;
+        } else if (result instanceof Action) {
+            return result.getClass();
         }
         return null;
     }
@@ -521,12 +523,12 @@ public class WSSConfig {
      * This operation allows applications to supply their own
      * actions for well-known operations.
      */
-    public String setAction(int code, Action action) {
-        Object previousAction = actionMap.put(new Integer(code), action);
-        if (previousAction instanceof String) {
-            return (String)previousAction;
-        } else if (previousAction instanceof Action){
-            return previousAction.getClass().getName();
+    public Class<?> setAction(int code, Class<?> clazz) {
+        Object result = actionMap.put(new Integer(code), clazz);
+        if (result instanceof Class<?>) {
+            return (Class<?>)result;
+        } else if (result instanceof Action) {
+            return result.getClass();
         }
         return null;
     }
@@ -539,23 +541,21 @@ public class WSSConfig {
      * @throws WSSecurityException
      */
     public Action getAction(int action) throws WSSecurityException {
-        Integer key = new Integer(action);
-        final Object actionObject = actionMap.get(key);
+        final Object actionObject = actionMap.get(new Integer(action));
         
-        if (actionObject instanceof String) {
-            final String name = (String)actionObject;
+        if (actionObject instanceof Class<?>) {
             try {
-                return (Action) Loader.loadClass(name).newInstance();
+                return (Action)((Class<?>)actionObject).newInstance();
             } catch (Throwable t) {
                 if (log.isDebugEnabled()) {
                     log.debug(t.getMessage(), t);
                 }
                 throw new WSSecurityException(WSSecurityException.FAILURE,
-                        "unableToLoadClass", new Object[] { name }, t);
+                        "unableToLoadClass", new Object[] { ((Class<?>)actionObject).getName()
}, t);
             }
         } else if (actionObject instanceof Action) {
             return (Action)actionObject;
-        } 
+        }
         return null;
     }
     
@@ -563,32 +563,35 @@ public class WSSConfig {
      * Associate a SOAP processor name with a specified SOAP Security header
      * element QName.  Processors registered under this QName will be
      * called when processing header elements with the specified type.
+     * 
+     * Please note that the Processor object does NOT get class-loaded per invocation, and
so
+     * it is up to the implementing class to ensure that it is thread-safe.
      */
-    public String setProcessor(QName el, String name) {
-        Object previousProcessor = processorMap.put(el, name);
-        if (previousProcessor instanceof String) {
-            return (String)previousProcessor;
-        } else if (previousProcessor instanceof Processor){
-            return previousProcessor.getClass().getName();
+    public Class<?> setProcessor(QName el, Processor processor) {
+        Object result = processorMap.put(el, processor);
+        if (result instanceof Class<?>) {
+            return (Class<?>)result;
+        } else if (result instanceof Processor) {
+            return result.getClass();
         }
         return null;
     }
     
     /**
-     * Associate a SOAP processor instance with a specified SOAP Security header
+     * Associate a SOAP processor name with a specified SOAP Security header
      * element QName.  Processors registered under this QName will be
      * called when processing header elements with the specified type.
      */
-    public String setProcessor(QName el, Processor processor) {
-        Object previousProcessor = processorMap.put(el, processor);
-        if (previousProcessor instanceof String) {
-            return (String)previousProcessor;
-        } else if (previousProcessor instanceof Processor){
-            return previousProcessor.getClass().getName();
+    public Class<?> setProcessor(QName el, Class<?> clazz) {
+        Object result = processorMap.put(el, clazz);
+        if (result instanceof Class<?>) {
+            return (Class<?>)result;
+        } else if (result instanceof Processor) {
+            return result.getClass();
         }
         return null;
     }
-
+    
     /**
      * @return      the SOAP processor associated with the specified
      *              QName.  The QName is intended to refer to an element
@@ -598,20 +601,20 @@ public class WSSConfig {
      */
     public Processor getProcessor(QName el) throws WSSecurityException {
         final Object processorObject = processorMap.get(el);
-        if (processorObject instanceof String) {
-            final String name = (String)processorObject;
+        
+        if (processorObject instanceof Class<?>) {
             try {
-                return (Processor) Loader.loadClass(name).newInstance();
+                return (Processor)((Class<?>)processorObject).newInstance();
             } catch (Throwable t) {
                 if (log.isDebugEnabled()) {
                     log.debug(t.getMessage(), t);
                 }
                 throw new WSSecurityException(WSSecurityException.FAILURE,
-                        "unableToLoadClass", new Object[] { name }, t);
+                        "unableToLoadClass", new Object[] { ((Class<?>)processorObject).getName()
}, t);
             }
         } else if (processorObject instanceof Processor) {
             return (Processor)processorObject;
-        } 
+        }
         return null;
     }
 

Modified: webservices/wss4j/trunk/src/test/java/org/apache/ws/security/handler/CustomActionProcessorTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/test/java/org/apache/ws/security/handler/CustomActionProcessorTest.java?rev=1051881&r1=1051880&r2=1051881&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/test/java/org/apache/ws/security/handler/CustomActionProcessorTest.java
(original)
+++ webservices/wss4j/trunk/src/test/java/org/apache/ws/security/handler/CustomActionProcessorTest.java
Wed Dec 22 13:06:02 2010
@@ -80,7 +80,7 @@ public class CustomActionProcessorTest e
         String p = "org.apache.ws.security.common.CustomProcessor";
         cfg.setProcessor(
             WSSecurityEngine.SIGNATURE,
-            p
+            org.apache.ws.security.common.CustomProcessor.class
         );
         final WSSecurityEngine engine = new WSSecurityEngine();
         engine.setWssConfig(cfg);
@@ -127,7 +127,7 @@ public class CustomActionProcessorTest e
         WSSConfig cfg = WSSConfig.getNewInstance();
         cfg.setProcessor(
             WSSecurityEngine.SIGNATURE,
-            new CustomProcessor()
+            CustomProcessor.class
         );
         final WSSecurityEngine engine = new WSSecurityEngine();
         engine.setWssConfig(cfg);
@@ -155,7 +155,7 @@ public class CustomActionProcessorTest e
         
         final WSSConfig cfg = WSSConfig.getNewInstance();
         final int action = 0xDEADF000;
-        cfg.setAction(action, "org.apache.ws.security.common.CustomAction");
+        cfg.setAction(action, org.apache.ws.security.common.CustomAction.class);
         final RequestData reqData = new RequestData();
         reqData.setWssConfig(cfg);
         
@@ -185,7 +185,7 @@ public class CustomActionProcessorTest e
         
         final WSSConfig cfg = WSSConfig.getNewInstance();
         final int action = 0xDEADF000;
-        cfg.setAction(action, new CustomAction());
+        cfg.setAction(action, CustomAction.class);
         final RequestData reqData = new RequestData();
         reqData.setWssConfig(cfg);
         
@@ -257,7 +257,7 @@ public class CustomActionProcessorTest e
         //
         // This parsing should pass as WSSConfig has been configured with the custom action
         //
-        cfg.setAction(customAction, "org.apache.ws.security.common.CustomAction");
+        cfg.setAction(customAction, org.apache.ws.security.common.CustomAction.class);
         int actions = WSSecurityUtil.decodeAction(actionString, actionList, cfg);
         
         final RequestData reqData = new RequestData();



Mime
View raw message