Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 11
java-version: 17

- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-v11-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-v11-${{ secrets.CACHE_VERSION }}
key: ${{ runner.os }}-m2-v17-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-v17-${{ secrets.CACHE_VERSION }}

- name: Build
run: mvn --batch-mode compile
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ You can specify the profile as a command-line argument to the Maven wrapper comm

### 5. Run the application

Spring Boot web applications can be run from the command-line. You need to have the Java Development Kit 8 installed for building the application package and running the application.
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.

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

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.15</version>
<version>3.1.9</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.webeid.example</groupId>
Expand All @@ -17,10 +17,10 @@
</description>

<properties>
<java.version>11</java.version>
<java.version>17</java.version>
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
<webeid.version>3.0.0</webeid.version>
<digidoc4j.version>5.2.0</digidoc4j.version>
<digidoc4j.version>5.3.0</digidoc4j.version>
<jmockit.version>1.44</jmockit.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,53 +24,52 @@

import eu.webeid.example.security.AuthTokenDTOAuthenticationProvider;
import eu.webeid.example.security.WebEidAjaxLoginProcessingFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.HttpStatusReturningLogoutSuccessHandler;
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
import org.springframework.security.web.context.SecurityContextRepository;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
public class ApplicationConfiguration extends WebSecurityConfigurerAdapter implements WebMvcConfigurer {
@EnableMethodSecurity(securedEnabled = true, jsr250Enabled = true)
public class ApplicationConfiguration implements WebMvcConfigurer {
final AuthTokenDTOAuthenticationProvider authTokenDTOAuthenticationProvider;
final SecurityContextRepository securityContextRepository;

public ApplicationConfiguration(AuthTokenDTOAuthenticationProvider authTokenDTOAuthenticationProvider) {
this.authTokenDTOAuthenticationProvider = authTokenDTOAuthenticationProvider;
this.securityContextRepository = new HttpSessionSecurityContextRepository();
}

@Override
protected void configure(AuthenticationManagerBuilder authenticationManagerBuilder) {
authenticationManagerBuilder.authenticationProvider(authTokenDTOAuthenticationProvider);
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}

@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.addFilterBefore(
new WebEidAjaxLoginProcessingFilter("/auth/login", authenticationManager()),
UsernamePasswordAuthenticationFilter.class)
.authorizeRequests()
.antMatchers("/auth/challenge", "/auth/login", "/")
.permitAll()
.antMatchers("/welcome")
.authenticated()
.and()
.logout()
.logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler())
.and()
.headers()
.frameOptions().sameOrigin();
// @formatter:on
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
AuthenticationManager manager = authenticationManager(http.getSharedObject(AuthenticationConfiguration.class));

return http
.authenticationProvider(authTokenDTOAuthenticationProvider)
.addFilterBefore(new WebEidAjaxLoginProcessingFilter("/auth/login", manager, securityContextRepository),
UsernamePasswordAuthenticationFilter.class)
.logout(logout -> logout.logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler()))
.headers(headers -> headers.frameOptions(options -> options.sameOrigin()))
.build();
}

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
registry.addViewController("/welcome").setViewName("welcome");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import eu.webeid.security.challenge.ChallengeNonce;
import eu.webeid.security.challenge.ChallengeNonceStore;

import javax.servlet.http.HttpSession;
import jakarta.servlet.http.HttpSession;

public class SessionBackedChallengeNonceStore implements ChallengeNonceStore {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import eu.webeid.security.validator.AuthTokenValidator;
import eu.webeid.security.validator.AuthTokenValidatorBuilder;

import javax.servlet.http.HttpSession;
import jakarta.servlet.http.HttpSession;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,42 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import eu.webeid.example.security.ajax.AjaxAuthenticationFailureHandler;
import eu.webeid.example.security.ajax.AjaxAuthenticationSuccessHandler;
import eu.webeid.example.security.dto.AuthTokenDTO;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
import org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy;
import org.springframework.security.web.context.SecurityContextRepository;

public class WebEidAjaxLoginProcessingFilter extends AbstractAuthenticationProcessingFilter {
private static final Logger LOG = LoggerFactory.getLogger(WebEidAjaxLoginProcessingFilter.class);
private final SecurityContextRepository securityContextRepository;

public WebEidAjaxLoginProcessingFilter(
String defaultFilterProcessesUrl,
AuthenticationManager authenticationManager
AuthenticationManager authenticationManager,
SecurityContextRepository securityContextRepository
) {
super(defaultFilterProcessesUrl);
this.setAuthenticationManager(authenticationManager);
this.setAuthenticationSuccessHandler(new AjaxAuthenticationSuccessHandler());
this.setAuthenticationFailureHandler(new AjaxAuthenticationFailureHandler());
setSessionAuthenticationStrategy(new SessionFixationProtectionStrategy());
this.securityContextRepository = securityContextRepository;
}

@Override
Expand All @@ -76,4 +83,10 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
LOG.info("attemptAuthentication(): Calling authentication manager");
return getAuthenticationManager().authenticate(token);
}

@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException {
super.successfulAuthentication(request, response, chain, authResult); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/OverriddenMethodBody
securityContextRepository.saveContext(SecurityContextHolder.getContext(), request, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import java.io.IOException;

public class AjaxAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/eu/webeid/example/service/SigningService.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
import org.springframework.core.io.ByteArrayResource;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import javax.xml.bind.DatatypeConverter;
import jakarta.servlet.http.HttpSession;
import jakarta.xml.bind.DatatypeConverter;
import java.io.IOException;
import java.io.InputStream;
import java.security.NoSuchAlgorithmException;
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/eu/webeid/example/web/IndexController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2020-2024 Estonian Information System Authority
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package eu.webeid.example.web;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class IndexController {
@GetMapping("/")
public String welcome(Model model, HttpServletRequest request) {
model.addAttribute("serverName", request.getServerName());
return "index";
}
}
2 changes: 1 addition & 1 deletion src/main/java/eu/webeid/example/web/WelcomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotNull;
import java.security.Principal;

import static eu.webeid.example.security.AuthTokenDTOAuthenticationProvider.ROLE_USER;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h3><a id="usage"></a>Usage</h3>
<li>on <b>Ubuntu Linux</b>, for Firefox and Chrome, download and execute the<br>
<a href="/scripts/download-install-web-eid.sh"><code>download-install-web-eid.sh</code></a>
script from the console with<br>
<code>wget -O - https://<span th:text="${#httpServletRequest.serverName}"/>/scripts/download-install-web-eid.sh
<code>wget -O - https://<span th:text="${serverName}"/>/scripts/download-install-web-eid.sh
| bash</code><br>
<b>Note that Firefox is installed with Snap in Ubuntu 22.04 or later by default and as the
Snap sandbox does not allow communication with the external native messaging host, Web
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/eu/webeid/example/WebApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class WebApplicationTest {
private WebApplicationContext context;

@Autowired
private javax.servlet.Filter[] springSecurityFilterChain;
private jakarta.servlet.Filter[] springSecurityFilterChain;

private static DefaultMockMvcBuilder mvcBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.StringReader;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.springframework.security.web.context.SecurityContextRepository;

class WebEidAjaxLoginProcessingFilterTest {

Expand All @@ -31,9 +32,10 @@ void testAttemptAuthentication() throws Exception {
when(request.getReader()).thenReturn(new BufferedReader(new StringReader(AUTH_TOKEN)));

final AuthenticationManager authenticationManager = mock(AuthenticationManager.class);
final SecurityContextRepository securityContextRepository = mock(SecurityContextRepository.class);

assertDoesNotThrow(() ->
new WebEidAjaxLoginProcessingFilter("/auth/login", authenticationManager)
new WebEidAjaxLoginProcessingFilter("/auth/login", authenticationManager, securityContextRepository)
.attemptAuthentication(request, response));
}
}
2 changes: 1 addition & 1 deletion src/test/java/eu/webeid/example/testutil/ObjectMother.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import eu.webeid.example.service.dto.CertificateDTO;
import eu.webeid.example.service.dto.SignatureDTO;

import javax.xml.bind.DatatypeConverter;
import jakarta.xml.bind.DatatypeConverter;
import java.io.FileInputStream;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
Expand Down