From 93426c157acd52904eda55f843a8296655e2b60a Mon Sep 17 00:00:00 2001 From: Lubos Racansky Date: Wed, 4 Oct 2023 08:16:22 +0200 Subject: [PATCH 01/13] Fix #880: Wrong bouncycastle version in jboss deployment --- docs/onboarding/Deploying-Wildfly.md | 2 +- .../src/main/webapp/WEB-INF/jboss-deployment-structure.xml | 2 +- .../src/main/webapp/WEB-INF/jboss-deployment-structure.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/onboarding/Deploying-Wildfly.md b/docs/onboarding/Deploying-Wildfly.md index 3e7bce39..b2653251 100644 --- a/docs/onboarding/Deploying-Wildfly.md +++ b/docs/onboarding/Deploying-Wildfly.md @@ -15,7 +15,7 @@ Enrollment Server contains the following configuration in `jboss-deployment-stru - + diff --git a/enrollment-server-onboarding/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/enrollment-server-onboarding/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index 2e3377e8..e7638f97 100644 --- a/enrollment-server-onboarding/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/enrollment-server-onboarding/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -8,7 +8,7 @@ - + diff --git a/enrollment-server/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/enrollment-server/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index f0b64661..86dc3331 100644 --- a/enrollment-server/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/enrollment-server/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -8,7 +8,7 @@ - + From ba710ba486363edfeb2f4d4a40c9d17e07881507 Mon Sep 17 00:00:00 2001 From: Lubos Racansky Date: Thu, 5 Oct 2023 10:00:23 +0200 Subject: [PATCH 02/13] Fix #882: Filter jboss descriptor with bouncycastle version from pom --- enrollment-server-onboarding/pom.xml | 13 +++++++++++++ .../webapp/WEB-INF/jboss-deployment-structure.xml | 2 +- enrollment-server/pom.xml | 13 +++++++++++++ .../webapp/WEB-INF/jboss-deployment-structure.xml | 2 +- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/enrollment-server-onboarding/pom.xml b/enrollment-server-onboarding/pom.xml index 6198686a..cb404f23 100644 --- a/enrollment-server-onboarding/pom.xml +++ b/enrollment-server-onboarding/pom.xml @@ -244,6 +244,19 @@ + + org.apache.maven.plugins + maven-war-plugin + + + + src/main/webapp/WEB-INF + WEB-INF + true + + + + diff --git a/enrollment-server-onboarding/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/enrollment-server-onboarding/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index e7638f97..ed6a86c0 100644 --- a/enrollment-server-onboarding/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/enrollment-server-onboarding/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -8,7 +8,7 @@ - + diff --git a/enrollment-server/pom.xml b/enrollment-server/pom.xml index ee55b0ac..d22135b6 100644 --- a/enrollment-server/pom.xml +++ b/enrollment-server/pom.xml @@ -185,6 +185,19 @@ external-service + + org.apache.maven.plugins + maven-war-plugin + + + + src/main/webapp/WEB-INF + WEB-INF + true + + + + diff --git a/enrollment-server/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/enrollment-server/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index 86dc3331..fe707a2a 100644 --- a/enrollment-server/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/enrollment-server/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -8,7 +8,7 @@ - + From 2a86397de96ff9abc135fd3eb010831f1d51a4b9 Mon Sep 17 00:00:00 2001 From: Lubos Racansky Date: Fri, 6 Oct 2023 09:17:15 +0200 Subject: [PATCH 03/13] Fix #884: Exclude lombok from war --- enrollment-server-onboarding/pom.xml | 12 ++++++++++++ enrollment-server/pom.xml | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/enrollment-server-onboarding/pom.xml b/enrollment-server-onboarding/pom.xml index cb404f23..4a32fad9 100644 --- a/enrollment-server-onboarding/pom.xml +++ b/enrollment-server-onboarding/pom.xml @@ -183,6 +183,18 @@ + + + + jakarta.servlet + jakarta.servlet-api + + + org.projectlombok + lombok + + + org.apache.maven.plugins diff --git a/enrollment-server/pom.xml b/enrollment-server/pom.xml index d22135b6..975117a1 100644 --- a/enrollment-server/pom.xml +++ b/enrollment-server/pom.xml @@ -176,6 +176,18 @@ + + + + jakarta.servlet + jakarta.servlet-api + + + org.projectlombok + lombok + + + org.apache.maven.plugins From bb28f627f59ba0bde47f07fb70100f97bb63f561 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Oct 2023 02:59:12 +0000 Subject: [PATCH 04/13] Bump net.javacrumbs.shedlock:shedlock-bom from 5.8.0 to 5.9.0 Bumps [net.javacrumbs.shedlock:shedlock-bom](https://github.com/lukas-krecan/ShedLock) from 5.8.0 to 5.9.0. - [Commits](https://github.com/lukas-krecan/ShedLock/compare/shedlock-parent-5.8.0...shedlock-parent-5.9.0) --- updated-dependencies: - dependency-name: net.javacrumbs.shedlock:shedlock-bom dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7d461ce0..1c5adcd3 100644 --- a/pom.xml +++ b/pom.xml @@ -86,7 +86,7 @@ 6.5.0 - 5.8.0 + 5.9.0 3.2.1 2.2.15 2.2.0 From fe8d58f771f6093989716cf9440e48639fa57be1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Oct 2023 02:35:24 +0000 Subject: [PATCH 05/13] Bump net.javacrumbs.shedlock:shedlock-bom from 5.9.0 to 5.9.1 Bumps [net.javacrumbs.shedlock:shedlock-bom](https://github.com/lukas-krecan/ShedLock) from 5.9.0 to 5.9.1. - [Commits](https://github.com/lukas-krecan/ShedLock/compare/shedlock-parent-5.9.0...shedlock-parent-5.9.1) --- updated-dependencies: - dependency-name: net.javacrumbs.shedlock:shedlock-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1c5adcd3..993735a6 100644 --- a/pom.xml +++ b/pom.xml @@ -86,7 +86,7 @@ 6.5.0 - 5.9.0 + 5.9.1 3.2.1 2.2.15 2.2.0 From bee5c0764933059ce560acd9408bba5aeab8b830 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Oct 2023 02:35:42 +0000 Subject: [PATCH 06/13] Bump org.springframework.boot:spring-boot-starter-parent Bumps [org.springframework.boot:spring-boot-starter-parent](https://github.com/spring-projects/spring-boot) from 3.1.4 to 3.1.5. - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.1.4...v3.1.5) --- updated-dependencies: - dependency-name: org.springframework.boot:spring-boot-starter-parent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1c5adcd3..a8251124 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.4 + 3.1.5 From 337a84dd499b6654266d8a599b5701dde3a7c4ac Mon Sep 17 00:00:00 2001 From: Lubos Racansky Date: Tue, 24 Oct 2023 10:20:33 +0200 Subject: [PATCH 07/13] Fix #891: Change defaulting of locales for template finding --- .../database/OperationTemplateRepository.java | 11 ++ .../service/OperationTemplateService.java | 5 +- .../service/OperationTemplateServiceTest.java | 102 ++++++++++++++++++ 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 enrollment-server/src/test/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateServiceTest.java diff --git a/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/database/OperationTemplateRepository.java b/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/database/OperationTemplateRepository.java index ea0b6a01..40c60556 100644 --- a/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/database/OperationTemplateRepository.java +++ b/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/database/OperationTemplateRepository.java @@ -41,4 +41,15 @@ public interface OperationTemplateRepository extends CrudRepository findFirstByLanguageAndPlaceholder(String language, String placeholder); + /** + * Find an operation template by the given operation type. + *

+ * Just a fallback method when no entry found by {@link #findFirstByLanguageAndPlaceholder(String, String)}. + * + * @param placeholder operation type + * @return operation template or empty + * @see #findFirstByLanguageAndPlaceholder(String, String) + */ + Optional findFirstByPlaceholder(String placeholder); + } diff --git a/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateService.java b/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateService.java index 9ff16994..0c135835 100644 --- a/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateService.java +++ b/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateService.java @@ -53,7 +53,10 @@ public OperationTemplateService(OperationTemplateRepository operationTemplateRep public Optional findTemplate(@NotNull String operationType, @NotNull String language) { return operationTemplateRepository.findFirstByLanguageAndPlaceholder(language, operationType).or(() -> { logger.debug("Trying fallback to EN locale for operationType={}", operationType); - return operationTemplateRepository.findFirstByLanguageAndPlaceholder("en", operationType); + return operationTemplateRepository.findFirstByLanguageAndPlaceholder("en", operationType).or(() -> { + logger.debug("Trying fallback to any locale for operationType={}", operationType); + return operationTemplateRepository.findFirstByPlaceholder(operationType); + }); }); } diff --git a/enrollment-server/src/test/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateServiceTest.java b/enrollment-server/src/test/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateServiceTest.java new file mode 100644 index 00000000..a4a563ee --- /dev/null +++ b/enrollment-server/src/test/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateServiceTest.java @@ -0,0 +1,102 @@ +/* + * PowerAuth Enrollment Server + * Copyright (C) 2023 Wultra s.r.o. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package com.wultra.app.enrollmentserver.impl.service; + +import com.wultra.app.enrollmentserver.database.OperationTemplateRepository; +import com.wultra.app.enrollmentserver.database.entity.OperationTemplateEntity; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.when; + +/** + * Test for {@link OperationTemplateService}. + * + * @author Lubos Racansky, lubos.racansky@wultra.com + */ +@ExtendWith(MockitoExtension.class) +class OperationTemplateServiceTest { + + @Mock + private OperationTemplateRepository dao; + + @InjectMocks + private OperationTemplateService tested; + + @Test + void testFindTemplate_givenLanguage() { + final OperationTemplateEntity entity = new OperationTemplateEntity(); + when(dao.findFirstByLanguageAndPlaceholder("cs", "myTemplate")) + .thenReturn(Optional.of(entity)); + + final Optional result = tested.findTemplate("myTemplate", "cs"); + + assertTrue(result.isPresent()); + assertEquals(entity, result.get()); + } + + @Test + void testFindTemplate_fallbackToEnglish() { + final OperationTemplateEntity entity = new OperationTemplateEntity(); + when(dao.findFirstByLanguageAndPlaceholder("cs", "myTemplate")) + .thenReturn(Optional.empty()); + when(dao.findFirstByLanguageAndPlaceholder("en", "myTemplate")) + .thenReturn(Optional.of(entity)); + + final Optional result = tested.findTemplate("myTemplate", "cs"); + + assertTrue(result.isPresent()); + assertEquals(entity, result.get()); + } + + @Test + void testFindTemplate_fallbackToAnyLanguage() { + final OperationTemplateEntity entity = new OperationTemplateEntity(); + when(dao.findFirstByLanguageAndPlaceholder("cs", "myTemplate")) + .thenReturn(Optional.empty()); + when(dao.findFirstByLanguageAndPlaceholder("en", "myTemplate")) + .thenReturn(Optional.empty()); + when(dao.findFirstByPlaceholder("myTemplate")) + .thenReturn(Optional.of(entity)); + + final Optional result = tested.findTemplate("myTemplate", "cs"); + + assertTrue(result.isPresent()); + assertEquals(entity, result.get()); + } + + @Test + void testFindTemplate_notFound() { + when(dao.findFirstByLanguageAndPlaceholder("cs", "myTemplate")) + .thenReturn(Optional.empty()); + when(dao.findFirstByLanguageAndPlaceholder("en", "myTemplate")) + .thenReturn(Optional.empty()); + when(dao.findFirstByPlaceholder("myTemplate")) + .thenReturn(Optional.empty()); + + final Optional result = tested.findTemplate("myTemplate", "cs"); + + assertFalse(result.isPresent()); + } +} From 11c3d76d2a624087f7107601671af1107735709b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Ra=C4=8Dansk=C3=BD?= Date: Wed, 25 Oct 2023 15:08:22 +0200 Subject: [PATCH 08/13] Optimize defaulting of locales for template finding (#895) * Optimize defaulting of locales for template finding A follow-up to #891 --- .../service/OperationTemplateService.java | 32 +++++++++++++++---- .../service/OperationTemplateServiceTest.java | 18 ++++++++++- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateService.java b/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateService.java index 0c135835..9aafce22 100644 --- a/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateService.java +++ b/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateService.java @@ -36,6 +36,8 @@ @Slf4j public class OperationTemplateService { + private static final String DEFAULT_LANGUAGE = "en"; + private final OperationTemplateRepository operationTemplateRepository; @Autowired @@ -44,20 +46,36 @@ public OperationTemplateService(OperationTemplateRepository operationTemplateRep } /** - * Find the operation template for the given type and language. Falling back to EN locale. + * Find the operation template for the given type and language. + *

+ * Falling back to EN locale and later on to any found language. * * @param operationType Operation type. * @param language Template language. * @return Found operation template or empty. */ public Optional findTemplate(@NotNull String operationType, @NotNull String language) { - return operationTemplateRepository.findFirstByLanguageAndPlaceholder(language, operationType).or(() -> { + return operationTemplateRepository.findFirstByLanguageAndPlaceholder(language, operationType).or(() -> + findTemplateFallback(operationType, language)); + } + + private Optional findTemplateFallback(final String operationType, final String language) { + if (!DEFAULT_LANGUAGE.equals(language)) { logger.debug("Trying fallback to EN locale for operationType={}", operationType); - return operationTemplateRepository.findFirstByLanguageAndPlaceholder("en", operationType).or(() -> { - logger.debug("Trying fallback to any locale for operationType={}", operationType); - return operationTemplateRepository.findFirstByPlaceholder(operationType); - }); - }); + return findDefaultTemplate(operationType); + } else { + return findAnyTemplate(operationType); + } + } + + private Optional findDefaultTemplate(final String operationType) { + return operationTemplateRepository.findFirstByLanguageAndPlaceholder(DEFAULT_LANGUAGE, operationType).or(() -> + findAnyTemplate(operationType)); + } + + private Optional findAnyTemplate(final String operationType) { + logger.debug("Trying fallback to any locale for operationType={}", operationType); + return operationTemplateRepository.findFirstByPlaceholder(operationType); } } diff --git a/enrollment-server/src/test/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateServiceTest.java b/enrollment-server/src/test/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateServiceTest.java index a4a563ee..dd6a2fc3 100644 --- a/enrollment-server/src/test/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateServiceTest.java +++ b/enrollment-server/src/test/java/com/wultra/app/enrollmentserver/impl/service/OperationTemplateServiceTest.java @@ -28,7 +28,7 @@ import java.util.Optional; import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; /** * Test for {@link OperationTemplateService}. @@ -86,6 +86,22 @@ void testFindTemplate_fallbackToAnyLanguage() { assertEquals(entity, result.get()); } + @Test + void testFindTemplate_fallbackToAnyLanguage_optimizationOfEnglishLocale() { + final OperationTemplateEntity entity = new OperationTemplateEntity(); + when(dao.findFirstByLanguageAndPlaceholder("en", "myTemplate")) + .thenReturn(Optional.empty()); + when(dao.findFirstByPlaceholder("myTemplate")) + .thenReturn(Optional.of(entity)); + + final Optional result = tested.findTemplate("myTemplate", "en"); + + assertTrue(result.isPresent()); + assertEquals(entity, result.get()); + + verify(dao, times(1)).findFirstByLanguageAndPlaceholder("en", "myTemplate"); + } + @Test void testFindTemplate_notFound() { when(dao.findFirstByLanguageAndPlaceholder("cs", "myTemplate")) From 16674ebd896c99b4279bd43913274a42f1fba618 Mon Sep 17 00:00:00 2001 From: Lubos Racansky Date: Mon, 30 Oct 2023 10:24:43 +0100 Subject: [PATCH 09/13] Fix #899: Remove implicit commons-text dependency --- enrollment-server/pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/enrollment-server/pom.xml b/enrollment-server/pom.xml index 975117a1..f83dfcf4 100644 --- a/enrollment-server/pom.xml +++ b/enrollment-server/pom.xml @@ -111,13 +111,6 @@ postgresql - - - org.apache.commons - commons-text - 1.10.0 - - net.logstash.logback From 499d181e9fa3c5a72d9cd06aef39ccb14b99015a Mon Sep 17 00:00:00 2001 From: Lubos Racansky Date: Mon, 30 Oct 2023 14:58:26 +0100 Subject: [PATCH 10/13] Fix #902: Update Wultra dependencies to SNAPSHOT version --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 927da56b..aaf05b1b 100644 --- a/pom.xml +++ b/pom.xml @@ -92,10 +92,10 @@ 2.2.0 1.4.2 - 1.7.0 - 1.5.1 - 1.5.0 - 1.5.0 + 1.8.0-SNAPSHOT + 1.6.0-SNAPSHOT + 1.6.0-SNAPSHOT + 1.6.0-SNAPSHOT 1.76 7.4 From 026c70f950145f01b84f578279061ee96b525264 Mon Sep 17 00:00:00 2001 From: Lubos Racansky Date: Tue, 31 Oct 2023 11:16:38 +0100 Subject: [PATCH 11/13] Update commons-lang3 to 3.13.0 --- pom.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pom.xml b/pom.xml index aaf05b1b..53bbf72a 100644 --- a/pom.xml +++ b/pom.xml @@ -92,6 +92,9 @@ 2.2.0 1.4.2 + + 3.13.0 + 1.8.0-SNAPSHOT 1.6.0-SNAPSHOT 1.6.0-SNAPSHOT From c734bdf3ab37a8a65471ff76ed0dfd609dc73395 Mon Sep 17 00:00:00 2001 From: Jan Dusil <134381434+jandusil@users.noreply.github.com> Date: Thu, 2 Nov 2023 00:26:04 -0600 Subject: [PATCH 12/13] Fix #889: Executable war (#890) * Fix #889: Executable war --- docs-private/Developer-How-To-Start.md | 2 -- enrollment-server-onboarding/pom.xml | 16 ---------------- enrollment-server/pom.xml | 16 ---------------- pom.xml | 15 +++++++-------- 4 files changed, 7 insertions(+), 42 deletions(-) diff --git a/docs-private/Developer-How-To-Start.md b/docs-private/Developer-How-To-Start.md index b59929d3..3a0eaad7 100644 --- a/docs-private/Developer-How-To-Start.md +++ b/docs-private/Developer-How-To-Start.md @@ -6,7 +6,6 @@ ### Standalone Run -- Enable maven profile `standalone` - Use IntelliJ Idea run configuration at `../.run/EnrollmentServerApplication.run.xml` - Open [http://localhost:8081/enrollment-server/actuator/health](http://localhost:8081/enrollment-server/actuator/health) and you should get `{"status":"UP"}` @@ -59,7 +58,6 @@ docker run -p 80:8080 -e ENROLLMENT_SERVER_DATASOURCE_URL='jdbc:postgresql://hos ### Standalone Run -- Enable maven profile `standalone` - Use IntelliJ Idea run configuration at `../.run/EnrollmentServerOnboardingApplication.run.xml` - Open [http://localhost:8083/enrollment-server-onboarding/actuator/health](http://localhost:8083/enrollment-server-onboarding/actuator/health) and you should get `{"status":"UP"}` diff --git a/enrollment-server-onboarding/pom.xml b/enrollment-server-onboarding/pom.xml index 4a32fad9..324935d9 100644 --- a/enrollment-server-onboarding/pom.xml +++ b/enrollment-server-onboarding/pom.xml @@ -282,22 +282,6 @@ -Xdoclint:none - - standalone - - - org.springframework.boot - spring-boot-starter-tomcat - provided - - - - org.apache.tomcat.embed - tomcat-embed-el - provided - - - public-repository diff --git a/enrollment-server/pom.xml b/enrollment-server/pom.xml index f83dfcf4..11ef1516 100644 --- a/enrollment-server/pom.xml +++ b/enrollment-server/pom.xml @@ -216,22 +216,6 @@ -Xdoclint:none - - standalone - - - org.springframework.boot - spring-boot-starter-tomcat - provided - - - - org.apache.tomcat.embed - tomcat-embed-el - provided - - - public-repository diff --git a/pom.xml b/pom.xml index 53bbf72a..0fa5c095 100644 --- a/pom.xml +++ b/pom.xml @@ -164,12 +164,6 @@ io.getlime.security powerauth-restful-security-spring-annotation ${powerauth-restful-integration.version} - - - org.springframework.boot - spring-boot-starter-tomcat - - @@ -187,8 +181,13 @@ org.apache.tomcat.embed tomcat-embed-el - ${tomcat.version} - test + provided + + + + org.springframework.boot + spring-boot-starter-tomcat + provided From 6e6ddc6d8d899f1e1cd012482a79b083aea9e480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Ra=C4=8Dansk=C3=BD?= Date: Mon, 6 Nov 2023 10:27:39 +0100 Subject: [PATCH 13/13] Fix #896: Use different error when PAS operation approve fails (#901) * Fix #896: Use a different error when PAS operation approve fails --- docs/Mobile-Token-API.md | 19 ++++++----- .../DefaultExceptionHandler.java | 7 ++-- .../MobileTokenAuthException.java | 7 +++- .../impl/service/MobileTokenService.java | 33 +++++++++---------- .../mtoken/model/enumeration/ErrorCode.java | 15 +++------ 5 files changed, 41 insertions(+), 40 deletions(-) diff --git a/docs/Mobile-Token-API.md b/docs/Mobile-Token-API.md index a7ddf261..a3eaa723 100644 --- a/docs/Mobile-Token-API.md +++ b/docs/Mobile-Token-API.md @@ -75,15 +75,16 @@ Mobile token API provides access to operations. List of error codes in Mobile Token API: -| Code | Description | HTTP Status Code | -|---|---|---| -| `INVALID_REQUEST` | Invalid request sent - missing request object in request | 400 | -| `INVALID_ACTIVATION` | Activation is not valid (it is different from configured activation). Return this error in case the activation does not exist, or in case the activation is not allowed to perform the action (for example, user did not allow operation approvals on such device). | 400 | -| `POWERAUTH_AUTH_FAIL` | PowerAuth authentication failed | 401 | -| `OPERATION_ALREADY_FINISHED` | Operation is already finished | 400 | -| `OPERATION_ALREADY_FAILED` | Operation is already failed | 400 | -| `OPERATION_ALREADY_CANCELED` | Operation is already canceled | 400 | -| `OPERATION_EXPIRED` | Operation is expired | 400 | +| Code | Description | HTTP Status Code | +|------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------| +| `INVALID_REQUEST` | Invalid request sent - missing request object in request | 400 | +| `INVALID_ACTIVATION` | Activation is not valid (it is different from configured activation). Return this error in case the activation does not exist, or in case the activation is not allowed to perform the action (for example, user did not allow operation approvals on such device). | 400 | +| `POWERAUTH_AUTH_FAIL` | PowerAuth authentication failed | 401 | +| `OPERATION_ALREADY_FINISHED` | Operation is already finished | 400 | +| `OPERATION_ALREADY_FAILED` | Operation is already failed | 400 | +| `OPERATION_ALREADY_CANCELED` | Operation is already canceled | 400 | +| `OPERATION_EXPIRED` | Operation is expired | 400 | +| `OPERATION_FAILED` | PowerAuth server operation approval fails. | 401 | ## Localization diff --git a/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/errorhandling/DefaultExceptionHandler.java b/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/errorhandling/DefaultExceptionHandler.java index 685fd754..80ac42a4 100644 --- a/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/errorhandling/DefaultExceptionHandler.java +++ b/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/errorhandling/DefaultExceptionHandler.java @@ -18,6 +18,7 @@ package com.wultra.app.enrollmentserver.errorhandling; +import com.wultra.security.powerauth.lib.mtoken.model.enumeration.ErrorCode; import io.getlime.core.rest.model.base.response.ErrorResponse; import io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthAuthenticationException; import lombok.extern.slf4j.Slf4j; @@ -57,7 +58,7 @@ public class DefaultExceptionHandler { @ResponseStatus(HttpStatus.BAD_REQUEST) public @ResponseBody ErrorResponse handleInvalidRequestException(InvalidRequestObjectException ex) { logger.warn("Error occurred when processing request object.", ex); - return new ErrorResponse("INVALID_REQUEST", "Invalid request object."); + return new ErrorResponse(ErrorCode.INVALID_REQUEST, "Invalid request object."); } /** @@ -69,7 +70,7 @@ public class DefaultExceptionHandler { @ResponseStatus(HttpStatus.BAD_REQUEST) public @ResponseBody ErrorResponse handlePushRegistrationException(PushRegistrationFailedException ex) { logger.warn("Error occurred when registering to push server.", ex); - return new ErrorResponse("PUSH_REGISTRATION_FAILED", "Push registration failed in Mobile Token API component."); + return new ErrorResponse(ErrorCode.PUSH_REGISTRATION_FAILED, "Push registration failed in Mobile Token API component."); } /** @@ -81,7 +82,7 @@ public class DefaultExceptionHandler { @ResponseStatus(HttpStatus.UNAUTHORIZED) public @ResponseBody ErrorResponse handleUnauthorizedException(PowerAuthAuthenticationException ex) { logger.warn("Unable to verify device registration - authentication failed.", ex); - return new ErrorResponse("POWERAUTH_AUTH_FAIL", "Unable to verify device registration."); + return new ErrorResponse(ErrorCode.POWERAUTH_AUTH_FAIL, "Unable to verify device registration."); } /** diff --git a/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/errorhandling/MobileTokenAuthException.java b/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/errorhandling/MobileTokenAuthException.java index d2f5810a..28fdf0ec 100644 --- a/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/errorhandling/MobileTokenAuthException.java +++ b/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/errorhandling/MobileTokenAuthException.java @@ -18,6 +18,8 @@ package com.wultra.app.enrollmentserver.errorhandling; +import com.wultra.security.powerauth.lib.mtoken.model.enumeration.ErrorCode; + import java.io.Serial; /** @@ -31,7 +33,10 @@ public class MobileTokenAuthException extends MobileTokenException { private static final long serialVersionUID = -4602362062047233809L; public MobileTokenAuthException() { - super("POWERAUTH_AUTH_FAIL", "Authentication failed"); + super(ErrorCode.POWERAUTH_AUTH_FAIL, "Authentication failed"); } + public MobileTokenAuthException(final String code, final String message) { + super(code, message); + } } diff --git a/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/impl/service/MobileTokenService.java b/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/impl/service/MobileTokenService.java index c5aaa297..956032fa 100644 --- a/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/impl/service/MobileTokenService.java +++ b/enrollment-server/src/main/java/com/wultra/app/enrollmentserver/impl/service/MobileTokenService.java @@ -25,7 +25,6 @@ import com.wultra.app.enrollmentserver.impl.service.converter.MobileTokenConverter; import com.wultra.core.http.common.request.RequestContext; import com.wultra.security.powerauth.client.PowerAuthClient; -import com.wultra.security.powerauth.client.model.enumeration.OperationStatus; import com.wultra.security.powerauth.client.model.enumeration.SignatureType; import com.wultra.security.powerauth.client.model.enumeration.UserActionResult; import com.wultra.security.powerauth.client.model.error.PowerAuthClientException; @@ -35,6 +34,7 @@ import com.wultra.security.powerauth.client.model.response.OperationDetailResponse; import com.wultra.security.powerauth.client.model.response.OperationUserActionResponse; import com.wultra.security.powerauth.lib.mtoken.model.entity.Operation; +import com.wultra.security.powerauth.lib.mtoken.model.enumeration.ErrorCode; import com.wultra.security.powerauth.lib.mtoken.model.response.OperationListResponse; import io.getlime.core.rest.model.base.response.Response; import io.getlime.security.powerauth.rest.api.spring.service.HttpCustomizationService; @@ -181,8 +181,8 @@ public Response operationApprove(@NotNull final OperationApproveParameterObject return new Response(); } else { final OperationDetailResponse operation = approveResponse.getOperation(); - handleStatus(operation.getStatus()); - throw new MobileTokenAuthException(); + handleStatus(operation); + throw new MobileTokenAuthException(ErrorCode.OPERATION_FAILED, "PowerAuth server operation approval fails"); } } @@ -208,7 +208,7 @@ public void operationFailApprove(@NotNull String operationId, @NotNull RequestCo ); final OperationDetailResponse operation = failApprovalResponse.getOperation(); - handleStatus(operation.getStatus()); + handleStatus(operation); } /** @@ -262,8 +262,8 @@ public Response operationReject( return new Response(); } else { final OperationDetailResponse operation = rejectResponse.getOperation(); - handleStatus(operation.getStatus()); - throw new MobileTokenAuthException(); + handleStatus(operation); + throw new MobileTokenAuthException(ErrorCode.OPERATION_FAILED, "PowerAuth server operation rejection fails"); } } @@ -285,7 +285,7 @@ private OperationDetailResponse getOperationDetail(String operationId) throws Po httpCustomizationService.getQueryParams(), httpCustomizationService.getHttpHeaders() ); - handleStatus(operationDetail.getStatus()); + handleStatus(operationDetail); return operationDetail; } @@ -297,22 +297,21 @@ private OperationDetailResponse getOperationDetail(String operationId) throws Po *

  • CANCELLED, APPROVED, REJECTED, or EXPIRED - throws exception with appropriate code and message.
  • * * - * @param status Operation status. + * @param operation Operation detail. * @throws MobileTokenException In case operation is in status that does not allow processing, the method throws appropriate exception. */ - private void handleStatus(OperationStatus status) throws MobileTokenException { - switch (status) { - case PENDING -> { - // OK, this operation is still pending - } + private static void handleStatus(final OperationDetailResponse operation) throws MobileTokenException { + switch (operation.getStatus()) { + case PENDING -> + logger.debug("OK, operation ID: {} is still pending", operation.getId()); case CANCELED -> - throw new MobileTokenException("OPERATION_ALREADY_CANCELED", "Operation was already canceled"); + throw new MobileTokenException(ErrorCode.OPERATION_ALREADY_CANCELED, "Operation was already canceled"); case APPROVED, REJECTED -> - throw new MobileTokenException("OPERATION_ALREADY_FINISHED", "Operation was already completed"); + throw new MobileTokenException(ErrorCode.OPERATION_ALREADY_FINISHED, "Operation was already completed"); case FAILED -> - throw new MobileTokenException("OPERATION_ALREADY_FAILED", "Operation already failed"); + throw new MobileTokenException(ErrorCode.OPERATION_ALREADY_FAILED, "Operation already failed"); default -> - throw new MobileTokenException("OPERATION_EXPIRED", "Operation already expired"); + throw new MobileTokenException(ErrorCode.OPERATION_EXPIRED, "Operation already expired"); } } diff --git a/mtoken-model/src/main/java/com/wultra/security/powerauth/lib/mtoken/model/enumeration/ErrorCode.java b/mtoken-model/src/main/java/com/wultra/security/powerauth/lib/mtoken/model/enumeration/ErrorCode.java index e14e922a..a6ef3225 100644 --- a/mtoken-model/src/main/java/com/wultra/security/powerauth/lib/mtoken/model/enumeration/ErrorCode.java +++ b/mtoken-model/src/main/java/com/wultra/security/powerauth/lib/mtoken/model/enumeration/ErrorCode.java @@ -36,16 +36,6 @@ public class ErrorCode { */ public static final String INVALID_REQUEST = "INVALID_REQUEST"; - /** - * Error code for situation when an activation is not active. - */ - public static final String ACTIVATION_NOT_ACTIVE = "ACTIVATION_NOT_ACTIVE"; - - /** - * Error code for situation when an activation is not configured. - */ - public static final String ACTIVATION_NOT_CONFIGURED = "ACTIVATION_NOT_CONFIGURED"; - /** * Error code for situation when an invalid activation / device is * attempted for operation manipulation. @@ -75,6 +65,11 @@ public class ErrorCode { */ public static final String OPERATION_ALREADY_CANCELED = "OPERATION_ALREADY_CANCELED"; + /** + * Error code for situation when PowerAuth server operation approval fails. + */ + public static final String OPERATION_FAILED = "OPERATION_FAILED"; + /** * Error code for situation when an operation expired and yet, some further * action was requested with that operation.