Skip to content

Commit

Permalink
update documentation about how to configure a proxy server (#70)
Browse files Browse the repository at this point in the history
* update documentation about how to configure a proxy server
* fix to issue 69

Co-authored-by: Juhan Aasaru <[email protected]>
  • Loading branch information
aasaru and aasaru authored Sep 12, 2022
1 parent b7d62bf commit 0736c82
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 81 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [2.2.1] - 2022-09-12

### Fixed
- added jakarta.ws.rs:jakarta.ws.rs-api as a dependency to avoid ClassNotFoundException with spring framework

### Changed
- Updated dependencies

### Changes in tests and documentation
- How to use a proxy server - added documentation to README.md and tests to ReadmeTest.java

## [2.2] - 2022-02-22

### Changed
Expand Down
64 changes: 43 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,34 @@ For using Smart-ID API v. 1.0 see [Smart-ID Java Client 1.X](https://github.com/
* [Requirements](#requirements)
* [Getting the library](#getting-the-library)
* [Changelog](#changelog)
* [How to use it](#how-to-use-it)
* [Test accounts for testing]()
* [Logging](#logging)
* [How to use it](#how-to-use-it)
* [Test accounts for testing]()
* [Logging](#logging)
* [Log request payloads](#log-request-payloads)
* [Get the IP address of user's device](#get-the-ip-address-of-users-device)
* [Example of configuring the client](#example-of-configuring-the-client)
* [Example of configuring the client](#example-of-configuring-the-client)
* [Reading trusted certificates from key store](#reading-trusted-certificates-from-key-store)
* [Feeding trusted certificates one by one](#feeding-trusted-certificates-one-by-one)
* [Examples of performing authentication](#examples-of-performing-authentication)
* [Examples of performing authentication](#examples-of-performing-authentication)
* [Authenticating with semantics identifier](#authenticating-with-semantics-identifier)
* [Authenticating with document number](#authenticating-with-document-number)
* [Validating authentication response](#validating-authentication-response)
* [Creating a signature](#creating-a-signature)
* [Creating a signature](#creating-a-signature)
* [Obtaining signer's certificate](#obtaining-signers-certificate)
* [Create the signature](#create-the-signature)
* [Setting the order of preferred interactions for displaying text and asking PIN](#setting-the-order-of-preferred-interactions-for-displaying-text-and-asking-pin)
* [Setting the order of preferred interactions for displaying text and asking PIN](#setting-the-order-of-preferred-interactions-for-displaying-text-and-asking-pin)
* [Parameter allowedInteractionsOrder most common examples](#parameter-allowedinteractionsorder-most-common-examples)
* [Short confirmation message with PIN](#short-confirmation-message-with-pin)
* [Verification code choice](#verification-code-choice)
* [Long confirmation message with fallback to PIN](#long-confirmation-message-with-fallback-to-pin)
* [Long confirmation message together with verification code choice with fallback to verification code choice](#long-confirmation-message-together-with-verification-code-choice-with-fallback-to-verification-code-choice)
* [Interactions with longer text without fallback](#interactions-with-longer-text-without-fallback)
* [Handling exceptions](#handling-exceptions)
* [Network connection configuration of the client](#network-connection-configuration-of-the-client)
* [Handling exceptions](#handling-exceptions)
* [Network connection configuration of the client](#network-connection-configuration-of-the-client)
* [Example of creating a client with configured ssl context on JBoss using JAXWS RS](#example-of-creating-a-client-with-configured-ssl-context-on-jboss-using-jaxws-rs)
* [Example of creating a client with configured proxy on JBoss](#example-of-creating-a-client-with-configured-ssl-context-on-jboss-using-jaxws-rs)

* [Configuring a proxy](#configuring-a-proxy)
* [Configuring a proxy using JBoss Resteasy library](#configuring-a-proxy-using-jboss-resteasy-library)
* [Configuring a proxy using Jersey](#configuring-a-proxy-using-jersey)

## Introduction

Expand Down Expand Up @@ -560,19 +561,40 @@ client.setHostUrl("https://sid.demo.sk.ee/smart-id-rp/v2/");
client.setConfiguredClient(resteasyClient);
```

## Configuring a proxy

### Example of creating a client with configured proxy on JBoss
If you need to access the internet through a proxy (that runs on 127.0.0.1:3128 in the examples)
you have two alternatives:

### Configuring a proxy using JBoss Resteasy library

<!-- Do not change code samples here but instead copy from ReadmeTest.document_setProxy_withJbossRestEasy() -->
```java
ResteasyClient resteasyClient = new ResteasyClientBuilder()
.defaultProxy("localhost", 8080, "http")
.build();
org.jboss.resteasy.client.jaxrs.ResteasyClient resteasyClient =
new org.jboss.resteasy.client.jaxrs.internal.ResteasyClientBuilderImpl()
.defaultProxy("127.0.0.1", 3128, "http")
.build();
SmartIdClient client = new SmartIdClient();
client.setRelyingPartyUUID("00000000-0000-0000-0000-000000000000");
client.setRelyingPartyName("DEMO");
client.setHostUrl("https://sid.demo.sk.ee/smart-id-rp/v2/");
client.setConfiguredClient(resteasyClient);
client.setTrustedCertificates(DEMO_HOST_SSL_CERTIFICATE);
```

SmartIdClient client = new SmartIdClient();
client.setRelyingPartyUUID("00000000-0000-0000-0000-000000000000");
client.setRelyingPartyName("DEMO");
client.setHostUrl("https://sid.demo.sk.ee/smart-id-rp/v2/");
client.setConfiguredClient(resteasyClient);
### Example of creating a client with configured proxy on JBoss

<!-- Do not change code samples here but instead copy from ReadmeTest.document_setNetworkConnectionConfig_withJersey()-->
```java
org.glassfish.jersey.client.ClientConfig clientConfig =
new org.glassfish.jersey.client.ClientConfig();
clientConfig.property(ClientProperties.PROXY_URI, "http://127.0.0.1:3128");

SmartIdClient client = new SmartIdClient();
client.setRelyingPartyUUID("00000000-0000-0000-0000-000000000000");
client.setRelyingPartyName("DEMO");
client.setHostUrl("https://sid.demo.sk.ee/smart-id-rp/v2/");
client.setNetworkConnectionConfig(clientConfig);
client.setTrustedCertificates(DEMO_HOST_SSL_CERTIFICATE);
```


44 changes: 29 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jackson.version>2.13.1</jackson.version>
<jersey.version>3.0.4</jersey.version>
<jackson.version>2.13.3</jackson.version>
<jersey.version>3.0.6</jersey.version>
<rs-api.version>3.0.0</rs-api.version>
<resteasy.version>6.0.3.Final</resteasy.version>
</properties>

<dependencies>
Expand All @@ -65,6 +67,13 @@
<artifactId>jersey-hk2</artifactId>
<version>${jersey.version}</version>
</dependency>

<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>${rs-api.version}</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
Expand Down Expand Up @@ -93,9 +102,17 @@
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>3.0.1</version>
<version>4.0.0</version>
</dependency>


<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.70</version>
</dependency>


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -111,38 +128,35 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.10</version>
<version>1.2.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.4.1</version>
<version>2.27.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.3.1</version>
<version>4.7.0</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.69</version>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${resteasy.version}</version>
<scope>test</scope>
</dependency>

<!-- comment in if you want to configure client with RestEasy in tests
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.12.0.Final</version>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${resteasy.version}</version>
<scope>test</scope>
<optional>true</optional>
</dependency>
-->

</dependencies>

Expand Down
26 changes: 13 additions & 13 deletions src/test/java/ee/sk/smartid/rest/SmartIdRestIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public void setUp() {
public void getCertificateAndSignHash() throws Exception {
CertificateChoiceResponse certificateChoiceResponse = fetchCertificateChoiceSession(DOCUMENT_NUMBER_LT);

SessionStatus sessionStatus = pollSessionStatus(certificateChoiceResponse.getSessionID());
SessionStatus sessionStatus = pollSessionStatus(certificateChoiceResponse.getSessionID(), connector);
assertCertificateChosen(sessionStatus);

String documentNumber = sessionStatus.getResult().getDocumentNumber();
SignatureSessionResponse signatureSessionResponse = createRequestAndFetchSignatureSession(documentNumber);
sessionStatus = pollSessionStatus(signatureSessionResponse.getSessionID());
sessionStatus = pollSessionStatus(signatureSessionResponse.getSessionID(), connector);
assertSignatureCreated(sessionStatus);
}

Expand All @@ -85,7 +85,7 @@ public void authenticate_withSemanticsIdentifier() throws Exception {
assertNotNull(authenticationSessionResponse);
assertThat(authenticationSessionResponse.getSessionID(), not(isEmptyOrNullString()));

SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID());
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID(), connector);
assertAuthenticationResponseCreated(sessionStatus);
}

Expand All @@ -97,7 +97,7 @@ public void authenticate_withDocumentNumber() throws Exception {
assertNotNull(authenticationSessionResponse);
assertThat(authenticationSessionResponse.getSessionID(), not(isEmptyOrNullString()));

SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID());
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID(), connector);

assertNotNull(sessionStatus.getResult());
assertThat(sessionStatus.getResult().getEndResult(), is("OK"));
Expand All @@ -124,7 +124,7 @@ public void authenticate_withDocumentNumber_advancedInteraction() throws Excepti
assertNotNull(authenticationSessionResponse);
assertThat(authenticationSessionResponse.getSessionID(), not(isEmptyOrNullString()));

SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID());
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID(), connector);

assertNotNull(sessionStatus.getResult());
assertThat(sessionStatus.getResult().getEndResult(), is("OK"));
Expand All @@ -137,15 +137,15 @@ public void authenticate_withDocumentNumber_advancedInteraction() throws Excepti
public void getIgnoredProperties_withSign_getIgnoredProperties_withAuthenticate_testAccountsIgnoreVcChoice() throws Exception {
CertificateChoiceResponse certificateChoiceResponse = fetchCertificateChoiceSession(DOCUMENT_NUMBER);

SessionStatus sessionStatus = pollSessionStatus(certificateChoiceResponse.getSessionID());
SessionStatus sessionStatus = pollSessionStatus(certificateChoiceResponse.getSessionID(), connector);
assertCertificateChosen(sessionStatus);

String documentNumber = sessionStatus.getResult().getDocumentNumber();

SignatureSessionRequest signatureSessionRequest = createSignatureSessionRequest();

SignatureSessionResponse signatureSessionResponse = fetchSignatureSession(documentNumber, signatureSessionRequest);
sessionStatus = pollSessionStatus(signatureSessionResponse.getSessionID());
sessionStatus = pollSessionStatus(signatureSessionResponse.getSessionID(), connector);

assertNotNull(sessionStatus.getResult());
assertThat(sessionStatus.getResult().getEndResult(), is("OK"));
Expand All @@ -172,7 +172,7 @@ public void getIgnoredProperties_withAuthenticate() throws Exception {
assertNotNull(authenticationSessionResponse);
assertThat(authenticationSessionResponse.getSessionID(), not(isEmptyOrNullString()));

SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID());
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID(), connector);

assertThat(sessionStatus.getInteractionFlowUsed(), is("displayTextAndPIN"));

Expand Down Expand Up @@ -221,7 +221,7 @@ private SignatureSessionRequest createSignatureSessionRequest() {
return signatureSessionRequest;
}

private AuthenticationSessionRequest createAuthenticationSessionRequest() {
public static AuthenticationSessionRequest createAuthenticationSessionRequest() {
AuthenticationSessionRequest authenticationSessionRequest = new AuthenticationSessionRequest();
authenticationSessionRequest.setRelyingPartyUUID(RELYING_PARTY_UUID);
authenticationSessionRequest.setRelyingPartyName(RELYING_PARTY_NAME);
Expand All @@ -235,10 +235,10 @@ private AuthenticationSessionRequest createAuthenticationSessionRequest() {
return authenticationSessionRequest;
}

private SessionStatus pollSessionStatus(String sessionId) throws InterruptedException {
public static SessionStatus pollSessionStatus(String sessionId, SmartIdConnector connector1) throws InterruptedException {
SessionStatus sessionStatus = null;
while (sessionStatus == null || "RUNNING".equalsIgnoreCase(sessionStatus.getState() )) {
sessionStatus = connector.getSessionStatus(sessionId);
sessionStatus = connector1.getSessionStatus(sessionId);
TimeUnit.SECONDS.sleep(1);
}
assertEquals("COMPLETE", sessionStatus.getState());
Expand All @@ -258,7 +258,7 @@ private void assertCertificateChosen(SessionStatus sessionStatus) {
assertThat(sessionStatus.getCert().getValue(), not(isEmptyOrNullString()));
}

private void assertAuthenticationResponseCreated(SessionStatus sessionStatus) {
public static void assertAuthenticationResponseCreated(SessionStatus sessionStatus) {
assertNotNull(sessionStatus);

assertThat(sessionStatus.getResult().getEndResult(), not(isEmptyOrNullString()));
Expand All @@ -267,7 +267,7 @@ private void assertAuthenticationResponseCreated(SessionStatus sessionStatus) {
assertThat(sessionStatus.getCert().getCertificateLevel(), not(isEmptyOrNullString()));
}

private String calculateHashInBase64(byte[] dataToSign) {
private static String calculateHashInBase64(byte[] dataToSign) {
byte[] digestValue = DigestCalculator.calculateDigest(dataToSign, HashType.SHA512);
return Base64.encodeBase64String(digestValue);
}
Expand Down
Loading

0 comments on commit 0736c82

Please sign in to comment.