Skip to content

Commit

Permalink
Removed parallel auth from certificate-based auth
Browse files Browse the repository at this point in the history
Minor upgrades of libraries
  • Loading branch information
Yong Sheng Tan committed Oct 21, 2019
1 parent 12969fe commit e269f9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 60 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.symphony.platformsolutions</groupId>
<artifactId>symphony-api-client-java</artifactId>
<version>1.0.43-SNAPSHOT</version>
<version>1.0.44</version>
<name>Symphony API Client</name>
<url>https://github.com/SymphonyPlatformSolutions/symphony-api-client-java</url>
<description>Symphony API Client provided by Symphony Platform Solutions team</description>
Expand Down Expand Up @@ -34,10 +34,10 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jjwt.version>0.9.1</jjwt.version>
<commons-codec.version>1.12</commons-codec.version>
<commons-codec.version>1.13</commons-codec.version>
<commons-io.version>2.6</commons-io.version>
<jersey.version>2.29</jersey.version>
<slf4j.version>1.7.26</slf4j.version>
<jersey.version>2.29.1</jersey.version>
<slf4j.version>1.7.28</slf4j.version>
</properties>

<build>
Expand Down Expand Up @@ -147,7 +147,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.10</version>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -224,7 +224,7 @@
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>2.23.2</version>
<version>2.25.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
59 changes: 5 additions & 54 deletions src/main/java/authentication/SymBotAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import clients.symphony.api.constants.CommonConstants;
import configuration.SymConfig;
import exceptions.AuthenticationException;
import java.util.concurrent.*;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;
Expand Down Expand Up @@ -32,16 +32,8 @@ public SymBotAuth(SymConfig config) {

this.sessionAuthClient = client;
this.kmAuthClient = client;

ClientConfig clientConfig = HttpClientBuilderHelper.getPodClientConfig(config);
if (clientConfig != null) {
this.sessionAuthClient = clientBuilder.withConfig(clientConfig).build();
}

ClientConfig kmClientConfig = HttpClientBuilderHelper.getKMClientConfig(config);
if (kmClientConfig != null) {
this.kmAuthClient = clientBuilder.withConfig(kmClientConfig).build();
}
this.sessionAuthClient = clientBuilder.withConfig(HttpClientBuilderHelper.getPodClientConfig(config)).build();
this.kmAuthClient = clientBuilder.withConfig(HttpClientBuilderHelper.getKMClientConfig(config)).build();
}

public SymBotAuth(final SymConfig inputConfig,
Expand Down Expand Up @@ -70,49 +62,8 @@ public SymBotAuth(final SymConfig inputConfig,
@Override
public void authenticate() throws AuthenticationException {
if (lastAuthTime == 0 || System.currentTimeMillis() - lastAuthTime > AuthEndpointConstants.WAIT_TIME) {
ExecutorService executor = Executors.newFixedThreadPool(2);
Future<AuthenticationException> sessionAuthFuture = executor.submit(() -> {
try {
sessionAuthenticate();
return null;
} catch (AuthenticationException e) {
return e;
}
});
Future<AuthenticationException> kmAuthFuture = executor.submit(() -> {
try {
kmAuthenticate();
return null;
} catch (AuthenticationException e) {
return e;
}
});
executor.shutdown();

try {
int connectionTimeout = config.getConnectionTimeout();
if (connectionTimeout == 0) {
connectionTimeout = 35000;
}
executor.awaitTermination(connectionTimeout, TimeUnit.MILLISECONDS);
executor.shutdownNow();
if (!executor.isTerminated()) {
throw new AuthenticationException(new Exception("Timeout"));
}
} catch (InterruptedException e) {
throw new RuntimeException("Termination Interrupted");
}

try {
if (sessionAuthFuture.get() != null) {
throw sessionAuthFuture.get();
}
if (kmAuthFuture.get() != null) {
throw kmAuthFuture.get();
}
} catch (InterruptedException | ExecutionException e) {
logger.error("Interrupted Exception");
}
sessionAuthenticate();
kmAuthenticate();

lastAuthTime = System.currentTimeMillis();
} else {
Expand Down

0 comments on commit e269f9c

Please sign in to comment.