ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1806440 - in /webservices/wss4j/branches/2_1_x-fixes: ws-security-common/src/main/java/org/apache/wss4j/common/crypto/ ws-security-dom/src/main/java/org/apache/wss4j/dom/engine/ ws-security-dom/src/test/java/org/apache/wss4j/dom/components...
Date Mon, 28 Aug 2017 12:24:54 GMT
Author: coheigea
Date: Mon Aug 28 12:24:53 2017
New Revision: 1806440

URL: http://svn.apache.org/viewvc?rev=1806440&view=rev
Log:
WSS-614 - Add cleanUp methods to WSSConfig + WSProviderConfig to remove security providers.

Added:
    webservices/wss4j/branches/2_1_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/components/crypto/WSSConfigTest.java
Modified:
    webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSProviderConfig.java
    webservices/wss4j/branches/2_1_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/engine/WSSConfig.java

Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSProviderConfig.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSProviderConfig.java?rev=1806440&r1=1806439&r2=1806440&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSProviderConfig.java
(original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSProviderConfig.java
Mon Aug 28 12:24:53 2017
@@ -53,7 +53,11 @@ public final class WSProviderConfig {
      * initialized.  This flag prevents repeated and unnecessary calls
      * to static initialization code at construction time.
      */
-    private static boolean staticallyInitialized = false;
+    private static boolean staticallyInitialized;
+
+    private static boolean santuarioProviderAdded;
+    private static boolean bcProviderAdded;
+    private static boolean tlProviderAdded;
 
     private WSProviderConfig() {
         // complete
@@ -80,6 +84,10 @@ public final class WSProviderConfig {
                         return true;
                     }
                 });
+
+                santuarioProviderAdded = true;
+                bcProviderAdded = false;
+                tlProviderAdded = false;
             }
             staticallyInitialized = true;
         }
@@ -89,6 +97,7 @@ public final class WSProviderConfig {
         if (!staticallyInitialized) {
             initializeResourceBundles();
             setXmlSecIgnoreLineBreak();
+            santuarioProviderAdded = addXMLDSigRIInternalProv;
             if (addXMLDSigRIInternalProv) {
                 AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
                     public Boolean run() {
@@ -97,6 +106,8 @@ public final class WSProviderConfig {
                     }
                 });
             }
+
+            bcProviderAdded = addBCProv;
             if (addBCProv) {
                 AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
                     public Boolean run() {
@@ -114,6 +125,8 @@ public final class WSProviderConfig {
                     }
                 });
             }
+
+            tlProviderAdded = addTLProv;
             if (addTLProv) {
                 AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
                     public Boolean run() {
@@ -126,6 +139,25 @@ public final class WSProviderConfig {
         }
     }
 
+    public static synchronized void cleanUp() {
+        if (staticallyInitialized) {
+            if (santuarioProviderAdded) {
+                Security.removeProvider("ApacheXMLDSig");
+                santuarioProviderAdded = false;
+            }
+            if (bcProviderAdded) {
+                Security.removeProvider("BC");
+                bcProviderAdded = false;
+            }
+            if (tlProviderAdded) {
+                Security.removeProvider("TLSP");
+                tlProviderAdded = false;
+            }
+
+            staticallyInitialized = false;
+        }
+    }
+
     /**
      * Set the value of the internal addJceProviders flag.  This flag
      * turns on (or off) automatic registration of known JCE providers

Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/engine/WSSConfig.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/engine/WSSConfig.java?rev=1806440&r1=1806439&r2=1806440&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/engine/WSSConfig.java
(original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/engine/WSSConfig.java
Mon Aug 28 12:24:53 2017
@@ -358,6 +358,19 @@ public final class WSSConfig {
         }
     }
 
+    public static synchronized void cleanUp() {
+        if (staticallyInitialized) {
+            if (addJceProviders) {
+                Security.removeProvider("STRTransform");
+                Security.removeProvider("AttachmentContentSignatureTransform");
+                Security.removeProvider("AttachmentCompleteSignatureTransform");
+            }
+            WSProviderConfig.cleanUp();
+
+            staticallyInitialized = false;
+        }
+    }
+
     /**
      * @return a new WSSConfig instance configured with the default values
      */

Added: webservices/wss4j/branches/2_1_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/components/crypto/WSSConfigTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/components/crypto/WSSConfigTest.java?rev=1806440&view=auto
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/components/crypto/WSSConfigTest.java
(added)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-dom/src/test/java/org/apache/wss4j/dom/components/crypto/WSSConfigTest.java
Mon Aug 28 12:24:53 2017
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wss4j.dom.components.crypto;
+
+import java.security.Security;
+
+import org.apache.wss4j.common.crypto.WSProviderConfig;
+import org.apache.wss4j.dom.engine.WSSConfig;
+import org.junit.Test;
+
+/**
+ * Test loading and removing security providers via WSSConfig
+ */
+public class WSSConfigTest extends org.junit.Assert {
+
+    @Test
+    public void testWSSConfig() {
+        WSSConfig.cleanUp();
+        WSSConfig.init();
+
+        // Check providers
+        assertTrue(Security.getProvider("STRTransform") != null);
+        assertTrue(Security.getProvider("AttachmentContentSignatureTransform") != null);
+        assertTrue(Security.getProvider("AttachmentCompleteSignatureTransform") != null);
+        assertTrue(Security.getProvider("ApacheXMLDSig") != null);
+
+        WSSConfig.cleanUp();
+
+        assertTrue(Security.getProvider("STRTransform") == null);
+        assertTrue(Security.getProvider("AttachmentContentSignatureTransform") == null);
+        assertTrue(Security.getProvider("AttachmentCompleteSignatureTransform") == null);
+        assertTrue(Security.getProvider("ApacheXMLDSig") == null);
+
+    }
+
+    @Test
+    public void testWSProviderConfig() {
+        WSProviderConfig.cleanUp();
+        WSProviderConfig.init();
+
+        // Check providers
+        assertTrue(Security.getProvider("ApacheXMLDSig") != null);
+
+        WSProviderConfig.cleanUp();
+
+        assertTrue(Security.getProvider("ApacheXMLDSig") == null);
+
+        WSProviderConfig.init(true, true, true);
+        assertTrue(Security.getProvider("ApacheXMLDSig") != null);
+        assertTrue(Security.getProvider("BC") != null);
+        assertTrue(Security.getProvider("TLSP") != null);
+
+        WSProviderConfig.cleanUp();
+
+        assertTrue(Security.getProvider("ApacheXMLDSig") == null);
+        assertTrue(Security.getProvider("BC") == null);
+        assertTrue(Security.getProvider("TLSP") == null);
+
+    }
+
+}



Mime
View raw message