You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: example/README.md
+31-13Lines changed: 31 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Web eID Spring Boot example
2
2
3
-

3
+
<imgsrc="src/main/resources/static/img/eu-fund-flags.jpg"width="300"alt="European Regional Development Fund">
4
4
5
5
This project is an example Spring Boot web application that shows how to implement strong authentication
6
6
and digital signing with electronic ID smart cards using Web eID.
@@ -37,6 +37,8 @@ web-eid-auth-token:
37
37
domain names, use the ASCII/Punycode origin form in `local-origin`, for example
38
38
`https://xn--pike-loa.ee`for `https://päike.ee`.
39
39
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
+
40
42
### 3. Configure the trusted certificate authority certificates
41
43
42
44
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
53
55
54
56
### 5. Run the application
55
57
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.
57
59
58
60
Build and run the application with the following command in a terminal window:
59
61
@@ -84,6 +86,7 @@ When the application has started, open the _ngrok_ HTTPS URL in your preferred w
84
86
- [Using DigiDoc4j in production mode with the `prod` profile](#using-digidoc4j-in-production-mode-with-the-prod-profile)
85
87
+ [Stateful and stateless authentication](#stateful-and-stateless-authentication)
86
88
+ [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)
87
90
* [HTTPS support](#https-support)
88
91
+ [How to verify that HTTPS is configured properly](#how-to-verify-that-https-is-configured-properly)
89
92
* [Deployment](#deployment)
@@ -102,7 +105,8 @@ This repository contains the code of a minimal Spring Boot web application that
102
105
- Spring Security,
103
106
- the Web eID authentication token validation library [_web-eid-authtoken-validation-java_](https://github.com/web-eid/web-eid-authtoken-validation-java),
104
107
- 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/).
106
110
107
111
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.
108
112
@@ -115,11 +119,15 @@ The source code folder `src` contains the application source code and resources
115
119
The `src/main/java/eu/webeid/example` directory contains the Spring Boot application Java class and the following subdirectories:
116
120
117
121
- `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.
123
131
124
132
The `src/resources` directory contains the resources used by the application:
125
133
@@ -136,7 +144,7 @@ The `src/tests` directory contains the application test suite. The most importan
136
144
137
145
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.
138
146
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.
140
148
141
149
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.
142
150
@@ -146,7 +154,7 @@ Spring Security has CSRF protection enabled by default. Web eID requires CSRF pr
146
154
147
155
### Integration with Web eID components
148
156
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.
150
158
151
159
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.
152
160
@@ -176,6 +184,16 @@ A common alternative to stateful authentication is stateless authentication with
176
184
177
185
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.
178
186
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
+
179
197
## HTTPS support
180
198
181
199
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
218
236
server.tomcat.protocol-header=x-forwarded-proto
219
237
220
238
These settings are already enabled in the main configuration file `application.yaml`. See chapter
[Enable HTTPS When Running Behind a Proxy Server](https://docs.spring.io/spring-boot/3.5/how-to/security.html#howto.security.enable-https)
224
242
in the official documentation for further details.
225
243
226
244
### How to verify that HTTPS is configured properly
@@ -231,7 +249,7 @@ Strict Transport Security (HSTS) header and the `JSESSIONID` session cookie has
231
249
232
250
## Deployment
233
251
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.
235
253
236
254
Build the Docker image with [Jib](https://github.com/GoogleContainerTools/jib) as follows:
0 commit comments