harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r726249 - /harmony/enhanced/classlib/trunk/modules/x-net/src/main/java/javax/net/ssl/DefaultSSLContext.java
Date Sat, 13 Dec 2008 18:23:25 GMT
Author: ndbeyer
Date: Sat Dec 13 10:23:24 2008
New Revision: 726249

URL: http://svn.apache.org/viewvc?rev=726249&view=rev
Log:
add synchronized keyword to keep thread-safe; general clean up of code

Modified:
    harmony/enhanced/classlib/trunk/modules/x-net/src/main/java/javax/net/ssl/DefaultSSLContext.java

Modified: harmony/enhanced/classlib/trunk/modules/x-net/src/main/java/javax/net/ssl/DefaultSSLContext.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/main/java/javax/net/ssl/DefaultSSLContext.java?rev=726249&r1=726248&r2=726249&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/main/java/javax/net/ssl/DefaultSSLContext.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/main/java/javax/net/ssl/DefaultSSLContext.java
Sat Dec 13 10:23:24 2008
@@ -24,27 +24,24 @@
 
 import java.io.FileInputStream;
 import java.security.AccessController;
+import java.security.KeyStore;
+import java.security.PrivilegedAction;
 import java.security.Provider;
 import java.security.Security;
-import java.security.KeyStore;
-import java.util.Iterator;
 
 import org.apache.harmony.security.fortress.Engine;
 import org.apache.harmony.security.fortress.Services;
 
-
 /**
  * Support class for this package.
- *  
  */
-
-class DefaultSSLContext {
+final class DefaultSSLContext {
     private static SSLContext defaultSSLContext;
 
-    public static SSLContext getContext() {
+     static synchronized SSLContext getContext() {
         if (defaultSSLContext == null) {
             defaultSSLContext = AccessController
-                    .doPrivileged(new java.security.PrivilegedAction<SSLContext>()
{
+                    .doPrivileged(new PrivilegedAction<SSLContext>() {
                         public SSLContext run() {
                             return findDefault();
                         }
@@ -55,40 +52,35 @@
 
     private static SSLContext findDefault() {
         // FIXME EXPORT CONTROL
-        Provider.Service service;
-        for (Iterator it1 = Services.getProvidersList().iterator(); it1
-                .hasNext();) {
-            service = Engine.door.getService((Provider) it1.next(),
-                    "SSLContext");
+        for (Provider provider : Services.getProvidersList()) {
+            final Provider.Service service = Engine.door.getService(provider, "SSLContext");
             if (service != null) {
                 try {
-                    SSLContext con = new ContextImpl(
-                            (SSLContextSpi) service.newInstance(null),
-                            service.getProvider(), 
-                            service.getAlgorithm());
+                    SSLContext con = new ContextImpl((SSLContextSpi) service.newInstance(null),
+                            service.getProvider(), service.getAlgorithm());
 
- //TODO javax.net.ssl.keyStoreProvider, javax.net.ssl.trustStoreProvider system property
+                    /* 
+                     * TODO 
+                     * javax.net.ssl.keyStoreProvider, 
+                     * javax.net.ssl.trustStoreProvider system property
+                     */
+                    
                     // find KeyStore, KeyManagers
                     KeyManager[] keyManagers = null;
-                    KeyStore ks = KeyStore.getInstance(KeyStore
-                            .getDefaultType());
-                    String keystore = System
-                            .getProperty("javax.net.ssl.keyStore");
-                    String keystorepwd = System
-                            .getProperty("javax.net.ssl.keyStorePassword");
+                    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+                    String keystore = System.getProperty("javax.net.ssl.keyStore");
+                    String keystorepwd = System.getProperty("javax.net.ssl.keyStorePassword");
                     char[] pwd = null;
                     if (keystorepwd != null) {
                         pwd = keystorepwd.toCharArray();
                     }
                     if (keystore != null) {
-                        FileInputStream fis = new java.io.FileInputStream(
-                                keystore);
+                        FileInputStream fis = new FileInputStream(keystore);
                         ks.load(fis, pwd);
                         fis.close();
 
                         KeyManagerFactory kmf;
-                        String kmfAlg = Security
-                                .getProperty("ssl.KeyManagerFactory.algorithm");
+                        String kmfAlg = Security.getProperty("ssl.KeyManagerFactory.algorithm");
                         if (kmfAlg == null) {
                             kmfAlg = "SunX509";
                         }
@@ -100,21 +92,18 @@
                     // find TrustStore, TrustManagers
                     TrustManager[] trustManagers = null;
                     keystore = System.getProperty("javax.net.ssl.trustStore");
-                    keystorepwd = System
-                            .getProperty("javax.net.ssl.trustStorePassword");
+                    keystorepwd = System.getProperty("javax.net.ssl.trustStorePassword");
                     pwd = null;
                     if (keystorepwd != null) {
                         pwd = keystorepwd.toCharArray();
                     }
-                    //TODO Defaults: jssecacerts; cacerts
+                    // TODO Defaults: jssecacerts; cacerts
                     if (keystore != null) {
-                        FileInputStream fis = new java.io.FileInputStream(
-                                keystore);
+                        FileInputStream fis = new FileInputStream(keystore);
                         ks.load(fis, pwd);
                         fis.close();
                         TrustManagerFactory tmf;
-                        String tmfAlg = Security
-                                .getProperty("ssl.TrustManagerFactory.algorithm");
+                        String tmfAlg = Security.getProperty("ssl.TrustManagerFactory.algorithm");
                         if (tmfAlg == null) {
                             tmfAlg = "PKIX";
                         }
@@ -126,7 +115,6 @@
                     con.init(keyManagers, trustManagers, null);
                     return con;
                 } catch (Exception e) {
-                    // e.printStackTrace();
                     // ignore and try another
                 }
             }



Mime
View raw message