Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel-608 committed Jun 20, 2024
1 parent 9f1e6d5 commit 770125a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 36 deletions.
23 changes: 4 additions & 19 deletions common-authentication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>

<dependency>
Expand All @@ -33,9 +29,8 @@
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>

<dependency>
Expand All @@ -48,16 +43,6 @@
<artifactId>alfresco-hxinsight-connector-common-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock.integrations.testcontainers</groupId>
<artifactId>wiremock-testcontainers-module</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import static com.github.tomakehurst.wiremock.client.WireMock.serverError;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static org.apache.hc.core5.http.ContentType.APPLICATION_FORM_URLENCODED;
import static org.apache.http.HttpHeaders.CONTENT_LENGTH;
import static org.apache.http.HttpHeaders.CONTENT_TYPE;
import static org.apache.http.HttpHeaders.HOST;
import static org.apache.hc.core5.http.HttpHeaders.CONTENT_LENGTH;
import static org.apache.hc.core5.http.HttpHeaders.CONTENT_TYPE;
import static org.apache.hc.core5.http.HttpHeaders.HOST;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.BDDMockito.then;
Expand All @@ -49,7 +49,7 @@
import com.github.tomakehurst.wiremock.matching.EqualToPattern;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.http.HttpStatus;
import org.apache.hc.core5.http.HttpStatus;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.SpyBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
*/
package org.alfresco.hxi_connector.common.adapters.auth;

import static org.apache.hc.core5.http.HttpHeaders.AUTHORIZATION;

import java.util.Base64;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.Exchange;
import org.springframework.http.HttpHeaders;

import org.alfresco.hxi_connector.common.adapters.auth.config.properties.AuthProperties;

Expand All @@ -52,7 +53,7 @@ public void setAlfrescoAuthorizationHeaders(Exchange exchange)
String authType = authProvider.getType();
String authHeaderValue = getAlfrescoAuthHeaderValue(accessTokenProvider, authProvider);
clearAuthHeaders(exchange);
exchange.getIn().setHeader(HttpHeaders.AUTHORIZATION, authHeaderValue);
exchange.getIn().setHeader(AUTHORIZATION, authHeaderValue);
log.debug("Authorization :: {} {} authorization header added", ALFRESCO_AUTH_PROVIDER, authType);
}

Expand All @@ -62,7 +63,7 @@ public void setHxIAuthorizationHeaders(Exchange exchange)
AuthProperties.AuthProvider authProvider = authProperties.getProviders().get(HXI_AUTH_PROVIDER);
String authHeaderValue = BEARER + token;
clearAuthHeaders(exchange);
exchange.getIn().setHeader(HttpHeaders.AUTHORIZATION, authHeaderValue);
exchange.getIn().setHeader(AUTHORIZATION, authHeaderValue);
exchange.getIn().setHeader(ENVIRONMENT_KEY_HEADER, authProvider.getEnvironmentKey());
log.debug("Authorization :: {} authorization header added", HXI_AUTH_PROVIDER);
}
Expand All @@ -87,7 +88,7 @@ private static String getBasicAuthenticationHeader(AuthProperties.AuthProvider a

private static void clearAuthHeaders(Exchange exchange)
{
exchange.getIn().removeHeader(HttpHeaders.AUTHORIZATION);
exchange.getIn().removeHeader(AUTHORIZATION);
exchange.getIn().removeHeader(ENVIRONMENT_KEY_HEADER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.apache.logging.log4j.util.Strings;
import org.springframework.util.CollectionUtils;

@AllArgsConstructor
Expand All @@ -56,19 +56,19 @@ public List<NameValuePair> getTokenRequestBody()
form.add(new BasicNameValuePair("grant_type", this.grantType));
form.add(new BasicNameValuePair("client_id", this.clientId));

if (Strings.isNotBlank(this.clientSecret))
if (StringUtils.isNotBlank(this.clientSecret))
{
form.add(new BasicNameValuePair("client_secret", this.clientSecret));
}
if (!CollectionUtils.isEmpty(this.scope))
{
form.add(new BasicNameValuePair("scope", String.join(",", this.scope)));
}
if (Strings.isNotBlank(this.username))
if (StringUtils.isNotBlank(this.username))
{
form.add(new BasicNameValuePair("username", this.username));
}
if (Strings.isNotBlank(this.password))
if (StringUtils.isNotBlank(this.password))
{
form.add(new BasicNameValuePair("password", this.password));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
package org.alfresco.hxi_connector.common.adapters.auth;

import static org.apache.hc.core5.http.HttpHeaders.AUTHORIZATION;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
Expand All @@ -43,7 +44,6 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpHeaders;

import org.alfresco.hxi_connector.common.adapters.auth.config.properties.AuthProperties;

Expand Down Expand Up @@ -86,7 +86,7 @@ void givenValidBearerToken_whenSetAlfrescoAuthorizationHeaders_thenBearerHeaderI

// then
thenExpectedAuthHeadersCleared();
then(mockExchange.getIn()).should().setHeader(HttpHeaders.AUTHORIZATION, AuthService.BEARER + VALID_TOKEN);
then(mockExchange.getIn()).should().setHeader(AUTHORIZATION, AuthService.BEARER + VALID_TOKEN);
}

@Test
Expand All @@ -105,7 +105,7 @@ void givenBasicAlfrescoAuthProvided_whenSetAlfrescoAuthorizationHeaders_thenBasi

// then
thenExpectedAuthHeadersCleared();
then(mockExchange.getIn()).should().setHeader(HttpHeaders.AUTHORIZATION, AuthService.BASIC + getEncodedCredentials(username, password));
then(mockExchange.getIn()).should().setHeader(AUTHORIZATION, AuthService.BASIC + getEncodedCredentials(username, password));
}

@Test
Expand All @@ -122,7 +122,7 @@ void givenValidBearerToken_whenSetHxIAuthorizationHeaders_thenHeadersAreSet()

// then
thenExpectedAuthHeadersCleared();
then(mockExchange.getIn()).should().setHeader(HttpHeaders.AUTHORIZATION, AuthService.BEARER + VALID_TOKEN);
then(mockExchange.getIn()).should().setHeader(AUTHORIZATION, AuthService.BEARER + VALID_TOKEN);
then(mockExchange.getIn()).should().setHeader(ENVIRONMENT_KEY_HEADER, dummyEnvKey);
}

Expand All @@ -134,7 +134,7 @@ private static String getEncodedCredentials(String username, String password)

private void thenExpectedAuthHeadersCleared()
{
then(mockExchange.getIn()).should().removeHeader(HttpHeaders.AUTHORIZATION);
then(mockExchange.getIn()).should().removeHeader(AUTHORIZATION);
then(mockExchange.getIn()).should().removeHeader(ENVIRONMENT_KEY_HEADER);
}
}
4 changes: 4 additions & 0 deletions live-ingester/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>

<dependency>
<groupId>org.apache.camel.springboot</groupId>
Expand Down

0 comments on commit 770125a

Please sign in to comment.