You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2017/11/28 02:08:43 UTC

[GitHub] jiazhai closed pull request #779: Issue 230: Enable Checkstyle on the tls package

jiazhai closed pull request #779: Issue 230: Enable Checkstyle on the tls package
URL: https://github.com/apache/bookkeeper/pull/779
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/SecurityException.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/SecurityException.java
index 166513e64..67fa1980a 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/SecurityException.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/SecurityException.java
@@ -17,6 +17,9 @@
  */
 package org.apache.bookkeeper.tls;
 
+/**
+ * Signals that a security-related exception has occurred.
+ */
 public class SecurityException extends Exception {
     public SecurityException() {}
 
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/SecurityHandlerFactory.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/SecurityHandlerFactory.java
index 84a3a5ea7..59be8847d 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/SecurityHandlerFactory.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/SecurityHandlerFactory.java
@@ -17,19 +17,27 @@
  */
 package org.apache.bookkeeper.tls;
 
-import org.apache.bookkeeper.conf.AbstractConfiguration;
-
 import io.netty.handler.ssl.SslHandler;
 
+import org.apache.bookkeeper.conf.AbstractConfiguration;
+
+/**
+ * A factory to manage the security handlers.
+ */
 public interface SecurityHandlerFactory {
-    public enum NodeType {
+
+    /**
+     * The security handler type.
+     */
+    enum NodeType {
         Unknown,
         Client,
         Server,
     }
 
-    public abstract String getHandlerName();
+    String getHandlerName();
+
+    void init(NodeType type, AbstractConfiguration conf) throws SecurityException;
 
-    public abstract void init(NodeType type, AbstractConfiguration conf) throws SecurityException;
-    public SslHandler newTLSHandler();
+    SslHandler newTLSHandler();
 }
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/SecurityProviderFactoryFactory.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/SecurityProviderFactoryFactory.java
index 38376d8a9..94d6096ad 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/SecurityProviderFactoryFactory.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/SecurityProviderFactoryFactory.java
@@ -20,8 +20,11 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * A factory to manage security provider factories.
+ */
 public abstract class SecurityProviderFactoryFactory {
-    private final static Logger LOG = LoggerFactory.getLogger(SecurityProviderFactoryFactory.class);
+    private static final Logger LOG = LoggerFactory.getLogger(SecurityProviderFactoryFactory.class);
 
     public static SecurityHandlerFactory getSecurityProviderFactory(String securityHandler)
             throws SecurityException {
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/TLSContextFactory.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/TLSContextFactory.java
index eda5aec98..f9c673a83 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/TLSContextFactory.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/TLSContextFactory.java
@@ -17,13 +17,6 @@
  */
 package org.apache.bookkeeper.tls;
 
-import org.apache.bookkeeper.conf.AbstractConfiguration;
-import org.apache.bookkeeper.conf.ClientConfiguration;
-import org.apache.bookkeeper.conf.ServerConfiguration;
-import org.apache.commons.io.FileUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import com.google.common.base.Strings;
 
 import io.netty.buffer.PooledByteBufAllocator;
@@ -46,9 +39,19 @@
 import javax.net.ssl.KeyManagerFactory;
 import javax.net.ssl.TrustManagerFactory;
 
+import org.apache.bookkeeper.conf.AbstractConfiguration;
+import org.apache.bookkeeper.conf.ClientConfiguration;
+import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.commons.io.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A factory to manage TLS contexts.
+ */
 public class TLSContextFactory implements SecurityHandlerFactory {
-    private final static Logger LOG = LoggerFactory.getLogger(TLSContextFactory.class);
-    private final static String TLSCONTEXT_HANDLER_NAME = "tls";
+    private static final Logger LOG = LoggerFactory.getLogger(TLSContextFactory.class);
+    private static final String TLSCONTEXT_HANDLER_NAME = "tls";
     private String[] protocols;
     private String[] ciphers;
     private SslContext sslContext;
@@ -148,12 +151,12 @@ private SslProvider getTLSProvider(String sslProvider) {
         return SslProvider.JDK;
     }
 
-    private void createClientContext(AbstractConfiguration conf) throws SecurityException, KeyStoreException, NoSuchAlgorithmException,
-            CertificateException, IOException, UnrecoverableKeyException {
+    private void createClientContext(AbstractConfiguration conf) throws SecurityException, KeyStoreException,
+            NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException {
         final SslContextBuilder sslContextBuilder;
         final ClientConfiguration clientConf;
         final SslProvider provider;
-        final boolean Authentication;
+        final boolean authentication;
 
         KeyManagerFactory kmf = null;
         TrustManagerFactory tmf = null;
@@ -165,12 +168,12 @@ private void createClientContext(AbstractConfiguration conf) throws SecurityExce
 
         clientConf = (ClientConfiguration) conf;
         provider = getTLSProvider(clientConf.getTLSProvider());
-        Authentication = clientConf.getTLSClientAuthentication();
+        authentication = clientConf.getTLSClientAuthentication();
 
         tmf = initTrustManagerFactory(clientConf.getTLSTrustStoreType(), clientConf.getTLSTrustStore(),
                 clientConf.getTLSTrustStorePasswordPath());
 
-        if (Authentication) {
+        if (authentication) {
             kmf = initKeyManagerFactory(clientConf.getTLSKeyStoreType(), clientConf.getTLSKeyStore(),
                     clientConf.getTLSKeyStorePasswordPath());
         }
@@ -185,19 +188,19 @@ private void createClientContext(AbstractConfiguration conf) throws SecurityExce
                                             .clientAuth(ClientAuth.REQUIRE);
 
         /* if mutual authentication is enabled */
-        if (Authentication) {
+        if (authentication) {
             sslContextBuilder.keyManager(kmf);
         }
 
         sslContext = sslContextBuilder.build();
     }
 
-    private void createServerContext(AbstractConfiguration conf) throws SecurityException, KeyStoreException, NoSuchAlgorithmException,
-            CertificateException, IOException, UnrecoverableKeyException {
+    private void createServerContext(AbstractConfiguration conf) throws SecurityException, KeyStoreException,
+            NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException {
         final SslContextBuilder sslContextBuilder;
         final ServerConfiguration serverConf;
         final SslProvider provider;
-        final boolean Authentication;
+        final boolean authentication;
 
         KeyManagerFactory kmf = null;
         TrustManagerFactory tmf = null;
@@ -209,12 +212,12 @@ private void createServerContext(AbstractConfiguration conf) throws SecurityExce
 
         serverConf = (ServerConfiguration) conf;
         provider = getTLSProvider(serverConf.getTLSProvider());
-        Authentication = serverConf.getTLSClientAuthentication();
+        authentication = serverConf.getTLSClientAuthentication();
 
         kmf = initKeyManagerFactory(serverConf.getTLSKeyStoreType(), serverConf.getTLSKeyStore(),
                 serverConf.getTLSKeyStorePasswordPath());
 
-        if (Authentication) {
+        if (authentication) {
             tmf = initTrustManagerFactory(serverConf.getTLSTrustStoreType(), serverConf.getTLSTrustStore(),
                     serverConf.getTLSTrustStorePasswordPath());
         }
@@ -228,7 +231,7 @@ private void createServerContext(AbstractConfiguration conf) throws SecurityExce
                                             .startTls(true);
 
         /* if mutual authentication is enabled */
-        if (Authentication) {
+        if (authentication) {
             sslContextBuilder.trustManager(tmf)
                             .clientAuth(ClientAuth.REQUIRE);
         }
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/package-info.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/package-info.java
new file mode 100644
index 000000000..54b2fee92
--- /dev/null
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tls/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Security and TLS-related classes.
+ */
+package org.apache.bookkeeper.tls;
diff --git a/buildtools/src/main/resources/bookkeeper/server-suppressions.xml b/buildtools/src/main/resources/bookkeeper/server-suppressions.xml
index 0d4f896b0..93b821186 100644
--- a/buildtools/src/main/resources/bookkeeper/server-suppressions.xml
+++ b/buildtools/src/main/resources/bookkeeper/server-suppressions.xml
@@ -32,7 +32,6 @@
     <suppress checks=".*" files=".*[\\/]replication[\\/].*"/>
     <suppress checks=".*" files=".*[\\/]sasl[\\/].*"/>
     <suppress checks=".*" files=".*[\\/]test[\\/].*"/>
-    <suppress checks=".*" files=".*[\\/]tls[\\/].*"/>
     <suppress checks=".*" files=".*[\\/]util[\\/].*"/>
 
     <!-- suppress all checks in the generated directories -->


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services