Skip to content

Commit

Permalink
Removed duplicate UserAgent logic
Browse files Browse the repository at this point in the history
used okta-commons-lang ApplicationInfo instead
  • Loading branch information
bdemers committed Dec 14, 2018
1 parent 7e49165 commit e78d185
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 634 deletions.
4 changes: 4 additions & 0 deletions oauth2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<groupId>com.okta.commons</groupId>
<artifactId>okta-config-check</artifactId>
</dependency>
<dependency>
<groupId>com.okta.commons</groupId>
<artifactId>okta-commons-lang</artifactId>
</dependency>

<!-- security -->
<dependency>
Expand Down
485 changes: 0 additions & 485 deletions oauth2/src/main/java/com/okta/spring/boot/oauth/http/UserAgent.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,25 @@
*/
package com.okta.spring.boot.oauth.http;

import com.okta.commons.lang.ApplicationInfo;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.IOException;
import java.util.stream.Collectors;

public final class UserAgentRequestInterceptor implements ClientHttpRequestInterceptor {

private final static String USER_AGENT_VALUE = ApplicationInfo.get().entrySet().stream()
.map(e -> e.getKey() + "/" + e.getValue())
.collect(Collectors.joining(" "));

@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().add(HttpHeaders.USER_AGENT, UserAgent.getUserAgentString());
request.getHeaders().add(HttpHeaders.USER_AGENT, USER_AGENT_VALUE);
return execution.execute(request, body);
}
}
55 changes: 0 additions & 55 deletions oauth2/src/main/java/com/okta/spring/boot/oauth/http/Version.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
*/
package com.okta.spring.boot.oauth.http

import org.hamcrest.MatcherAssert
import org.mockito.ArgumentCaptor
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpRequest
import org.springframework.http.client.ClientHttpRequestExecution
import org.springframework.http.client.ClientHttpResponse
import org.testng.annotations.Test

import static org.hamcrest.Matchers.allOf
import static org.hamcrest.Matchers.containsString
import static org.hamcrest.Matchers.is
import static org.hamcrest.Matchers.matchesPattern
import static org.hamcrest.Matchers.not
import static org.mockito.ArgumentMatchers.eq
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.verify
import static org.mockito.Mockito.when
Expand All @@ -44,6 +49,17 @@ class UserAgentRequestInterceptorTest {
def underTest = new UserAgentRequestInterceptor()
assertThat underTest.intercept(request, null, execution), is(response)

verify(headers).add("User-Agent", UserAgent.userAgentString)
def userAgentCapture = ArgumentCaptor.forClass(String)

verify(headers).add(eq("User-Agent"), userAgentCapture.capture())
def userAgentString = userAgentCapture.getValue()
assertThat userAgentString, allOf(
matchesPattern(".*okta-spring-security/\\d.*"),
matchesPattern(".* spring/\\d.*"),
matchesPattern(".* spring-boot/\\d.*"),
containsString("java/${System.getProperty("java.version")}"),
containsString("${System.getProperty("os.name")}/${System.getProperty("os.version")}"),
not(containsString('${'))
)
}
}

This file was deleted.

This file was deleted.

8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<spring-cloud.version>2.0.2.RELEASE</spring-cloud.version>
<github.slug>okta/okta-spring-boot</github.slug>
<okta.sdk.version>1.3.0</okta.sdk.version>
<okta.commons.version>1.1.0</okta.commons.version>
</properties>

<modules>
Expand Down Expand Up @@ -106,7 +107,12 @@
<dependency>
<groupId>com.okta.commons</groupId>
<artifactId>okta-config-check</artifactId>
<version>1.0.0</version>
<version>${okta.commons.version}</version>
</dependency>
<dependency>
<groupId>com.okta.commons</groupId>
<artifactId>okta-commons-lang</artifactId>
<version>${okta.commons.version}</version>
</dependency>
<dependency>
<groupId>com.okta.oidc.tck</groupId>
Expand Down

0 comments on commit e78d185

Please sign in to comment.