< prev index next >

src/java.base/share/classes/sun/security/ssl/SSLServerSocketImpl.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -26,11 +26,10 @@
 package sun.security.ssl;
 
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.Socket;
-import java.util.concurrent.locks.ReentrantLock;
 import javax.net.ssl.SSLParameters;
 import javax.net.ssl.SSLServerSocket;
 
 /**
  * This class provides a simple way for servers to support conventional

@@ -55,11 +54,10 @@
  * @author David Brownell
  */
 final class SSLServerSocketImpl extends SSLServerSocket {
     private final SSLContextImpl        sslContext;
     private final SSLConfiguration      sslConfig;
-    private final ReentrantLock         serverSocketLock = new ReentrantLock();
 
     SSLServerSocketImpl(SSLContextImpl sslContext) throws IOException {
 
         super();
         this.sslContext = sslContext;

@@ -84,28 +82,18 @@
         this.sslConfig = new SSLConfiguration(sslContext, false);
         this.sslConfig.isClientMode = false;
     }
 
     @Override
-    public String[] getEnabledCipherSuites() {
-        serverSocketLock.lock();
-        try {
-            return CipherSuite.namesOf(sslConfig.enabledCipherSuites);
-        } finally {
-            serverSocketLock.unlock();
-        }
+    public synchronized String[] getEnabledCipherSuites() {
+        return CipherSuite.namesOf(sslConfig.enabledCipherSuites);
     }
 
     @Override
-    public void setEnabledCipherSuites(String[] suites) {
-        serverSocketLock.lock();
-        try {
-            sslConfig.enabledCipherSuites =
-                    CipherSuite.validValuesOf(suites);
-        } finally {
-            serverSocketLock.unlock();
-        }
+    public synchronized void setEnabledCipherSuites(String[] suites) {
+        sslConfig.enabledCipherSuites =
+                CipherSuite.validValuesOf(suites);
     }
 
     @Override
     public String[] getSupportedCipherSuites() {
         return CipherSuite.namesOf(sslContext.getSupportedCipherSuites());

@@ -116,157 +104,97 @@
         return ProtocolVersion.toStringArray(
                 sslContext.getSupportedProtocolVersions());
     }
 
     @Override
-    public String[] getEnabledProtocols() {
-        serverSocketLock.lock();
-        try {
-            return ProtocolVersion.toStringArray(sslConfig.enabledProtocols);
-        } finally {
-            serverSocketLock.unlock();
-        }
+    public synchronized String[] getEnabledProtocols() {
+        return ProtocolVersion.toStringArray(sslConfig.enabledProtocols);
     }
 
     @Override
-    public void setEnabledProtocols(String[] protocols) {
-        serverSocketLock.lock();
-        try {
-            if (protocols == null) {
-                throw new IllegalArgumentException("Protocols cannot be null");
-            }
-
-            sslConfig.enabledProtocols = ProtocolVersion.namesOf(protocols);
-        } finally {
-            serverSocketLock.unlock();
+    public synchronized void setEnabledProtocols(String[] protocols) {
+        if (protocols == null) {
+            throw new IllegalArgumentException("Protocols cannot be null");
         }
+
+        sslConfig.enabledProtocols = ProtocolVersion.namesOf(protocols);
     }
 
     @Override
-    public void setNeedClientAuth(boolean need) {
-        serverSocketLock.lock();
-        try {
-            sslConfig.clientAuthType =
-                    (need ? ClientAuthType.CLIENT_AUTH_REQUIRED :
-                            ClientAuthType.CLIENT_AUTH_NONE);
-        } finally {
-            serverSocketLock.unlock();
-        }
+    public synchronized void setNeedClientAuth(boolean need) {
+        sslConfig.clientAuthType =
+                (need ? ClientAuthType.CLIENT_AUTH_REQUIRED :
+                        ClientAuthType.CLIENT_AUTH_NONE);
     }
 
     @Override
-    public boolean getNeedClientAuth() {
-        serverSocketLock.lock();
-        try {
-            return (sslConfig.clientAuthType ==
+    public synchronized boolean getNeedClientAuth() {
+        return (sslConfig.clientAuthType ==
                         ClientAuthType.CLIENT_AUTH_REQUIRED);
-        } finally {
-            serverSocketLock.unlock();
-        }
     }
 
     @Override
-    public void setWantClientAuth(boolean want) {
-        serverSocketLock.lock();
-        try {
-            sslConfig.clientAuthType =
-                    (want ? ClientAuthType.CLIENT_AUTH_REQUESTED :
-                            ClientAuthType.CLIENT_AUTH_NONE);
-        } finally {
-            serverSocketLock.unlock();
-        }
+    public synchronized void setWantClientAuth(boolean want) {
+        sslConfig.clientAuthType =
+                (want ? ClientAuthType.CLIENT_AUTH_REQUESTED :
+                        ClientAuthType.CLIENT_AUTH_NONE);
     }
 
     @Override
-    public boolean getWantClientAuth() {
-        serverSocketLock.lock();
-        try {
-            return (sslConfig.clientAuthType ==
+    public synchronized boolean getWantClientAuth() {
+        return (sslConfig.clientAuthType ==
                         ClientAuthType.CLIENT_AUTH_REQUESTED);
-        } finally {
-            serverSocketLock.unlock();
-        }
     }
 
     @Override
-    public void setUseClientMode(boolean useClientMode) {
-        serverSocketLock.lock();
-        try {
-            /*
-             * If we need to change the client mode and the enabled
-             * protocols and cipher suites haven't specifically been
-             * set by the user, change them to the corresponding
-             * default ones.
-             */
-            if (sslConfig.isClientMode != useClientMode) {
-                if (sslContext.isDefaultProtocolVesions(
-                        sslConfig.enabledProtocols)) {
-                    sslConfig.enabledProtocols =
+    public synchronized void setUseClientMode(boolean useClientMode) {
+        /*
+         * If we need to change the client mode and the enabled
+         * protocols and cipher suites haven't specifically been
+         * set by the user, change them to the corresponding
+         * default ones.
+         */
+        if (sslConfig.isClientMode != useClientMode) {
+            if (sslContext.isDefaultProtocolVesions(
+                    sslConfig.enabledProtocols)) {
+                sslConfig.enabledProtocols =
                         sslContext.getDefaultProtocolVersions(!useClientMode);
-                }
+            }
 
-                if (sslContext.isDefaultCipherSuiteList(
-                        sslConfig.enabledCipherSuites)) {
-                    sslConfig.enabledCipherSuites =
+            if (sslContext.isDefaultCipherSuiteList(
+                    sslConfig.enabledCipherSuites)) {
+                sslConfig.enabledCipherSuites =
                         sslContext.getDefaultCipherSuites(!useClientMode);
-                }
-
-                sslConfig.isClientMode = useClientMode;
             }
-        } finally {
-            serverSocketLock.unlock();
+
+            sslConfig.isClientMode = useClientMode;
         }
     }
 
     @Override
-    public boolean getUseClientMode() {
-        serverSocketLock.lock();
-        try {
-            return sslConfig.isClientMode;
-        } finally {
-            serverSocketLock.unlock();
-        }
+    public synchronized boolean getUseClientMode() {
+        return sslConfig.isClientMode;
     }
 
     @Override
-    public void setEnableSessionCreation(boolean flag) {
-        serverSocketLock.lock();
-        try {
-            sslConfig.enableSessionCreation = flag;
-        } finally {
-            serverSocketLock.unlock();
-        }
+    public synchronized void setEnableSessionCreation(boolean flag) {
+        sslConfig.enableSessionCreation = flag;
     }
 
     @Override
-    public boolean getEnableSessionCreation() {
-        serverSocketLock.lock();
-        try {
-            return sslConfig.enableSessionCreation;
-        } finally {
-            serverSocketLock.unlock();
-        }
+    public synchronized boolean getEnableSessionCreation() {
+        return sslConfig.enableSessionCreation;
     }
 
     @Override
-    public SSLParameters getSSLParameters() {
-        serverSocketLock.lock();
-        try {
-            return sslConfig.getSSLParameters();
-        } finally {
-            serverSocketLock.unlock();
-        }
+    public synchronized SSLParameters getSSLParameters() {
+        return sslConfig.getSSLParameters();
     }
 
     @Override
-    public void setSSLParameters(SSLParameters params) {
-        serverSocketLock.lock();
-        try {
-            sslConfig.setSSLParameters(params);
-        } finally {
-            serverSocketLock.unlock();
-        }
+    public synchronized void setSSLParameters(SSLParameters params) {
+        sslConfig.setSSLParameters(params);
     }
 
     @Override
     public Socket accept() throws IOException {
         SSLSocketImpl s = new SSLSocketImpl(sslContext, sslConfig);
< prev index next >