knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kris...@apache.org
Subject knox git commit: KNOX-1669 - Enable PMD code style rules
Date Tue, 11 Dec 2018 19:16:06 GMT
Repository: knox
Updated Branches:
  refs/heads/master c2cbb345b -> fcb97c75d


KNOX-1669 - Enable PMD code style rules

Signed-off-by: Kevin Risden <krisden@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/fcb97c75
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/fcb97c75
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/fcb97c75

Branch: refs/heads/master
Commit: fcb97c75d5264c4b8d75d82b18be00e2ea15688f
Parents: c2cbb34
Author: Kevin Risden <krisden@apache.org>
Authored: Tue Dec 11 13:17:42 2018 -0500
Committer: Kevin Risden <krisden@apache.org>
Committed: Tue Dec 11 13:44:00 2018 -0500

----------------------------------------------------------------------
 .../resources/build-tools/pmd/pmd-ruleset.xml   | 13 ++++
 .../loggers/sl4j/Sl4jMessageLogger.java         | 46 +++++++-------
 .../loggers/sl4j/Sl4jMessageLoggerFactory.java  |  2 -
 .../filter/rewrite/impl/UrlRewriteResponse.java |  6 +-
 .../rewrite/impl/xml/XmlFilterReader.java       |  3 +-
 .../gateway/filter/AclsAuthorizationFilter.java | 12 +++-
 .../jwt/filter/AccessTokenFederationFilter.java |  6 --
 .../filter/JWTAccessTokenAssertionFilter.java   |  5 --
 .../jwt/filter/JWTAuthCodeAssertionFilter.java  | 63 ++++++++++----------
 .../gateway/config/impl/GatewayConfigImpl.java  |  4 +-
 .../gateway/dispatch/UrlConnectionDispatch.java | 10 +---
 .../knox/gateway/util/PrincipalCredentials.java | 14 ++---
 .../topology/DefaultTopologyServiceTest.java    | 11 ++--
 .../dispatch/AbstractGatewayDispatch.java       | 24 +++-----
 .../gateway/filter/GatewayResponseWrapper.java  |  2 -
 .../security/impl/CMFMasterService.java         |  7 ++-
 .../knox/test/mock/MockResponseProvider.java    |  8 +--
 .../knox/gateway/util/X500PrincipalParser.java  | 14 +++--
 pom.xml                                         |  2 +
 19 files changed, 123 insertions(+), 129 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml
----------------------------------------------------------------------
diff --git a/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml b/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml
index dc2c394..15c9bc4 100644
--- a/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml
+++ b/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml
@@ -39,9 +39,22 @@ limitations under the License.
         <exclude name="SystemPrintln" />
         <exclude name="UseVarargs" />
     </rule>
+
     <!--<rule ref="category/java/codestyle.xml" />-->
+    <rule ref="category/java/codestyle.xml/AvoidProtectedFieldInFinalClass" />
+    <rule ref="category/java/codestyle.xml/ControlStatementBraces" />
+    <rule ref="category/java/codestyle.xml/DontImportJavaLang" />
+    <rule ref="category/java/codestyle.xml/DuplicateImports" />
+    <rule ref="category/java/codestyle.xml/ExtendsObject" />
+    <rule ref="category/java/codestyle.xml/ForLoopShouldBeWhileLoop" />
+    <rule ref="category/java/codestyle.xml/NoPackage" />
+    <rule ref="category/java/codestyle.xml/PackageCase" />
+    <rule ref="category/java/codestyle.xml/UnnecessaryModifier" />
+    <rule ref="category/java/codestyle.xml/UnnecessaryReturn" />
+
     <!--<rule ref="category/java/design.xml" />-->
     <!--<rule ref="category/java/documentation.xml" />-->
+
     <rule ref="category/java/errorprone.xml">
         <exclude name="AssignmentInOperand" />
         <exclude name="AssignmentToNonFinalStatic" />

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-i18n-logging-sl4j/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sl4j/Sl4jMessageLogger.java
----------------------------------------------------------------------
diff --git a/gateway-i18n-logging-sl4j/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sl4j/Sl4jMessageLogger.java
b/gateway-i18n-logging-sl4j/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sl4j/Sl4jMessageLogger.java
index e40d76a..777cb53 100644
--- a/gateway-i18n-logging-sl4j/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sl4j/Sl4jMessageLogger.java
+++ b/gateway-i18n-logging-sl4j/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sl4j/Sl4jMessageLogger.java
@@ -47,36 +47,40 @@ public class Sl4jMessageLogger implements MessageLogger {
     switch( messageLevel ) {
       case FATAL:
       case ERROR:
-        if( thrown == null )
-          logger.error( messageText );
-        else
-          logger.error( messageText, thrown );
+        if( thrown == null ) {
+          logger.error(messageText);
+        } else {
+          logger.error(messageText, thrown);
+        }
         break;
       case WARN:
-        if( thrown == null )
-          logger.warn( messageText );
-        else
-          logger.warn( messageText, thrown );
+        if( thrown == null ) {
+          logger.warn(messageText);
+        } else {
+          logger.warn(messageText, thrown);
+        }
         break;
       case INFO:
-        if( thrown == null )
-          logger.info( messageText );
-        else
-          logger.info( messageText, thrown );
+        if( thrown == null ) {
+          logger.info(messageText);
+        } else {
+          logger.info(messageText, thrown);
+        }
         break;
       case DEBUG:
-        if( thrown == null )
-          logger.debug( messageText );
-        else
-          logger.debug( messageText, thrown );
+        if( thrown == null ) {
+          logger.debug(messageText);
+        } else {
+          logger.debug(messageText, thrown);
+        }
         break;
       case TRACE:
-        if( thrown == null )
-          logger.trace( messageText );
-        else
-          logger.trace( messageText, thrown );
+        if( thrown == null ) {
+          logger.trace(messageText);
+        } else {
+          logger.trace(messageText, thrown);
+        }
         break;
     }
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-i18n-logging-sl4j/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sl4j/Sl4jMessageLoggerFactory.java
----------------------------------------------------------------------
diff --git a/gateway-i18n-logging-sl4j/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sl4j/Sl4jMessageLoggerFactory.java
b/gateway-i18n-logging-sl4j/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sl4j/Sl4jMessageLoggerFactory.java
index 7b47be1..78f2e99 100644
--- a/gateway-i18n-logging-sl4j/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sl4j/Sl4jMessageLoggerFactory.java
+++ b/gateway-i18n-logging-sl4j/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sl4j/Sl4jMessageLoggerFactory.java
@@ -22,10 +22,8 @@ import org.apache.knox.gateway.i18n.messages.MessageLoggerFactory;
 import org.slf4j.LoggerFactory;
 
 public class Sl4jMessageLoggerFactory implements MessageLoggerFactory {
-
   @Override
   public MessageLogger getLogger( String name ) {
     return new Sl4jMessageLogger( LoggerFactory.getLogger( name ) );
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteResponse.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteResponse.java
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteResponse.java
index aa1effb..3b71e2a 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteResponse.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteResponse.java
@@ -276,9 +276,9 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements
Params
 
   private List <String> getInboundQueryParam(String name ){
      List <String> inboundHosts = null;
-     if( this.request!=null )
-       inboundHosts =
-         Arrays.asList( this.request.getParameterValues(name));
+     if( this.request != null ) {
+       inboundHosts = Arrays.asList(this.request.getParameterValues(name));
+     }
      return inboundHosts;
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
index 38aab4b..743cfbe 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
@@ -155,8 +155,9 @@ public abstract class XmlFilterReader extends Reader {
         processEndDocument();
         break;
       case XMLEvent.START_ELEMENT:
-        if( parser.peek().getEventType() == XMLEvent.END_ELEMENT )
+        if( parser.peek().getEventType() == XMLEvent.END_ELEMENT ) {
           isEmptyElement = true;
+        }
         processStartElement( event.asStartElement());
         break;
       case XMLEvent.END_ELEMENT:

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-provider-security-authz-acls/src/main/java/org/apache/knox/gateway/filter/AclsAuthorizationFilter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-security-authz-acls/src/main/java/org/apache/knox/gateway/filter/AclsAuthorizationFilter.java
b/gateway-provider-security-authz-acls/src/main/java/org/apache/knox/gateway/filter/AclsAuthorizationFilter.java
index 337c3d7..24ef465 100644
--- a/gateway-provider-security-authz-acls/src/main/java/org/apache/knox/gateway/filter/AclsAuthorizationFilter.java
+++ b/gateway-provider-security-authz-acls/src/main/java/org/apache/knox/gateway/filter/AclsAuthorizationFilter.java
@@ -165,9 +165,15 @@ public class AclsAuthorizationFilter implements Filter {
       // to make sense and not grant access to everyone by mistake.
       // exclusion in OR is equivalent to denied
       // so, let's set each one that contains '*' to false.
-      if (parser.anyUser) userAccess = false;
-      if (parser.anyGroup) groupAccess = false;
-      if (parser.ipv.allowsAnyIP()) ipAddrAccess = false;
+      if (parser.anyUser) {
+        userAccess = false;
+      }
+      if (parser.anyGroup) {
+        groupAccess = false;
+      }
+      if (parser.ipv.allowsAnyIP()) {
+        ipAddrAccess = false;
+      }
 
       return (userAccess || groupAccess || ipAddrAccess);
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/AccessTokenFederationFilter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/AccessTokenFederationFilter.java
b/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/AccessTokenFederationFilter.java
index 3636f3a..201e98c 100644
--- a/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/AccessTokenFederationFilter.java
+++ b/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/AccessTokenFederationFilter.java
@@ -89,31 +89,26 @@ public class AccessTokenFederationFilter implements Filter {
           else {
             log.failedToValidateAudience();
             sendUnauthorized(response);
-            return; // break the chain
           }
         }
         else {
           log.tokenHasExpired();
           sendUnauthorized(response);
-          return; // break the chain
         }
       }
       else {
         log.failedToVerifyTokenSignature();
         sendUnauthorized(response);
-        return; // break the chain
       }
     }
     else {
       log.missingBearerToken();
       sendUnauthorized(response);
-      return; // break the chain
     }
   }
 
   private void sendUnauthorized(ServletResponse response) throws IOException {
     ((HttpServletResponse) response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
-    return;
   }
 
   private void continueWithEstablishedSecurityContext(Subject subject, final HttpServletRequest
request, final HttpServletResponse response, final FilterChain chain) throws IOException,
ServletException {
@@ -160,5 +155,4 @@ public class AccessTokenFederationFilter implements Filter {
     // To modify the private credential Set, the caller must have AuthPermission("modifyPrivateCredentials").
     return new javax.security.auth.Subject(true, principals, emptySet, emptySet);
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTAccessTokenAssertionFilter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTAccessTokenAssertionFilter.java
b/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTAccessTokenAssertionFilter.java
index ac14794..45aa98f 100644
--- a/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTAccessTokenAssertionFilter.java
+++ b/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTAccessTokenAssertionFilter.java
@@ -125,15 +125,12 @@ public class JWTAccessTokenAssertionFilter extends AbstractIdentityAssertionFilt
       jsonResponse = JsonUtils.renderAsJsonString(map);
 
       response.getWriter().write(jsonResponse);
-      //KNOX-685: response.getWriter().flush();
-      return; // break filter chain
     }
     else {
       // no token provided in header
       // something is really wrong since the JWTFederationFilter should have verified its
existence already
       // TODO: may have to check cookie and url as well before sending error
       ((HttpServletResponse) response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
-      return; //break filter chain
     }
   }
 
@@ -141,7 +138,6 @@ public class JWTAccessTokenAssertionFilter extends AbstractIdentityAssertionFilt
     String accessToken = null;
 
     Principal p = new Principal() {
-
       @Override
       public String getName() {
         return principalName;
@@ -160,5 +156,4 @@ public class JWTAccessTokenAssertionFilter extends AbstractIdentityAssertionFilt
 
     return accessToken;
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTAuthCodeAssertionFilter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTAuthCodeAssertionFilter.java
b/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTAuthCodeAssertionFilter.java
index 9afb21e..ad00f8d 100644
--- a/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTAuthCodeAssertionFilter.java
+++ b/gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTAuthCodeAssertionFilter.java
@@ -57,41 +57,38 @@ public class JWTAuthCodeAssertionFilter extends AbstractIdentityAssertionFilter
 
   @Override
   public void doFilter(ServletRequest request, ServletResponse response,
-      FilterChain chain) throws IOException, ServletException {
-
-      Subject subject = Subject.getSubject(AccessController.getContext());
-      String principalName = getPrincipalName(subject);
-      principalName = mapper.mapUserPrincipal(principalName);
-      JWT authCode;
-      try {
-        authCode = authority.issueToken(subject, "RS256");
-        // get the url for the token service
-        String url = null;
-        if (sr != null) {
-          url = sr.lookupServiceURL("token", "TGS");
-        }
+                       FilterChain chain) throws IOException {
+    Subject subject = Subject.getSubject(AccessController.getContext());
+    String principalName = getPrincipalName(subject);
+    principalName = mapper.mapUserPrincipal(principalName);
+    JWT authCode;
+    try {
+      authCode = authority.issueToken(subject, "RS256");
+      // get the url for the token service
+      String url = null;
+      if (sr != null) {
+        url = sr.lookupServiceURL("token", "TGS");
+      }
 
-        HashMap<String, Object> map = new HashMap<>();
-        // TODO: populate map from JWT authorization code
-        // Coverity CID 1327960
-        if( authCode != null ) {
-          map.put( "iss", authCode.getIssuer() );
-          map.put( "sub", authCode.getPrincipal() );
-          map.put( "aud", authCode.getAudience() );
-          map.put( "exp", authCode.getExpires() );
-          map.put( "code", authCode.toString() );
-        }
-        if (url != null) {
-          map.put("tke", url);
-        }
+      HashMap<String, Object> map = new HashMap<>();
+      // TODO: populate map from JWT authorization code
+      // Coverity CID 1327960
+      if (authCode != null) {
+        map.put("iss", authCode.getIssuer());
+        map.put("sub", authCode.getPrincipal());
+        map.put("aud", authCode.getAudience());
+        map.put("exp", authCode.getExpires());
+        map.put("code", authCode.toString());
+      }
+      if (url != null) {
+        map.put("tke", url);
+      }
 
-        String jsonResponse = JsonUtils.renderAsJsonString(map);
+      String jsonResponse = JsonUtils.renderAsJsonString(map);
 
-        response.getWriter().write(jsonResponse);
-        //KNOX-685: response.getWriter().flush();
-      } catch (TokenServiceException e) {
-        e.printStackTrace();
-      }
-      return; // break filter chain
+      response.getWriter().write(jsonResponse);
+    } catch (TokenServiceException e) {
+      e.printStackTrace();
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
index 62d70a0..e86d547 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
@@ -337,8 +337,9 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig
{
     if( lastFileUrl != null ) {
       File file = new File( lastFileUrl.getFile() ).getAbsoluteFile();
       File dir = file.getParentFile().getParentFile(); // Move up two levels to get to parent
of conf.
-      if( dir.exists() && dir.canRead() )
+      if (dir.exists() && dir.canRead()) {
         home = dir.getAbsolutePath();
+      }
       set( GATEWAY_HOME_VAR, home );
       log.settingGatewayHomeDir( "configuration file location", home );
       return;
@@ -347,7 +348,6 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig
{
     if( home != null ) {
       set( GATEWAY_HOME_VAR, home );
       log.settingGatewayHomeDir( "user.dir system property", home );
-      return;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-server/src/main/java/org/apache/knox/gateway/dispatch/UrlConnectionDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/dispatch/UrlConnectionDispatch.java
b/gateway-server/src/main/java/org/apache/knox/gateway/dispatch/UrlConnectionDispatch.java
index 27c83e5..3a63242 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/dispatch/UrlConnectionDispatch.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/dispatch/UrlConnectionDispatch.java
@@ -128,20 +128,14 @@ public class UrlConnectionDispatch extends AbstractGatewayFilter {
     String urlStr = targetUri.toString() + paramStr.toString();
     try {
       URL clientUrl = new URL( urlStr );
-      //System.out.println( "Resolved query: " + clientUrl );
       AuthenticatedURL.Token token = new AuthenticatedURL.Token();
       KerberosAuthenticator authenticator = new KerberosAuthenticator();
       auditor.audit( Action.DISPATCH, urlStr, ResourceType.URI, ActionOutcome.UNAVAILABLE
);
       HttpURLConnection conn = new AuthenticatedURL( authenticator ).openConnection( clientUrl,
token );
-      //System.out.println( "STATUS=" + conn.getResponseCode() );
       InputStream input = conn.getInputStream();
       if( input != null ) {
-        OutputStream output = response.getOutputStream();
-        try {
+        try(OutputStream output = response.getOutputStream()) {
           IOUtils.copy( input, output );
-        } finally {
-          //KNOX-685: output.flush();
-          input.close();
         }
       }
       auditor.audit( Action.DISPATCH, urlStr, ResourceType.URI, ActionOutcome.SUCCESS );
@@ -154,7 +148,5 @@ public class UrlConnectionDispatch extends AbstractGatewayFilter {
       LOG.failedToEstablishConnectionToUrl( urlStr, e );
       auditor.audit( Action.DISPATCH, urlStr, ResourceType.URI, ActionOutcome.FAILURE, RES.responseStatus(
HttpServletResponse.SC_NOT_FOUND ) );
     }
-
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-server/src/main/java/org/apache/knox/gateway/util/PrincipalCredentials.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/util/PrincipalCredentials.java
b/gateway-server/src/main/java/org/apache/knox/gateway/util/PrincipalCredentials.java
index 7757437..2c8f380 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/util/PrincipalCredentials.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/util/PrincipalCredentials.java
@@ -38,7 +38,9 @@ public class PrincipalCredentials implements Credentials, Serializable {
 
   public PrincipalCredentials( Principal principal ) {
     super();
-    if( principal == null ) throw new IllegalArgumentException( "principal==null" );
+    if( principal == null ) {
+      throw new IllegalArgumentException( "principal==null" );
+    }
     this.principal = principal;
   }
 
@@ -59,12 +61,12 @@ public class PrincipalCredentials implements Credentials, Serializable
{
 
   @Override
   public boolean equals( Object object ) {
-    if( this == object ) return true;
+    if( this == object ) {
+      return true;
+    }
     if( object instanceof PrincipalCredentials ) {
       PrincipalCredentials that = (PrincipalCredentials)object;
-      if( this.principal.equals( that.principal ) ) {
-        return true;
-      }
+      return this.principal.equals(that.principal);
     }
     return false;
   }
@@ -73,6 +75,4 @@ public class PrincipalCredentials implements Credentials, Serializable {
   public String toString() {
     return this.principal.toString();
   }
-
 }
-

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
b/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
index 079727c..99dd6d4 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
@@ -72,12 +72,11 @@ public class DefaultTopologyServiceTest {
     if (!file.exists()) {
       FileUtils.touch(file);
     }
-    InputStream input = ClassLoader.getSystemResourceAsStream(resource);
-    OutputStream output = FileUtils.openOutputStream(file);
-    IOUtils.copy(input, output);
-    //KNOX-685: output.flush();
-    input.close();
-    output.close();
+    try(InputStream input = ClassLoader.getSystemResourceAsStream(resource);
+        OutputStream output = FileUtils.openOutputStream(file)) {
+      assertNotNull(input);
+      IOUtils.copy(input, output);
+    }
     file.setLastModified(timestamp);
     assertTrue("Failed to create test file " + file.getAbsolutePath(), file.exists());
     assertTrue("Failed to populate test file " + file.getAbsolutePath(), file.length() >
0);

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
index d566995..ab5f3fe 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
@@ -50,22 +50,15 @@ public abstract class AbstractGatewayDispatch implements Dispatch {
   public void init() {
   }
 
-  protected void writeResponse(HttpServletRequest request, HttpServletResponse response,
InputStream stream )
+  protected void writeResponse(HttpServletRequest request, HttpServletResponse response,
InputStream stream)
       throws IOException {
-//    ResponseStreamer streamer =
-//        (ResponseStreamer)request.getAttribute( RESPONSE_STREAMER_ATTRIBUTE_NAME );
-//    if( streamer != null ) {
-//      streamer.streamResponse( stream, response.getOutputStream() );
-//    } else {
-      if( response instanceof GatewayResponse ) {
-        ((GatewayResponse)response).streamResponse( stream );
-      } else {
-        OutputStream output = response.getOutputStream();
-        IOUtils.copy(stream, output);
-        //KNOX-685: output.flush();
-        output.close();
-      }
-//    }
+    if (response instanceof GatewayResponse) {
+      ((GatewayResponse) response).streamResponse(stream);
+    } else {
+      OutputStream output = response.getOutputStream();
+      IOUtils.copy(stream, output);
+      output.close();
+    }
   }
 
   @Override
@@ -167,5 +160,4 @@ public abstract class AbstractGatewayDispatch implements Dispatch {
       greaterThan = str.indexOf(">", greaterThan+1);
     }
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-spi/src/main/java/org/apache/knox/gateway/filter/GatewayResponseWrapper.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/filter/GatewayResponseWrapper.java
b/gateway-spi/src/main/java/org/apache/knox/gateway/filter/GatewayResponseWrapper.java
index 94db2b7..25f5a31 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/filter/GatewayResponseWrapper.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/filter/GatewayResponseWrapper.java
@@ -61,8 +61,6 @@ public abstract class GatewayResponseWrapper extends HttpServletResponseWrapper
   @Override
   public void streamResponse( InputStream input, OutputStream output ) throws IOException
{
     IOUtils.copy(input, output);
-    //KNOX-685: output.flush();
     output.close();
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
index 023583f..611e670 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
@@ -181,10 +181,12 @@ public class CMFMasterService {
       // TODO: look into the following for Windows: Runtime.getRuntime().exec("attrib -r
myFile");
       if (isUnixEnv()) {
           //args and file should never be null.
-          if (args == null || file == null)
+          if (args == null || file == null) {
             throw new IllegalArgumentException("nullArg");
-          if (!file.exists())
+          }
+          if (!file.exists()) {
             throw new IOException("fileNotFound");
+          }
 
           // " +" regular expression for 1 or more spaces
           final String[] argsString = args.split(" +");
@@ -199,5 +201,4 @@ public class CMFMasterService {
   private boolean isUnixEnv() {
     return (File.separatorChar == '/');
   }
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-test-utils/src/main/java/org/apache/knox/test/mock/MockResponseProvider.java
----------------------------------------------------------------------
diff --git a/gateway-test-utils/src/main/java/org/apache/knox/test/mock/MockResponseProvider.java
b/gateway-test-utils/src/main/java/org/apache/knox/test/mock/MockResponseProvider.java
index 1d5831a..07ff0f8 100644
--- a/gateway-test-utils/src/main/java/org/apache/knox/test/mock/MockResponseProvider.java
+++ b/gateway-test-utils/src/main/java/org/apache/knox/test/mock/MockResponseProvider.java
@@ -23,6 +23,7 @@ import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.util.HashMap;
@@ -148,10 +149,9 @@ public class MockResponseProvider {
     }
     response.flushBuffer();
     if( entity != null ) {
-      response.getOutputStream().write( entity );
-      //KNOX-685: response.getOutputStream().flush();
-      response.getOutputStream().close();
+      try(OutputStream outputStream = response.getOutputStream()) {
+          outputStream.write(entity);
+      }
     }
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X500PrincipalParser.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X500PrincipalParser.java
b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X500PrincipalParser.java
index e44cd48..c55c408 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X500PrincipalParser.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/X500PrincipalParser.java
@@ -112,8 +112,9 @@ public class X500PrincipalParser {
         // Return the string starting after the ID string and the = sign that follows it.
         retNamePart = namePart.substring(searchPart.length());
         // By definition the first one is most significant
-        if (significance == MOSTSIGNIFICANT)
+        if (significance == MOSTSIGNIFICANT) {
           break;
+        }
       }
     }
 
@@ -131,10 +132,10 @@ public class X500PrincipalParser {
       int endIndex;
       for(endIndex = startIndex; endIndex < dn.length(); endIndex++) {
         c = dn.charAt(endIndex);
-        if(c == ',' || c == '+')
+        if(c == ',' || c == '+') {
           break;
-        if(c == '\\')
-        {
+        }
+        if(c == '\\') {
           endIndex++; // skip the escaped char
         }
       }
@@ -147,10 +148,11 @@ public class X500PrincipalParser {
 
       if(c != '+') {
         rdnNameArray.add(nameValues);
-        if(endIndex != dn.length())
+        if(endIndex != dn.length()) {
           nameValues = new ArrayList<>();
-        else
+        } else {
           nameValues = null;
+        }
       }
       startIndex = endIndex + 1;
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/fcb97c75/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 92ac657..ac8bfbe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -628,6 +628,7 @@
                         <ruleset>build-tools/pmd/pmd-ruleset.xml</ruleset>
                     </rulesets>
                     <printFailingErrors>true</printFailingErrors>
+                    <linkXRef>false</linkXRef>
                     <targetJdk>1.8</targetJdk>
                 </configuration>
                 <executions>
@@ -695,6 +696,7 @@
                     <rulesets>
                         <ruleset>build-tools/pmd/pmd-ruleset.xml</ruleset>
                     </rulesets>
+                    <linkXRef>false</linkXRef>
                     <targetJdk>1.8</targetJdk>
                 </configuration>
             </plugin>


Mime
View raw message