From fd4a710685a63eb6797cbd0e13dd5bc25b9e2ebc Mon Sep 17 00:00:00 2001 From: Romain Bioteau Date: Tue, 31 Jan 2023 11:43:08 +0100 Subject: [PATCH] fix(auth): Use default auth port (#105) Always set a default auth port default value even when not specified in the configuration. Closes STUDIO-4444 --- pom.xml | 909 +++++++++--------- .../rest/AbstractRESTConnectorImpl.java | 3 +- .../connectors/rest/RESTConnectorTest.java | 67 +- .../{logback.xml => logback-test.xml} | 8 +- 4 files changed, 525 insertions(+), 462 deletions(-) rename src/test/resources/{logback.xml => logback-test.xml} (69%) diff --git a/pom.xml b/pom.xml index b0352ad..88d7b7a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,482 +1,495 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - org.bonitasoft.connectors - bonita-connector-rest - 1.3.1-SNAPSHOT + org.bonitasoft.connectors + bonita-connector-rest + 1.3.1-SNAPSHOT - Bonita Rest Connector - Rest Connector for Bonita - https://www.bonitasoft.com + Bonita Rest Connector + Rest Connector for Bonita + https://www.bonitasoft.com - - - bonitasoft - Bonitasoft - rd.user@bonitasoft.com - Bonitasoft - https://www.bonitasoft.com - - + + + bonitasoft + Bonitasoft + rd.user@bonitasoft.com + Bonitasoft + https://www.bonitasoft.com + + - - - GPL-v2.0 - http://www.gnu.org/licenses/gpl-2.0.txt - - + + + GPL-v2.0 + http://www.gnu.org/licenses/gpl-2.0.txt + + - - - 11 - UTF-8 - UTF-8 - yyyy.MM.dd-hh.mm + + + 11 + UTF-8 + UTF-8 + yyyy.MM.dd-hh.mm - - rest-head - 1.0.0 - ${head.def.id}-impl - ${project.version} - org.bonitasoft.connectors.rest.HeadConnectorImpl + + rest-head + 1.0.0 + ${head.def.id}-impl + ${project.version} + org.bonitasoft.connectors.rest.HeadConnectorImpl - - rest-get - 1.2.0 - ${get.def.id}-impl - ${project.version} - org.bonitasoft.connectors.rest.GetConnectorImpl + + rest-get + 1.2.0 + ${get.def.id}-impl + ${project.version} + org.bonitasoft.connectors.rest.GetConnectorImpl - - rest-post - 1.3.0 - ${post.def.id}-impl - ${project.version} - org.bonitasoft.connectors.rest.PostConnectorImpl + + rest-post + 1.3.0 + ${post.def.id}-impl + ${project.version} + org.bonitasoft.connectors.rest.PostConnectorImpl - - rest-file-post - 1.0.0 - ${file-post.def.id}-impl - ${project.version} - org.bonitasoft.connectors.rest.PostConnectorImpl + + rest-file-post + 1.0.0 + ${file-post.def.id}-impl + ${project.version} + org.bonitasoft.connectors.rest.PostConnectorImpl - - rest-put - 1.3.0 - ${put.def.id}-impl - ${project.version} - org.bonitasoft.connectors.rest.PutConnectorImpl + + rest-put + 1.3.0 + ${put.def.id}-impl + ${project.version} + org.bonitasoft.connectors.rest.PutConnectorImpl - - rest-file-put - 1.0.0 - ${file-put.def.id}-impl - ${project.version} - org.bonitasoft.connectors.rest.PutConnectorImpl + + rest-file-put + 1.0.0 + ${file-put.def.id}-impl + ${project.version} + org.bonitasoft.connectors.rest.PutConnectorImpl - - rest-delete - 1.2.0 - ${delete.def.id}-impl - ${project.version} - org.bonitasoft.connectors.rest.DeleteConnectorImpl + + rest-delete + 1.2.0 + ${delete.def.id}-impl + ${project.version} + org.bonitasoft.connectors.rest.DeleteConnectorImpl - - 1.2 - 1.15 + + 1.2 + 1.15 - - 7.13.0 + + 7.15.0 - - 1.10.19 - 2.35.0 - 3.24.2 - 4.13.2 - 0.8.8 - 3.9.1.2184 - 1.17.6 - 0.0.10 - 4.2.0 + + 1.10.19 + + + 2.31.0 + 3.24.2 + 4.13.2 + 0.8.8 + 3.9.1.2184 + 1.17.6 + 0.0.10 + 4.2.0 + 1.7.36 - - 3.10.1 - ${java.version} - 3.4.2 - 2.1.1 - 3.0.14 - 3.0.0-M8 - 3.0.0-M8 - 1.6.13 - 3.4.1 - 3.2.1 + + 3.10.1 + ${java.version} + 3.4.2 + 2.1.1 + 3.0.14 + 3.0.0-M8 + 3.0.0-M8 + 1.6.13 + 3.4.1 + 3.2.1 - - bonitasoft_bonita-connector-rest - bonitasoft - https://sonarcloud.io - + + bonitasoft_bonita-connector-rest + bonitasoft + https://sonarcloud.io + - - - - org.bonitasoft.runtime - bonita-runtime-bom - ${bonita.engine.version} - pom - import - - - com.fasterxml.jackson.core - jackson-core - provided - - - org.testcontainers - testcontainers-bom - ${testcontainers.version} - pom - import - - - + + + + org.bonitasoft.runtime + bonita-runtime-bom + ${bonita.engine.version} + pom + import + + + com.fasterxml.jackson.core + jackson-core + provided + + + org.testcontainers + testcontainers-bom + ${testcontainers.version} + pom + import + + + - - - - bonita-common - org.bonitasoft.engine - provided - + + + + bonita-common + org.bonitasoft.engine + provided + - - - commons-logging - commons-logging - ${commons-logging.version} - provided - - - commons-codec - commons-codec - ${commons-codec.version} - provided - - - commons-io - commons-io - provided - - - org.apache.httpcomponents - httpclient - provided - + + + commons-logging + commons-logging + ${commons-logging.version} + provided + + + commons-codec + commons-codec + ${commons-codec.version} + provided + + + commons-io + commons-io + provided + + + org.apache.httpcomponents + httpclient + provided + - - - junit - junit - ${junit.version} - test - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.mockito - mockito-all - ${mockito.version} - test - - - com.github.tomakehurst - wiremock-jre8 - ${wiremock.version} - test - - - ch.qos.logback - logback-classic - 1.2.11 - test - - - org.testcontainers - testcontainers - test - - - org.bonitasoft.web - bonita-java-client - ${bonita-java-client.version} - test - - - org.awaitility - awaitility - ${awaitility.version} - test - - + + + junit + junit + ${junit.version} + test + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.mockito + mockito-all + ${mockito.version} + test + + + com.github.tomakehurst + wiremock-jre8 + ${wiremock.version} + test + + + ch.qos.logback + logback-classic + 1.2.11 + test + + + org.slf4j + jul-to-slf4j + ${jul-to-slf4j.version} + test + + + org.testcontainers + testcontainers + test + + + org.bonitasoft.web + bonita-java-client + ${bonita-java-client.version} + test + + + org.awaitility + awaitility + ${awaitility.version} + test + + - - verify - - - src/main/resources-filtered - true - - - src/main/resources - false - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - org.apache.maven.plugins - maven-failsafe-plugin - ${maven-failsafe-plugin.version} - - - maven-assembly-plugin - ${maven-assembly-plugin.version} - - ${project.basedir}/src/assembly - - - - package-connectors - package - - single - - - true - - - - - - org.codehaus.gmaven - groovy-maven-plugin - ${groovy-maven-plugin.version} - - - org.codehaus.groovy - groovy - ${groovy.version} - - - - - org.jacoco - jacoco-maven-plugin - ${jacoco-maven-plugin.version} - - true - - - - prepare-agent - - prepare-agent - - - - prepare-agent-integration - - prepare-agent-integration - - - - jacoco-site - verify - - report - - - - - - org.sonarsource.scanner.maven - sonar-maven-plugin - ${sonar-maven-plugin.version} - - - org.sonatype.plugins - nexus-staging-maven-plugin - ${nexus-staging-maven-plugin.version} - true - - ossrh - https://oss.sonatype.org/ - false - - - - + + verify + + + src/main/resources-filtered + true + + + src/main/resources + false + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + org.apache.maven.plugins + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + + + maven-assembly-plugin + ${maven-assembly-plugin.version} + + + ${project.basedir}/src/assembly + + + + package-connectors + package + + single + + + true + + + + + + org.codehaus.gmaven + groovy-maven-plugin + ${groovy-maven-plugin.version} + + + org.codehaus.groovy + groovy + ${groovy.version} + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco-maven-plugin.version} + + true + + + + prepare-agent + + prepare-agent + + + + prepare-agent-integration + + prepare-agent-integration + + + + jacoco-site + verify + + report + + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + ${sonar-maven-plugin.version} + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + ossrh + https://oss.sonatype.org/ + false + + + + - - - org.codehaus.gmaven - groovy-maven-plugin - - - generate-resources - - execute - - - ${project.basedir}/src/script/dependencies-as-var.groovy - - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - org.jacoco - jacoco-maven-plugin - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin.version} - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - integration-tests-7.13 - - integration-test - - - - 7.13.0 - - - - - integration-tests-7.14 - - integration-test - - - - 7.14.0 - - - - - - verify - - - - - - + + + org.codehaus.gmaven + groovy-maven-plugin + + + generate-resources + + execute + + + + ${project.basedir}/src/script/dependencies-as-var.groovy + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + org.jacoco + jacoco-maven-plugin + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + integration-tests-7.13 + + integration-test + + + + 7.13.0 + + + + + integration-tests-7.14 + + integration-test + + + + 7.14.0 + + + + + + verify + + + + + + - - - - deploy - - - - - org.apache.maven.plugins - maven-gpg-plugin - 3.0.1 - - - sign-artifacts - verify - - sign - - - - - --pinentry-mode - loopback - - - - - - - - - + + + + deploy + + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.0.1 + + + sign-artifacts + verify + + sign + + + + + --pinentry-mode + loopback + + + + + + + + + - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + - - scm:git:git@github.com:bonitasoft/bonita-connector-rest.git - scm:git:git@github.com:bonitasoft/bonita-connector-rest.git - https://github.com/bonitasoft/bonita-connector-rest - HEAD - + + + scm:git:git@github.com:bonitasoft/bonita-connector-rest.git + scm:git:git@github.com:bonitasoft/bonita-connector-rest.git + https://github.com/bonitasoft/bonita-connector-rest + HEAD + diff --git a/src/main/java/org/bonitasoft/connectors/rest/AbstractRESTConnectorImpl.java b/src/main/java/org/bonitasoft/connectors/rest/AbstractRESTConnectorImpl.java index a856f7d..86da44e 100644 --- a/src/main/java/org/bonitasoft/connectors/rest/AbstractRESTConnectorImpl.java +++ b/src/main/java/org/bonitasoft/connectors/rest/AbstractRESTConnectorImpl.java @@ -183,7 +183,8 @@ protected final String getAuthHost() { } protected final Integer getAuthPort() { - return (Integer) getInputParameter(AUTH_PORT_INPUT_PARAMETER); + Integer port = (Integer) getInputParameter(AUTH_PORT_INPUT_PARAMETER); + return port == null ? -1 : port; } protected final String getAuthRealm() { diff --git a/src/test/java/org/bonitasoft/connectors/rest/RESTConnectorTest.java b/src/test/java/org/bonitasoft/connectors/rest/RESTConnectorTest.java index 50c6f8f..af500cf 100644 --- a/src/test/java/org/bonitasoft/connectors/rest/RESTConnectorTest.java +++ b/src/test/java/org/bonitasoft/connectors/rest/RESTConnectorTest.java @@ -55,6 +55,7 @@ import java.util.Map; import org.apache.http.HttpStatus; +import org.apache.http.auth.AUTH; import org.apache.http.client.ClientProtocolException; import org.apache.http.entity.ContentType; import org.bonitasoft.connectors.rest.model.AuthorizationType; @@ -71,6 +72,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mockito; +import org.slf4j.bridge.SLF4JBridgeHandler; import com.github.tomakehurst.wiremock.client.MappingBuilder; import com.github.tomakehurst.wiremock.client.WireMock; @@ -79,6 +81,10 @@ /** The class for the UTs of the REST Connector */ public class RESTConnectorTest extends AcceptanceTestBase { + static { + SLF4JBridgeHandler.install(); + } + private static final int NB_OUTPUTS = 5; // WireMock @@ -87,7 +93,6 @@ public class RESTConnectorTest extends AcceptanceTestBase { private static final String WM_CHARSET = "charset"; private static final String WM_COOKIES = "Cookie"; - private static final String WM_AUTHORIZATION = "Authorization"; // METHODS /** All the tested method values */ @@ -138,9 +143,6 @@ public class RESTConnectorTest extends AcceptanceTestBase { /** All the tested SSL verifier values */ private static final String STRICT = "Strict"; - // AUTHORIZATIONS - /** All the tested authorization values */ - private static final String BASIC_RULE = "Basic"; private static final String USERNAME = "username"; private static final String PASSWORD = "password"; @@ -747,7 +749,8 @@ private Map buildBodyParametersSet(final String body) { * @param preemptive Preemptive * @return The set of parameters */ - private Map buildBasicAuthorizationParametersSet( + private Map buildAuthorizationParametersSet( + AuthorizationType type, final String username, final String password, final String host, @@ -768,7 +771,7 @@ private Map buildBasicAuthorizationParametersSet( STRICT); parametersSet.put( - AbstractRESTConnectorImpl.AUTH_TYPE_PARAMETER, AuthorizationType.BASIC.name()); + AbstractRESTConnectorImpl.AUTH_TYPE_PARAMETER, type.name()); parametersSet.put(AbstractRESTConnectorImpl.AUTH_USERNAME_INPUT_PARAMETER, username); parametersSet.put(AbstractRESTConnectorImpl.AUTH_PASSWORD_INPUT_PARAMETER, password); parametersSet.put(AbstractRESTConnectorImpl.AUTH_HOST_INPUT_PARAMETER, host); @@ -1536,11 +1539,39 @@ public void notEmptyBody() throws BonitaException { public void basicAuthWithUsernameAndPassword() throws BonitaException { stubFor( get(urlEqualTo("/")) - .withHeader(WM_AUTHORIZATION, containing(BASIC_RULE)) + .willReturn(aResponse() + .withHeader(AUTH.WWW_AUTH, "Basic") + .withStatus(HttpStatus.SC_UNAUTHORIZED))); + + stubFor( + get(urlEqualTo("/")) + .withBasicAuth(USERNAME, PASSWORD) + .willReturn(aResponse().withStatus(HttpStatus.SC_OK))); + checkResultIsPresent( + executeConnector( + buildAuthorizationParametersSet(AuthorizationType.BASIC, USERNAME, PASSWORD, EMPTY, EMPTY, Boolean.TRUE))); + } + + @Test + public void digestAuthWithUsernameAndPassword() throws BonitaException { + // 401 with digest challenge + stubFor( + get(urlEqualTo("/")) + .willReturn(aResponse() + .withHeader(AUTH.WWW_AUTH, "Digest realm=\"*\",qop=\"auth,auth-int\",nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\"") + .withStatus(HttpStatus.SC_UNAUTHORIZED))); + + // http client resolving the challenge + stubFor( + get(urlEqualTo("/")) + .withHeader("Authorization", containing("Digest username=\"username\"") + .and(containing("realm=\"*\"")) + .and(containing("algorithm=MD5"))) .willReturn(aResponse().withStatus(HttpStatus.SC_OK))); + checkResultIsPresent( executeConnector( - buildBasicAuthorizationParametersSet(USERNAME, PASSWORD, EMPTY, EMPTY, Boolean.TRUE))); + buildAuthorizationParametersSet(AuthorizationType.DIGEST, USERNAME, PASSWORD, EMPTY, EMPTY, Boolean.TRUE))); } /** @@ -1553,12 +1584,18 @@ public void basicAuthWithUsernameAndPassword() throws BonitaException { public void basicAuthWithUsernamePasswordAndLocalhost() throws BonitaException { stubFor( get(urlEqualTo("/")) - .withHeader(WM_AUTHORIZATION, containing(BASIC_RULE)) + .willReturn(aResponse() + .withHeader(AUTH.WWW_AUTH, "Basic") + .withStatus(HttpStatus.SC_UNAUTHORIZED))); + + stubFor( + get(urlEqualTo("/")) + .withBasicAuth(USERNAME, PASSWORD) .willReturn(aResponse().withStatus(HttpStatus.SC_OK))); checkResultIsPresent( executeConnector( - buildBasicAuthorizationParametersSet(USERNAME, PASSWORD, HOST, EMPTY, Boolean.TRUE))); + buildAuthorizationParametersSet(AuthorizationType.BASIC, USERNAME, PASSWORD, HOST, EMPTY, Boolean.TRUE))); } /** @@ -1571,12 +1608,18 @@ public void basicAuthWithUsernamePasswordAndLocalhost() throws BonitaException { public void basicAuthWithUsernamePasswordAndRealm() throws BonitaException { stubFor( get(urlEqualTo("/")) - .withHeader(WM_AUTHORIZATION, containing(BASIC_RULE)) + .willReturn(aResponse() + .withHeader(AUTH.WWW_AUTH, "Basic realm=realm") + .withStatus(HttpStatus.SC_UNAUTHORIZED))); + + stubFor( + get(urlEqualTo("/")) + .withBasicAuth(USERNAME, PASSWORD) .willReturn(aResponse().withStatus(HttpStatus.SC_OK))); checkResultIsPresent( executeConnector( - buildBasicAuthorizationParametersSet(USERNAME, PASSWORD, EMPTY, REALM, Boolean.TRUE))); + buildAuthorizationParametersSet(AuthorizationType.BASIC, USERNAME, PASSWORD, EMPTY, REALM, Boolean.TRUE))); } /** diff --git a/src/test/resources/logback.xml b/src/test/resources/logback-test.xml similarity index 69% rename from src/test/resources/logback.xml rename to src/test/resources/logback-test.xml index cf6644a..c296cb3 100644 --- a/src/test/resources/logback.xml +++ b/src/test/resources/logback-test.xml @@ -1,5 +1,9 @@ + + true + + @@ -7,9 +11,11 @@ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - + + + \ No newline at end of file