Repository: knox Updated Branches: refs/heads/master 159bb800c -> 28a77b727
KNOX-1451 - Setup base checkstyle plugin Signed-off-by: Kevin Risden <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/28a77b72 Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/28a77b72 Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/28a77b72 Branch: refs/heads/master Commit: 28a77b7273d2b4515ee2f8898d70e6a380c57144 Parents: 159bb80 Author: Kevin Risden <[email protected]> Authored: Tue Sep 25 14:48:47 2018 -0400 Committer: Kevin Risden <[email protected]> Committed: Tue Sep 25 14:48:52 2018 -0400 ---------------------------------------------------------------------- .../federation/AbstractJWTFilterTest.java | 4 +- .../preauth/filter/PreAuthFederationFilter.java | 1 + .../HeaderPreAuthFederationFilterTest.java | 6 +- .../websockets/GatewayWebsocketHandler.java | 4 +- pom.xml | 33 ++++++++- src/checkstyle/checker.xml | 71 ++++++++++++++++++++ src/checkstyle/suppressions.xml | 27 ++++++++ 7 files changed, 136 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/28a77b72/gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/AbstractJWTFilterTest.java ---------------------------------------------------------------------- diff --git a/gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/AbstractJWTFilterTest.java b/gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/AbstractJWTFilterTest.java index fb75163..f9d4e7b 100644 --- a/gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/AbstractJWTFilterTest.java +++ b/gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/AbstractJWTFilterTest.java @@ -527,8 +527,8 @@ public abstract class AbstractJWTFilterTest { TestFilterChain chain = new TestFilterChain(); handler.doFilter(request, response, chain); - Assert.assertTrue("doFilterCalled should not be true.", chain.doFilterCalled == false); - Assert.assertTrue("No Subject should be returned.", chain.subject == null); + Assert.assertFalse("doFilterCalled should not be true.", chain.doFilterCalled); + Assert.assertNull("No Subject should be returned.", chain.subject); } catch (ServletException se) { fail("Should NOT have thrown a ServletException."); } http://git-wip-us.apache.org/repos/asf/knox/blob/28a77b72/gateway-provider-security-preauth/src/main/java/org/apache/knox/gateway/preauth/filter/PreAuthFederationFilter.java ---------------------------------------------------------------------- diff --git a/gateway-provider-security-preauth/src/main/java/org/apache/knox/gateway/preauth/filter/PreAuthFederationFilter.java b/gateway-provider-security-preauth/src/main/java/org/apache/knox/gateway/preauth/filter/PreAuthFederationFilter.java index 67e3a7c..be7783b 100644 --- a/gateway-provider-security-preauth/src/main/java/org/apache/knox/gateway/preauth/filter/PreAuthFederationFilter.java +++ b/gateway-provider-security-preauth/src/main/java/org/apache/knox/gateway/preauth/filter/PreAuthFederationFilter.java @@ -101,6 +101,7 @@ public class PreAuthFederationFilter implements Filter { primaryPrincipal = (PrimaryPrincipal) currentSubject.getPrincipals(PrimaryPrincipal.class).toArray()[0]; if (primaryPrincipal != null) { if (!primaryPrincipal.getName().equals(principal)) { + // TODO? } } } http://git-wip-us.apache.org/repos/asf/knox/blob/28a77b72/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/HeaderPreAuthFederationFilterTest.java ---------------------------------------------------------------------- diff --git a/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/HeaderPreAuthFederationFilterTest.java b/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/HeaderPreAuthFederationFilterTest.java index c018d0f..bdf3947 100644 --- a/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/HeaderPreAuthFederationFilterTest.java +++ b/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/HeaderPreAuthFederationFilterTest.java @@ -123,11 +123,7 @@ public class HeaderPreAuthFederationFilterTest extends org.junit.Assert { public boolean validate(HttpServletRequest httpRequest, FilterConfig filterConfig) throws PreAuthValidationException { String token = httpRequest.getHeader("CUSTOM_TOKEN"); - if (token.equalsIgnoreCase("HelloWorld")) { - return true; - } else { - return false; - } + return token.equalsIgnoreCase("HelloWorld"); } /** http://git-wip-us.apache.org/repos/asf/knox/blob/28a77b72/gateway-server/src/main/java/org/apache/knox/gateway/websockets/GatewayWebsocketHandler.java ---------------------------------------------------------------------- diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/websockets/GatewayWebsocketHandler.java b/gateway-server/src/main/java/org/apache/knox/gateway/websockets/GatewayWebsocketHandler.java index 6d51d76..0ff0ae2 100644 --- a/gateway-server/src/main/java/org/apache/knox/gateway/websockets/GatewayWebsocketHandler.java +++ b/gateway-server/src/main/java/org/apache/knox/gateway/websockets/GatewayWebsocketHandler.java @@ -216,8 +216,8 @@ public class GatewayWebsocketHandler extends WebSocketHandler URL serviceUrl = new URL(backendURL); /* Use http host:port if ws url not configured */ - final String protocol = (serviceUrl.getProtocol() == "ws" - || serviceUrl.getProtocol() == "wss") ? serviceUrl.getProtocol() + final String protocol = (serviceUrl.getProtocol().equals("ws") + || serviceUrl.getProtocol().equals("wss")) ? serviceUrl.getProtocol() : "ws"; backend.append(protocol).append("://"); backend.append(serviceUrl.getHost()).append(":"); http://git-wip-us.apache.org/repos/asf/knox/blob/28a77b72/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 44e4c1f..b976796 100644 --- a/pom.xml +++ b/pom.xml @@ -121,6 +121,7 @@ <!-- Dependencies sorted alphabetically --> <apacheds-version>2.0.0-M16</apacheds-version> + <checkstyle.version>8.12</checkstyle.version> <commons-beanutils-version>1.9.3</commons-beanutils-version> <failsafe-version>2.19.1</failsafe-version> <findsecbugs-plugin.version>1.8.0</findsecbugs-plugin.version> @@ -130,6 +131,7 @@ <jackson.version>2.9.5</jackson.version> <javax-websocket-version>1.1</javax-websocket-version> <jetty-version>9.2.25.v20180606</jetty-version> + <maven-checkstyle-plugin.version>3.0.0</maven-checkstyle-plugin.version> <metrics-version>3.1.2</metrics-version> <mockito-version>1.10.19</mockito-version> <shiro.version>1.2.6</shiro.version> @@ -442,7 +444,36 @@ </goals> </execution> </executions> - </plugin> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <version>${maven-checkstyle-plugin.version}</version> + <executions> + <execution> + <id>validate</id> + <phase>validate</phase> + <configuration> + <configLocation>${session.executionRootDirectory}/src/checkstyle/checker.xml</configLocation> + <suppressionsLocation>${session.executionRootDirectory}/src/checkstyle/suppressions.xml</suppressionsLocation> + <consoleOutput>true</consoleOutput> + <!--<headerLocation>${session.executionRootDirectory}/src/checkstyle/header.txt</headerLocation>--> + <failOnViolation>true</failOnViolation> + <includeTestSourceDirectory>true</includeTestSourceDirectory> + </configuration> + <goals> + <goal>check</goal> + </goals> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>com.puppycrawl.tools</groupId> + <artifactId>checkstyle</artifactId> + <version>${checkstyle.version}</version> + </dependency> + </dependencies> + </plugin> </plugins> </build> http://git-wip-us.apache.org/repos/asf/knox/blob/28a77b72/src/checkstyle/checker.xml ---------------------------------------------------------------------- diff --git a/src/checkstyle/checker.xml b/src/checkstyle/checker.xml new file mode 100644 index 0000000..8e87eb0 --- /dev/null +++ b/src/checkstyle/checker.xml @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> + +<!-- + This version of checkstyle is based on the Apache Calcite checkstyle + configuration, which in turn is based on Giraph, Hadoop, and + common-math configurations. + + The documentation for checkstyle is available at + + http://checkstyle.sourceforge.net +--> + +<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.1//EN" + "http://www.puppycrawl.com/dtds/configuration_1_1.dtd"> + +<!-- Calcite customization of default Checkstyle behavior --> +<module name="Checker"> + <property name="localeLanguage" value="en"/> + + <module name="TreeWalker"> + <property name="cacheFile" value="target/checkstyle-cachefile"/> + + <!-- Checks for blocks. You know, those {}'s --> + <!-- See http://checkstyle.sf.net/config_blocks.html --> + <!-- No empty blocks (i.e. catch); must contain at least a comment --> + <module name="EmptyBlock"> + <property name="option" value="text"/> + </module> + <module name="AvoidNestedBlocks"> + <property name="allowInSwitchCase" value="true"/> + </module> + + <!-- Checks for common coding problems --> + <!-- See http://checkstyle.sf.net/config_coding.html --> + <module name="EmptyStatement"/> + <!-- Require hash code override when equals is --> + <module name="EqualsHashCode"/> + <!-- Disallow unnecessary instantiation of Boolean, String --> + <!--<module name="IllegalInstantiation"> + <property name="classes" value="java.lang.Boolean, java.lang.String"/> + </module>--> + <!-- Switch statements should be complete and with independent cases --> + <!--<module name="FallThrough"/>--> + <module name="SimplifyBooleanExpression"/> + <module name="SimplifyBooleanReturn"/> + <!-- Only one statement per line allowed --> + <!--<module name="OneStatementPerLine"/>--> + <!-- Don't add up parentheses when they are not required --> + <!--<module name="UnnecessaryParentheses"/>--> + <!-- Don't use = or != for string comparisons --> + <module name="StringLiteralEquality"/> + <!-- Don't declare multiple variables in the same statement --> + <!--<module name="MultipleVariableDeclarations"/>--> + </module> +</module> http://git-wip-us.apache.org/repos/asf/knox/blob/28a77b72/src/checkstyle/suppressions.xml ---------------------------------------------------------------------- diff --git a/src/checkstyle/suppressions.xml b/src/checkstyle/suppressions.xml new file mode 100644 index 0000000..43f7677 --- /dev/null +++ b/src/checkstyle/suppressions.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE suppressions PUBLIC + "-//Puppy Crawl//DTD Suppressions 1.1//EN" + "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd"> +<!-- +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. +--> +<suppressions> + <suppress checks="Header" files=".*.properties"/> + <suppress checks=".*" files="log4j.properties"/> + + <!-- Suppress JavadocPackage in the test packages --> + <suppress checks="JavadocPackage" files="src[/\\]test[/\\]java[/\\]"/> +</suppressions> \ No newline at end of file
