Skip to content

Commit 0736c82

Browse files
authored
update documentation about how to configure a proxy server (#70)
* update documentation about how to configure a proxy server * fix to issue 69 Co-authored-by: Juhan Aasaru <Juhan.Aasaru@nortal.com>
1 parent b7d62bf commit 0736c82

5 files changed

Lines changed: 155 additions & 81 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
All notable changes to this project will be documented in this file.
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44

5+
## [2.2.1] - 2022-09-12
6+
7+
### Fixed
8+
- added jakarta.ws.rs:jakarta.ws.rs-api as a dependency to avoid ClassNotFoundException with spring framework
9+
10+
### Changed
11+
- Updated dependencies
12+
13+
### Changes in tests and documentation
14+
- How to use a proxy server - added documentation to README.md and tests to ReadmeTest.java
15+
516
## [2.2] - 2022-02-22
617

718
### Changed

README.md

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,34 @@ For using Smart-ID API v. 1.0 see [Smart-ID Java Client 1.X](https://github.com/
1818
* [Requirements](#requirements)
1919
* [Getting the library](#getting-the-library)
2020
* [Changelog](#changelog)
21-
* [How to use it](#how-to-use-it)
22-
* [Test accounts for testing]()
23-
* [Logging](#logging)
21+
* [How to use it](#how-to-use-it)
22+
* [Test accounts for testing]()
23+
* [Logging](#logging)
2424
* [Log request payloads](#log-request-payloads)
2525
* [Get the IP address of user's device](#get-the-ip-address-of-users-device)
26-
* [Example of configuring the client](#example-of-configuring-the-client)
26+
* [Example of configuring the client](#example-of-configuring-the-client)
2727
* [Reading trusted certificates from key store](#reading-trusted-certificates-from-key-store)
2828
* [Feeding trusted certificates one by one](#feeding-trusted-certificates-one-by-one)
29-
* [Examples of performing authentication](#examples-of-performing-authentication)
29+
* [Examples of performing authentication](#examples-of-performing-authentication)
3030
* [Authenticating with semantics identifier](#authenticating-with-semantics-identifier)
3131
* [Authenticating with document number](#authenticating-with-document-number)
3232
* [Validating authentication response](#validating-authentication-response)
33-
* [Creating a signature](#creating-a-signature)
33+
* [Creating a signature](#creating-a-signature)
3434
* [Obtaining signer's certificate](#obtaining-signers-certificate)
3535
* [Create the signature](#create-the-signature)
36-
* [Setting the order of preferred interactions for displaying text and asking PIN](#setting-the-order-of-preferred-interactions-for-displaying-text-and-asking-pin)
36+
* [Setting the order of preferred interactions for displaying text and asking PIN](#setting-the-order-of-preferred-interactions-for-displaying-text-and-asking-pin)
3737
* [Parameter allowedInteractionsOrder most common examples](#parameter-allowedinteractionsorder-most-common-examples)
3838
* [Short confirmation message with PIN](#short-confirmation-message-with-pin)
3939
* [Verification code choice](#verification-code-choice)
4040
* [Long confirmation message with fallback to PIN](#long-confirmation-message-with-fallback-to-pin)
4141
* [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)
4242
* [Interactions with longer text without fallback](#interactions-with-longer-text-without-fallback)
43-
* [Handling exceptions](#handling-exceptions)
44-
* [Network connection configuration of the client](#network-connection-configuration-of-the-client)
43+
* [Handling exceptions](#handling-exceptions)
44+
* [Network connection configuration of the client](#network-connection-configuration-of-the-client)
4545
* [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)
46-
* [Example of creating a client with configured proxy on JBoss](#example-of-creating-a-client-with-configured-ssl-context-on-jboss-using-jaxws-rs)
47-
46+
* [Configuring a proxy](#configuring-a-proxy)
47+
* [Configuring a proxy using JBoss Resteasy library](#configuring-a-proxy-using-jboss-resteasy-library)
48+
* [Configuring a proxy using Jersey](#configuring-a-proxy-using-jersey)
4849

4950
## Introduction
5051

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

564+
## Configuring a proxy
563565

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

569+
### Configuring a proxy using JBoss Resteasy library
570+
571+
<!-- Do not change code samples here but instead copy from ReadmeTest.document_setProxy_withJbossRestEasy() -->
566572
```java
567-
ResteasyClient resteasyClient = new ResteasyClientBuilder()
568-
.defaultProxy("localhost", 8080, "http")
569-
.build();
573+
org.jboss.resteasy.client.jaxrs.ResteasyClient resteasyClient =
574+
new org.jboss.resteasy.client.jaxrs.internal.ResteasyClientBuilderImpl()
575+
.defaultProxy("127.0.0.1", 3128, "http")
576+
.build();
577+
SmartIdClient client = new SmartIdClient();
578+
client.setRelyingPartyUUID("00000000-0000-0000-0000-000000000000");
579+
client.setRelyingPartyName("DEMO");
580+
client.setHostUrl("https://sid.demo.sk.ee/smart-id-rp/v2/");
581+
client.setConfiguredClient(resteasyClient);
582+
client.setTrustedCertificates(DEMO_HOST_SSL_CERTIFICATE);
583+
```
570584

571-
SmartIdClient client = new SmartIdClient();
572-
client.setRelyingPartyUUID("00000000-0000-0000-0000-000000000000");
573-
client.setRelyingPartyName("DEMO");
574-
client.setHostUrl("https://sid.demo.sk.ee/smart-id-rp/v2/");
575-
client.setConfiguredClient(resteasyClient);
585+
### Example of creating a client with configured proxy on JBoss
586+
587+
<!-- Do not change code samples here but instead copy from ReadmeTest.document_setNetworkConnectionConfig_withJersey()-->
588+
```java
589+
org.glassfish.jersey.client.ClientConfig clientConfig =
590+
new org.glassfish.jersey.client.ClientConfig();
591+
clientConfig.property(ClientProperties.PROXY_URI, "http://127.0.0.1:3128");
592+
593+
SmartIdClient client = new SmartIdClient();
594+
client.setRelyingPartyUUID("00000000-0000-0000-0000-000000000000");
595+
client.setRelyingPartyName("DEMO");
596+
client.setHostUrl("https://sid.demo.sk.ee/smart-id-rp/v2/");
597+
client.setNetworkConnectionConfig(clientConfig);
598+
client.setTrustedCertificates(DEMO_HOST_SSL_CERTIFICATE);
576599
```
577600

578-

pom.xml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@
4545
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4646
<maven.compiler.source>1.8</maven.compiler.source>
4747
<maven.compiler.target>1.8</maven.compiler.target>
48-
<jackson.version>2.13.1</jackson.version>
49-
<jersey.version>3.0.4</jersey.version>
48+
<jackson.version>2.13.3</jackson.version>
49+
<jersey.version>3.0.6</jersey.version>
50+
<rs-api.version>3.0.0</rs-api.version>
51+
<resteasy.version>6.0.3.Final</resteasy.version>
5052
</properties>
5153

5254
<dependencies>
@@ -65,6 +67,13 @@
6567
<artifactId>jersey-hk2</artifactId>
6668
<version>${jersey.version}</version>
6769
</dependency>
70+
71+
<dependency>
72+
<groupId>jakarta.ws.rs</groupId>
73+
<artifactId>jakarta.ws.rs-api</artifactId>
74+
<version>${rs-api.version}</version>
75+
</dependency>
76+
6877
<dependency>
6978
<groupId>org.glassfish.jersey.connectors</groupId>
7079
<artifactId>jersey-apache-connector</artifactId>
@@ -93,9 +102,17 @@
93102
<dependency>
94103
<groupId>org.glassfish.jaxb</groupId>
95104
<artifactId>jaxb-runtime</artifactId>
96-
<version>3.0.1</version>
105+
<version>4.0.0</version>
106+
</dependency>
107+
108+
109+
<dependency>
110+
<groupId>org.bouncycastle</groupId>
111+
<artifactId>bcprov-jdk15on</artifactId>
112+
<version>1.70</version>
97113
</dependency>
98114

115+
99116
<dependency>
100117
<groupId>junit</groupId>
101118
<artifactId>junit</artifactId>
@@ -111,38 +128,35 @@
111128
<dependency>
112129
<groupId>ch.qos.logback</groupId>
113130
<artifactId>logback-classic</artifactId>
114-
<version>1.2.10</version>
131+
<version>1.2.11</version>
115132
<scope>test</scope>
116133
</dependency>
117134
<dependency>
118135
<groupId>com.github.tomakehurst</groupId>
119136
<artifactId>wiremock</artifactId>
120-
<version>2.4.1</version>
137+
<version>2.27.2</version>
121138
<scope>test</scope>
122139
</dependency>
123140
<dependency>
124141
<groupId>org.mockito</groupId>
125142
<artifactId>mockito-core</artifactId>
126-
<version>4.3.1</version>
143+
<version>4.7.0</version>
127144
<scope>test</scope>
128145
</dependency>
129146

130-
131147
<dependency>
132-
<groupId>org.bouncycastle</groupId>
133-
<artifactId>bcprov-jdk15on</artifactId>
134-
<version>1.69</version>
148+
<groupId>org.jboss.resteasy</groupId>
149+
<artifactId>resteasy-client</artifactId>
150+
<version>${resteasy.version}</version>
151+
<scope>test</scope>
135152
</dependency>
136153

137-
<!-- comment in if you want to configure client with RestEasy in tests
138154
<dependency>
139155
<groupId>org.jboss.resteasy</groupId>
140-
<artifactId>resteasy-client</artifactId>
141-
<version>3.12.0.Final</version>
156+
<artifactId>resteasy-jackson2-provider</artifactId>
157+
<version>${resteasy.version}</version>
142158
<scope>test</scope>
143-
<optional>true</optional>
144159
</dependency>
145-
-->
146160

147161
</dependencies>
148162

src/test/java/ee/sk/smartid/rest/SmartIdRestIntegrationTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ public void setUp() {
6666
public void getCertificateAndSignHash() throws Exception {
6767
CertificateChoiceResponse certificateChoiceResponse = fetchCertificateChoiceSession(DOCUMENT_NUMBER_LT);
6868

69-
SessionStatus sessionStatus = pollSessionStatus(certificateChoiceResponse.getSessionID());
69+
SessionStatus sessionStatus = pollSessionStatus(certificateChoiceResponse.getSessionID(), connector);
7070
assertCertificateChosen(sessionStatus);
7171

7272
String documentNumber = sessionStatus.getResult().getDocumentNumber();
7373
SignatureSessionResponse signatureSessionResponse = createRequestAndFetchSignatureSession(documentNumber);
74-
sessionStatus = pollSessionStatus(signatureSessionResponse.getSessionID());
74+
sessionStatus = pollSessionStatus(signatureSessionResponse.getSessionID(), connector);
7575
assertSignatureCreated(sessionStatus);
7676
}
7777

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

88-
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID());
88+
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID(), connector);
8989
assertAuthenticationResponseCreated(sessionStatus);
9090
}
9191

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

100-
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID());
100+
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID(), connector);
101101

102102
assertNotNull(sessionStatus.getResult());
103103
assertThat(sessionStatus.getResult().getEndResult(), is("OK"));
@@ -124,7 +124,7 @@ public void authenticate_withDocumentNumber_advancedInteraction() throws Excepti
124124
assertNotNull(authenticationSessionResponse);
125125
assertThat(authenticationSessionResponse.getSessionID(), not(isEmptyOrNullString()));
126126

127-
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID());
127+
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID(), connector);
128128

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

140-
SessionStatus sessionStatus = pollSessionStatus(certificateChoiceResponse.getSessionID());
140+
SessionStatus sessionStatus = pollSessionStatus(certificateChoiceResponse.getSessionID(), connector);
141141
assertCertificateChosen(sessionStatus);
142142

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

145145
SignatureSessionRequest signatureSessionRequest = createSignatureSessionRequest();
146146

147147
SignatureSessionResponse signatureSessionResponse = fetchSignatureSession(documentNumber, signatureSessionRequest);
148-
sessionStatus = pollSessionStatus(signatureSessionResponse.getSessionID());
148+
sessionStatus = pollSessionStatus(signatureSessionResponse.getSessionID(), connector);
149149

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

175-
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID());
175+
SessionStatus sessionStatus = pollSessionStatus(authenticationSessionResponse.getSessionID(), connector);
176176

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

@@ -221,7 +221,7 @@ private SignatureSessionRequest createSignatureSessionRequest() {
221221
return signatureSessionRequest;
222222
}
223223

224-
private AuthenticationSessionRequest createAuthenticationSessionRequest() {
224+
public static AuthenticationSessionRequest createAuthenticationSessionRequest() {
225225
AuthenticationSessionRequest authenticationSessionRequest = new AuthenticationSessionRequest();
226226
authenticationSessionRequest.setRelyingPartyUUID(RELYING_PARTY_UUID);
227227
authenticationSessionRequest.setRelyingPartyName(RELYING_PARTY_NAME);
@@ -235,10 +235,10 @@ private AuthenticationSessionRequest createAuthenticationSessionRequest() {
235235
return authenticationSessionRequest;
236236
}
237237

238-
private SessionStatus pollSessionStatus(String sessionId) throws InterruptedException {
238+
public static SessionStatus pollSessionStatus(String sessionId, SmartIdConnector connector1) throws InterruptedException {
239239
SessionStatus sessionStatus = null;
240240
while (sessionStatus == null || "RUNNING".equalsIgnoreCase(sessionStatus.getState() )) {
241-
sessionStatus = connector.getSessionStatus(sessionId);
241+
sessionStatus = connector1.getSessionStatus(sessionId);
242242
TimeUnit.SECONDS.sleep(1);
243243
}
244244
assertEquals("COMPLETE", sessionStatus.getState());
@@ -258,7 +258,7 @@ private void assertCertificateChosen(SessionStatus sessionStatus) {
258258
assertThat(sessionStatus.getCert().getValue(), not(isEmptyOrNullString()));
259259
}
260260

261-
private void assertAuthenticationResponseCreated(SessionStatus sessionStatus) {
261+
public static void assertAuthenticationResponseCreated(SessionStatus sessionStatus) {
262262
assertNotNull(sessionStatus);
263263

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

270-
private String calculateHashInBase64(byte[] dataToSign) {
270+
private static String calculateHashInBase64(byte[] dataToSign) {
271271
byte[] digestValue = DigestCalculator.calculateDigest(dataToSign, HashType.SHA512);
272272
return Base64.encodeBase64String(digestValue);
273273
}

0 commit comments

Comments
 (0)