Skip to content

Commit d15e02e

Browse files
Sander.Kondratjevaarmam
andcommitted
Add web-eid-1.1 token support
NFC-46 Signed-off-by: Sander Kondratjev <sander.kondratjev@nortal.com> Co-authored-by: Mart Aarma <mart.aarma@nortal.com>
1 parent 4c2cc54 commit d15e02e

92 files changed

Lines changed: 3981 additions & 1865 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/coverity-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ jobs:
2020
- uses: actions/setup-java@v4
2121
with:
2222
distribution: zulu
23-
java-version: 11
23+
java-version: 21
2424

2525
- name: Cache Maven packages
2626
uses: actions/cache@v4
2727
with:
2828
path: ~/.m2
29-
key: ${{ runner.os }}-m2-v8-${{ hashFiles('**/pom.xml') }}
30-
restore-keys: ${{ runner.os }}-m2-v8
29+
key: ${{ runner.os }}-m2-v21-${{ hashFiles('**/pom.xml') }}
30+
restore-keys: ${{ runner.os }}-m2-v21
3131

3232
- name: Download Coverity Build Tool
3333
run: |

.github/workflows/maven-build-example.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ jobs:
2020
- uses: actions/setup-java@v4
2121
with:
2222
distribution: zulu
23-
java-version: 17
23+
java-version: 21
2424

2525
- name: Cache Maven packages
2626
uses: actions/cache@v4
2727
with:
2828
path: ~/.m2
29-
key: ${{ runner.os }}-m2-v17-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/pom.xml') }}
30-
restore-keys: ${{ runner.os }}-m2-v17-${{ secrets.CACHE_VERSION }}
29+
key: ${{ runner.os }}-m2-v21-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/pom.xml') }}
30+
restore-keys: ${{ runner.os }}-m2-v21-${{ secrets.CACHE_VERSION }}
3131

3232
- name: Install library
3333
run: mvn -B -ntp install

.github/workflows/maven-build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ jobs:
2020
- uses: actions/setup-java@v4
2121
with:
2222
distribution: zulu
23-
java-version: 11
23+
java-version: 21
2424

2525
- name: Cache Maven packages
2626
uses: actions/cache@v4
2727
with:
2828
path: ~/.m2
29-
key: ${{ runner.os }}-m2-v8-${{ hashFiles('**/pom.xml') }}
30-
restore-keys: ${{ runner.os }}-m2-v8
29+
key: ${{ runner.os }}-m2-v21-${{ hashFiles('**/pom.xml') }}
30+
restore-keys: ${{ runner.os }}-m2-v21
3131

3232
- name: Build
3333
run: mvn --batch-mode compile

.github/workflows/maven-deploy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ jobs:
1414
- uses: actions/setup-java@v4
1515
with:
1616
distribution: zulu
17-
java-version: 11
17+
java-version: 21
1818

1919
- name: Cache Maven packages
2020
uses: actions/cache@v4
2121
with:
2222
path: ~/.m2
23-
key: ${{ runner.os }}-m2-v8-${{ hashFiles('**/pom.xml') }}
24-
restore-keys: ${{ runner.os }}-m2-v8
23+
key: ${{ runner.os }}-m2-v21-${{ hashFiles('**/pom.xml') }}
24+
restore-keys: ${{ runner.os }}-m2-v21
2525

2626
- name: Deploy to GitLab Package Repository # GitHub Packages
2727
env:

.github/workflows/sonarcloud-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ jobs:
2222
- uses: actions/checkout@v4
2323
with:
2424
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
25-
- name: Set up JDK 17
25+
- name: Set up JDK 21
2626
uses: actions/setup-java@v4
2727
with:
2828
distribution: zulu
29-
java-version: 17
29+
java-version: 21
3030
- name: Cache SonarCloud packages
3131
uses: actions/cache@v4
3232
with:
@@ -37,8 +37,8 @@ jobs:
3737
uses: actions/cache@v4
3838
with:
3939
path: ~/.m2
40-
key: ${{ runner.os }}-m2-v11-${{ hashFiles('**/pom.xml') }}
41-
restore-keys: ${{ runner.os }}-m2-v17
40+
key: ${{ runner.os }}-m2-v21-${{ hashFiles('**/pom.xml') }}
41+
restore-keys: ${{ runner.os }}-m2-v21
4242
- name: Build and analyze
4343
env:
4444
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any

README.md

Lines changed: 173 additions & 47 deletions
Large diffs are not rendered by default.

example/README.md

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Web eID Spring Boot example
22

3-
![European Regional Development Fund](https://github.com/open-eid/DigiDoc4-Client/blob/master/client/images/EL_Regionaalarengu_Fond.png)
3+
<img src="src/main/resources/static/img/eu-fund-flags.jpg" width="300" alt="European Regional Development Fund">
44

55
This project is an example Spring Boot web application that shows how to implement strong authentication
66
and digital signing with electronic ID smart cards using Web eID.
@@ -37,6 +37,8 @@ web-eid-auth-token:
3737
domain names, use the ASCII/Punycode origin form in `local-origin`, for example
3838
`https://xn--pike-loa.ee` for `https://päike.ee`.
3939

40+
The mobile authentication and signing example uses the configured web-eid-auth-token.validation.local-origin value when constructing mobile callback URIs. The example assumes that the application is deployed under the root context path (/). If deploying under a non-root context path, adjust the callback URI construction accordingly.
41+
4042
### 3. Configure the trusted certificate authority certificates
4143

4244
The algorithm, which performs the validation of the Web eID authentication token, needs to know which intermediate certificate authorities (CA) are trusted to issue the eID authentication certificates. CA certificates are loaded either from `.cer` files in the profile-specific subdirectory of the [`certs` resource directory](src/main/resources/certs) or the [truststore file](src/main/resources/certs/prod/trusted_certificates.jks). By default, Estonian eID test CA certificates are included in the `dev` profile and production CA certificates in the `prod` profile.
@@ -53,7 +55,7 @@ You can specify the profile as a command-line argument to the Maven wrapper comm
5355

5456
### 5. Run the application
5557

56-
Spring Boot web applications can be run from the command-line. You need to have the Java Development Kit 17 installed for building the application package and running the application.
58+
Spring Boot web applications can be run from the command-line. You need to have the Java Development Kit 21 installed for building the application package and running the application.
5759

5860
Build and run the application with the following command in a terminal window:
5961

@@ -84,6 +86,7 @@ When the application has started, open the _ngrok_ HTTPS URL in your preferred w
8486
- [Using DigiDoc4j in production mode with the `prod` profile](#using-digidoc4j-in-production-mode-with-the-prod-profile)
8587
+ [Stateful and stateless authentication](#stateful-and-stateless-authentication)
8688
+ [Assuring that the signing and authentication certificate subjects match](#assuring-that-the-signing-and-authentication-certificate-subjects-match)
89+
+ [Requesting the signing certificate in a separate step](#requesting-the-signing-certificate-in-a-separate-step)
8790
* [HTTPS support](#https-support)
8891
+ [How to verify that HTTPS is configured properly](#how-to-verify-that-https-is-configured-properly)
8992
* [Deployment](#deployment)
@@ -102,7 +105,8 @@ This repository contains the code of a minimal Spring Boot web application that
102105
- Spring Security,
103106
- the Web eID authentication token validation library [_web-eid-authtoken-validation-java_](https://github.com/web-eid/web-eid-authtoken-validation-java),
104107
- the Web eID JavaScript library [_web-eid.js_](https://github.com/web-eid/web-eid.js),
105-
- the digital signing library [_DigiDoc4j_](https://github.com/open-eid/digidoc4j).
108+
- the digital signing library [_DigiDoc4j_](https://github.com/open-eid/digidoc4j),
109+
- the Android application [_MOPP-Android_](https://github.com/open-eid/MOPP-Android/).
106110

107111
The project uses Maven for managing the dependencies and building the application. Maven project configuration file `pom.xml` is in the root of the project.
108112

@@ -115,11 +119,15 @@ The source code folder `src` contains the application source code and resources
115119
The `src/main/java/eu/webeid/example` directory contains the Spring Boot application Java class and the following subdirectories:
116120

117121
- `config`: Spring and HTTP security configuration, Web eID authentication token validation library configuration, trusted CA certificates loading etc,
118-
- `security`: Web eID authentication token validation library integration with Spring Security via an `AuthenticationProvider` and `AuthenticationProcessingFilter`,
119-
- `service`: Web eID signing service implementation that uses DigiDoc4j, and DigiDoc4j runtime configuration,
120-
- `web`: Spring Web MVC controller for the welcome page and Spring Web REST controllers that provide endpoints
121-
- for getting the challenge nonce used by the authentication token validation library,
122-
- for digital signing.
122+
- `security`: Web eID authentication token validation library integration with Spring Security
123+
- `AuthenticationProvider` and `AuthenticationProcessingFilter` for handling Web eID authentication tokens,
124+
- `WebEidChallengeNonceFilter` for issuing the challenge nonce required by the authentication flow,
125+
- `WebEidMobileAuthInitFilter` for issuing the challenge nonce and generating the deep link with the authentication request, used to initiate the mobile authentication flow,
126+
- `WebEidAjaxLoginProcessingFilter` and `WebEidLoginPageGeneratingFilter` for handling login requests.
127+
- `service`: Web eID signing service implementation that uses DigiDoc4j, and DigiDoc4j runtime configuration.
128+
- `SigningService`: prepares ASiC-E containers and finalizes signatures.
129+
- `MobileSigningService`: orchestrates the mobile signing flow (builds mobile signing requests/responses) and supports requesting the signing certificate in a separate step when enabled by configuration.
130+
- `web`: Spring Web MVC controller for the welcome page and Spring Web REST controller that provides a digital signing endpoint.
123131

124132
The `src/resources` directory contains the resources used by the application:
125133

@@ -136,7 +144,7 @@ The `src/tests` directory contains the application test suite. The most importan
136144

137145
As described in section [_4. Choose either the `dev` or `prod` profile_](#4-choose-either-the-dev-or-prod-profile) above, the application has two different configuration profiles: `dev` profile for running the application in development mode and `prod` profile for production mode. The `dev` profile is activated by default.
138146

139-
The profile-specific configuration files `src/main/resources/application-{dev,prod}.yaml` contain the `web-eid-auth-token.validation.use-digidoc4j-prod-configuration` setting that configures DigiDoc4j either in test or production mode, and a setting for configuring the origin URL as described in section [_2. Configure the origin URL_](#2-configure-the-origin-url) above. Additionally, the `web-eid-auth-token.validation.truststore-password` setting specifies the truststore password used in the `prod` profile.
147+
The profile-specific configuration files `src/main/resources/application-{dev,prod}.yaml` contain the `web-eid-auth-token.validation.use-digidoc4j-prod-configuration` setting that configures DigiDoc4j either in test or production mode, and a setting for configuring the origin URL as described in section [_2. Configure the origin URL_](#2-configure-the-origin-url) above. Additionally, the `web-eid-auth-token.validation.truststore-password` setting specifies the truststore password used in the `prod` profile. The `web-eid-mobile` section configures the mobile authentication flow, including the `base-request-uri` for deep link generation and the `request-signing-cert` flag that controls whether the signing certificate is requested during authentication.
140148

141149
The main configuration file `src/main/resources/application.yaml` is shared by all profiles and contains logging configuration and settings that make the session cookie secure behind a reverse proxy as described in section [_HTTPS support_](#https-support) below.
142150

@@ -146,7 +154,7 @@ Spring Security has CSRF protection enabled by default. Web eID requires CSRF pr
146154

147155
### Integration with Web eID components
148156

149-
Detailed overview of Java code changes required for integrating Web eID authentication token validation is available in the [_web-eid-authtoken-validation-java_ library README](https://github.com/web-eid/web-eid-authtoken-validation-java/blob/main/README.md). There are instructions for configuring the nonce generator, trusted certificate authority certificates, authentication token validator, Spring Security authentication integration and REST endpoints. The corresponding Java code is in the `src/main/java/eu/webeid/example/{config,security,web/rest}` directories.
157+
Detailed overview of Java code changes required for integrating Web eID authentication token validation is available in the [_web-eid-authtoken-validation-java_ library README](https://github.com/web-eid/web-eid-authtoken-validation-java/blob/main/README.md). There are instructions for configuring the nonce generator, trusted certificate authority certificates, authentication token validator, Spring Security authentication integration and security filters. The corresponding Java code is in the `src/main/java/eu/webeid/example/{config,security,web/rest}` directories.
150158

151159
A similar overview of JavaScript and HTML code changes required for authentication and digital signing with Web eID is available in the [web-eid.js library README](https://github.com/web-eid/web-eid.js/blob/main/README.md). The corresponding JavaScript and HTML code is in the `src/resources/{static,templates}` directories.
152160

@@ -176,6 +184,16 @@ A common alternative to stateful authentication is stateless authentication with
176184

177185
It is usually required to verify that the signing certificate subject matches the authentication certificate subject by assuring that both ID codes match. This check is implemented at the beginning of the `SigningService.prepareContainer()` method.
178186

187+
### Requesting the signing certificate in a separate step
188+
189+
In some deployments, the signing certificate is not reused from the authentication flow. Instead, it is retrieved directly from the user’s ID-card during the signing process itself.
190+
191+
This approach is useful when the signing process is performed without a prior authentication step. For example, in a mobile flow, the user may start signing directly without authenticating beforehand. In such cases, the signing certificate must be requested separately from the user’s ID-card before the signature can be created.
192+
193+
When this mode is enabled in the configuration, the backend issues a separate request for the signing certificate using the `MobileSigningService`. The service communicates with the client to obtain the certificate before the signing container is prepared, ensuring that the correct certificate chain is available for the signature.
194+
195+
This behavior is controlled by the `request-signing-cert` flag in the `application.yaml` configuration files (`application-dev.yaml`, `application-prod.yaml`). When the flag is set to **false**, the application explicitly requests the signing certificate during the signing process, demonstrating the separate signing certificate retrieval flow. When set to **true**, the signing uses the signing certificate that was already obtained during authentication, and no additional request is made.
196+
179197
## HTTPS support
180198

181199
There are two ways of adding HTTPS support to a Spring Boot application:
@@ -218,9 +236,9 @@ Tomcat web server automatically if it detects the presence of the
218236
server.tomcat.protocol-header=x-forwarded-proto
219237

220238
These settings are already enabled in the main configuration file `application.yaml`. See chapter
221-
[9.3.12](https://docs.spring.io/spring-boot/docs/2.2.5.RELEASE/reference/htmlsingle/#howto-use-behind-a-proxy-server)
239+
[Running Behind a Front-end Proxy Server](https://docs.spring.io/spring-boot/3.5/how-to/webserver.html#howto.webserver.use-behind-a-proxy-server)
222240
and
223-
[9.14.3](https://docs.spring.io/spring-boot/docs/2.2.5.RELEASE/reference/htmlsingle/#howto-enable-https)
241+
[Enable HTTPS When Running Behind a Proxy Server](https://docs.spring.io/spring-boot/3.5/how-to/security.html#howto.security.enable-https)
224242
in the official documentation for further details.
225243

226244
### How to verify that HTTPS is configured properly
@@ -231,7 +249,7 @@ Strict Transport Security (HSTS) header and the `JSESSIONID` session cookie has
231249

232250
## Deployment
233251

234-
A Docker Compose configuration file `docker-compose.yml` is available in the root of the project for packaging the application in a Docker image so that it can be deployed with a container enginge.
252+
A Docker Compose configuration file `docker-compose.yml` is available in the root of the project for packaging the application in a Docker image so that it can be deployed with a container engine.
235253

236254
Build the Docker image with [Jib](https://github.com/GoogleContainerTools/jib) as follows:
237255

example/pom.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
</parent>
1111
<groupId>eu.webeid.example</groupId>
1212
<artifactId>web-eid-springboot-example</artifactId>
13-
<version>3.2.2</version>
13+
<version>4.0.0-SNAPSHOT</version>
1414
<name>web-eid-springboot-example</name>
1515
<description>Example Spring Boot application that demonstrates how to use Web eID for authentication and digital
1616
signing
1717
</description>
1818

1919
<properties>
20-
<java.version>17</java.version>
20+
<java.version>21</java.version>
2121
<maven-surefire-plugin.version>3.5.3</maven-surefire-plugin.version>
22-
<webeid.version>3.2.1</webeid.version>
22+
<webeid.version>4.0.0-SNAPSHOT</webeid.version>
2323
<digidoc4j.version>6.1.1</digidoc4j.version>
2424
<jmockit.version>1.44</jmockit.version> <!-- Keep version 1.44, otherwise mocking will fail. -->
2525
<jib.version>3.5.1</jib.version>
@@ -41,6 +41,10 @@
4141
<groupId>org.springframework.boot</groupId>
4242
<artifactId>spring-boot-starter-thymeleaf</artifactId>
4343
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-validation</artifactId>
47+
</dependency>
4448

4549
<dependency>
4650
<groupId>org.digidoc4j</groupId>

0 commit comments

Comments
 (0)