import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
+import java.security.Policy;
import javax.imageio.ImageIO;
import javax.xml.parsers.DocumentBuilderFactory;
this.keepAliveProtection = keepAliveProtection;
}
+ /**
+ * Protect against the memory leak caused when the first call to
+ * <code>javax.security.auth.Policy</code> is triggered by a web
+ * application. This first call populate a static variable with a reference
+ * to the context class loader. Defaults to <code>true</code>.
+ */
+ private boolean securityPolicyProtection = true;
+ public boolean iSsecurityPolicyProtection() {
+ return securityPolicyProtection;
+ }
+ public void setSecurityPolicyProtection(boolean securityPolicyProtection) {
+ this.securityPolicyProtection = securityPolicyProtection;
+ }
+
/**
* Protect against the memory leak, when the initialization of the
* Java Cryptography Architecture is triggered by initializing
}
/*
+ * Calling getPolicy retains a static reference to the context class
+ * loader.
+ */
+ if (securityPolicyProtection) {
+ try {
+ Policy.getPolicy();
+ } catch(SecurityException e) {
+ // Ignore. Don't need call to getPolicy() to be successful,
+ // just need to trigger static initializer.
+ }
+ }
+
+ /*
* Creating a MessageDigest during web application startup
* initializes the Java Cryptography Architecture. Under certain
* conditions this starts a Token poller thread with TCCL equal
trigger a memory leak on reload. Defaults to <code>true</code>.</p>
</attribute>
+ <attribute name="securityPolicyProtection" required="false">
+ <p>Enables protection so that usage of
+ <code>javax.security.auth.Policy</code> by a web application does not
+ result in a memory leak. The first access of this class will trigger the
+ static initializer that will retain a static reference to the context
+ class loader. The protection calls the <code>getPolicy()</code> method
+ of this class to ensure that the static initializer is not triggered by
+ a web application. Defaults to <code>true</code>.</p>
+ </attribute>
+
<attribute name="tokenPollerProtection" required="false">
<p>Enables protection so that any token poller thread initialized by
<code>sun.security.pkcs11.SunPKCS11.initToken()</code> does not