[java-opensaml COMMIT] in /trunk/opensaml-saml-impl/src: main/java/org/opensaml/saml/config/ESAPIInitializer.java tes...

noreply at shibboleth.net noreply at shibboleth.net
Wed Mar 6 15:41:30 EST 2013


Author: scantor
Date: Wed Mar  6 15:41:30 2013
New Revision: 3249

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3249&view=rev
Log:
OSJ-28: ported java-opensaml2 1590

Modified:
    trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/config/ESAPIInitializer.java
    trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/config/ESAPITest.java

Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/config/ESAPIInitializer.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/config/ESAPIInitializer.java?rev=3249&r1=3248&r2=3249&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/config/ESAPIInitializer.java (original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/config/ESAPIInitializer.java Wed Mar  6 15:41:30 2013
@@ -20,15 +20,35 @@
 import org.opensaml.core.config.InitializationException;
 import org.opensaml.core.config.Initializer;
 import org.owasp.esapi.ESAPI;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * An initializer which initializes the OWASP ESAPI security library.
  */
 public class ESAPIInitializer implements Initializer {
 
+    /** Logger. */
+    private Logger log = LoggerFactory.getLogger(ESAPIInitializer.class);
+    
     /** {@inheritDoc} */
     public void init() throws InitializationException {
-        ESAPI.initialize("org.opensaml.saml.config.ESAPISecurityConfig"); 
+        String systemPropertyKey = "org.owasp.esapi.SecurityConfiguration";
+        String opensamlConfigImpl = ESAPISecurityConfig.class.getName();
+        
+        String currentValue = System.getProperty(systemPropertyKey);
+        if (currentValue == null || currentValue.isEmpty()) {
+            log.debug("Setting ESAPI SecurityConfiguration impl to OpenSAML internal class: {}", opensamlConfigImpl);
+            System.setProperty(systemPropertyKey, opensamlConfigImpl);
+            // We still need to call ESAPI.initialize() despite setting the system property, b/c within the ESAPI class
+            // the property is only evaluated once in a static initializer and stored. The initialize method however
+            // does overwrite the statically-set value from the system property. But still set the system property for 
+            // consistency, so other callers can see what has been set.
+            ESAPI.initialize(opensamlConfigImpl);
+        } else {
+            log.debug("ESAPI SecurityConfiguration impl was already set non-null and non-empty via system property, leaving existing value in place: {}",
+                    currentValue);
+        }
     }
 
-}
+}

Modified: trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/config/ESAPITest.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/config/ESAPITest.java?rev=3249&r1=3248&r2=3249&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/config/ESAPITest.java (original)
+++ trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/config/ESAPITest.java Wed Mar  6 15:41:30 2013
@@ -29,16 +29,23 @@
  */
 public class ESAPITest extends OpenSAMLInitBaseTestCase {
     
+    private String systemPropertyKey = "org.owasp.esapi.SecurityConfiguration";
+    private String opensamlConfigImpl = ESAPISecurityConfig.class.getName();
+    
     /**
      *  Tests that basic initialization has happened.
      */
     @Test
     public void testInit() {
+        Assert.assertEquals(opensamlConfigImpl, System.getProperty(systemPropertyKey));
+        
         SecurityConfiguration sc = ESAPI.securityConfiguration();
         Assert.assertNotNull(sc, "ESAPI SecurityConfiguration was null");
+        
+        Assert.assertTrue(sc instanceof ESAPISecurityConfig);
         
         Encoder encoder = ESAPI.encoder();
         Assert.assertNotNull(encoder, "ESAPI Encoder was null");
     }
 
-}
+}



More information about the commits mailing list