[java-opensaml COMMIT] in /trunk: opensaml-security-api/src/test/java/org/opensaml/security/BouncyCastleTestLoader.ja...

noreply at shibboleth.net noreply at shibboleth.net
Thu Sep 25 17:36:05 EDT 2014


Author: putmanb
Date: Thu Sep 25 17:36:05 2014
New Revision: 4071

URL: http://svn.shibboleth.net/view/java-opensaml?rev=4071&view=rev
Log:
Recast recent BouncyCastle test loader into a more general security provider support class.

Added:
    trunk/opensaml-security-api/src/test/java/org/opensaml/security/SecurityProviderTestSupport.java
      - copied, changed from r4070, trunk/opensaml-security-api/src/test/java/org/opensaml/security/BouncyCastleTestLoader.java
Modified:
    trunk/opensaml-security-api/src/test/java/org/opensaml/security/BouncyCastleTestLoader.java
    trunk/opensaml-xmlsec-api/pom.xml
    trunk/opensaml-xmlsec-api/src/test/java/org/opensaml/xmlsec/algorithm/AlgorithmRegistryTest.java
    trunk/opensaml-xmlsec-impl/src/test/java/org/opensaml/xmlsec/encryption/support/SimpleDecryptionTest.java
    trunk/opensaml-xmlsec-impl/src/test/java/org/opensaml/xmlsec/encryption/support/SimpleEncryptionTest.java
    trunk/opensaml-xmlsec-impl/src/test/java/org/opensaml/xmlsec/impl/AlgorithmRuntimeSupportedPredicateTest.java

Copied: trunk/opensaml-security-api/src/test/java/org/opensaml/security/SecurityProviderTestSupport.java (from r4070, trunk/opensaml-security-api/src/test/java/org/opensaml/security/BouncyCastleTestLoader.java)
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-security-api/src/test/java/org/opensaml/security/SecurityProviderTestSupport.java?p2=trunk/opensaml-security-api/src/test/java/org/opensaml/security/SecurityProviderTestSupport.java&p1=trunk/opensaml-security-api/src/test/java/org/opensaml/security/BouncyCastleTestLoader.java&r1=4070&r2=4071&rev=4071&view=diff
==============================================================================
--- trunk/opensaml-security-api/src/test/java/org/opensaml/security/BouncyCastleTestLoader.java (original)
+++ trunk/opensaml-security-api/src/test/java/org/opensaml/security/SecurityProviderTestSupport.java Thu Sep 25 17:36:05 2014
@@ -22,35 +22,85 @@
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 
 /**
- * Testing utility class whose purpose is to check and load the Bouncy Castle security provider for tests which require
+ * Testing utility class which providers various support functionality related to security providers and Java version, 
+ * useful for testing cryptographic components. 
+ * 
+ * <p>
+ * One major feature is the ability to check and load the Bouncy Castle security provider for tests which require
  * advanced crypto capabilities, and unload it afterwards, if it wasn't loaded originally.  The goal of this is to preserve
  * the pre-test condition of whether BC was originally loaded or not, so we don't muck with the environment of JVM in which
  * the tests are running.  For example, the JVM may actually have been configured with BC deliberately, 
  * so we don't want to unload it by mistake.
+ * </p>
  */
-public class BouncyCastleTestLoader {
+public class SecurityProviderTestSupport {
     
-    private static final String PROVIDER_NAME = "BC";
+    public static final String BC_PROVIDER_NAME = "BC";
+    
+    public static final String SUNEC_PROVIDER_NAME = "SunEC";
     
     private boolean hadBCOriginally;
     
-    public BouncyCastleTestLoader() {
-        hadBCOriginally = (Security.getProvider(PROVIDER_NAME) != null);
+    public SecurityProviderTestSupport() {
+        hadBCOriginally = (Security.getProvider(BC_PROVIDER_NAME) != null);
     }
     
-    public void load() {
+    /**
+     *  Conditionally load the Bouncy Castle provider, if it isn't already loaded.
+     */
+    public void loadBC() {
         // Only load if isn't already loaded
-        boolean haveBCNow = (Security.getProvider(PROVIDER_NAME) != null);
-        if (!haveBCNow) {
+        if (!haveBC()) {
             Security.addProvider(new BouncyCastleProvider());
         }
     }
     
-    public void unload() {
+    /**
+     *  Conditionally unload the Bouncy Castle provider, if it wasn't loaded originally (outside of this class),
+     *  and if it is currently loaded.
+     */
+    public void unloadBC() {
         // Only unload if wasn't loaded originally
-        if (!hadBCOriginally) {
-            Security.removeProvider("BC");
+        if (!hadBCOriginally && haveBC()) {
+            Security.removeProvider(BC_PROVIDER_NAME);
         }
+    }
+    
+    /**
+     * Return whether the Bouncy Castle provider is currently available.
+     * 
+     * @return true or false
+     */
+    public boolean haveBC() {
+        return Security.getProvider(BC_PROVIDER_NAME) != null; 
+    }
+    
+    /**
+     * Return whether the SunEC provider is currently available.
+     * 
+     * @return true or false
+     */
+    public boolean haveSunEC() {
+        return Security.getProvider(SUNEC_PROVIDER_NAME) != null; 
+    }
+    
+    /**
+     * Return whether the current Java major version (e.g. 6, 7, 8) is greater than or equal to the specified version.
+     * 
+     * @param requiredVersion
+     * @return true if greater or equal, false otherwise
+     */

[... 386 lines stripped ...]


More information about the commits mailing list