From c26b12db2c34e80b826d8c4cf6efcc790b8051c8 Mon Sep 17 00:00:00 2001 From: "Marc B." <125284318+M-Busk@users.noreply.github.com> Date: Thu, 13 Feb 2025 15:43:47 +0100 Subject: [PATCH] PI-872: adjust to code suggestions from sonarlint (#60) * clean up java classes * cleanup frontend issues --- backend/build.gradle.kts | 14 ++- .../configuration/AppConfigurer.java | 54 +++++----- .../BoundaryExceptionHandler.java | 2 +- .../ParticipantRegistrationRestApiMapper.java | 2 - ...ParticipantExtensionCredentialSubject.java | 2 +- .../ParticipantRegistrationServiceMapper.java | 6 -- .../possiblex/portal/utilities/LogUtils.java | 7 +- .../portal/PortalApplicationTests.java | 4 +- .../boundary/CommonPortalModuleTest.java | 2 +- ...rticipantRegistrationEntityMapperTest.java | 98 ++++++++++--------- ...ParticipantRegistrationRequestDAOFake.java | 41 +++----- ...ParticipantRegistrationRequestDAOTest.java | 14 ++- frontend/Dockerfile | 7 +- frontend/build.gradle.kts | 11 --- frontend/src/app/app.module.ts | 11 +-- .../default-layout.component.ts | 2 +- .../src/app/interceptors/auth.interceptor.ts | 13 +-- frontend/src/app/sdwizard/shared/utils.ts | 6 +- .../services/mgmt/api/angular-http-client.ts | 2 +- .../src/app/services/mgmt/api/api.service.ts | 4 +- .../app/services/mgmt/auth/auth.service.ts | 6 +- .../registration-request.component.ts | 6 +- .../views/impressum/impressum.component.scss | 1 - .../src/app/views/login/login.component.ts | 4 +- .../base-wizard-extension.component.ts | 8 +- .../participant-wizard-extension.component.ts | 8 +- 26 files changed, 161 insertions(+), 174 deletions(-) diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 9f7bdba..3cca1e4 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -43,18 +43,24 @@ dependencies { implementation(libs.titaniumJsonLd) implementation(libs.jakartaJson) implementation(libs.postgresql) - compileOnly(libs.lombok) - annotationProcessor(libs.lombokMapStructBinding) implementation(libs.mapStruct) + + annotationProcessor(libs.lombokMapStructBinding) annotationProcessor(libs.mapStructProcessor) - developmentOnly(libs.springBootDevtools) - runtimeOnly(libs.therApi) annotationProcessor(libs.lombok) annotationProcessor(libs.therApiScribe) + + developmentOnly(libs.springBootDevtools) + + runtimeOnly(libs.therApi) + + compileOnly(libs.lombok) + testImplementation(libs.springBootStarterTest) testImplementation(libs.reactorTest) testImplementation(libs.h2) testImplementation(libs.springSecurityTest) + testRuntimeOnly(libs.jUnit) } diff --git a/backend/src/main/java/eu/possiblex/portal/application/configuration/AppConfigurer.java b/backend/src/main/java/eu/possiblex/portal/application/configuration/AppConfigurer.java index 48297ed..47f33cd 100644 --- a/backend/src/main/java/eu/possiblex/portal/application/configuration/AppConfigurer.java +++ b/backend/src/main/java/eu/possiblex/portal/application/configuration/AppConfigurer.java @@ -7,9 +7,6 @@ import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; - -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Value; @@ -27,16 +24,14 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.provisioning.InMemoryUserDetailsManager; +import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.security.web.SecurityFilterChain; -import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; -import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.support.WebClientAdapter; import org.springframework.web.service.invoker.HttpServiceProxyFactory; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.security.web.AuthenticationEntryPoint; import reactor.netty.http.client.HttpClient; import javax.net.ssl.SSLException; @@ -126,46 +121,41 @@ public TechnicalFhCatalogClient fhCatalogClient() { } @Bean - public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { - http.authorizeHttpRequests((authorizeHttpRequests) -> - authorizeHttpRequests - .requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() - .requestMatchers(HttpMethod.POST, "/registration/request").permitAll() - .requestMatchers("/registration/**").authenticated() - .anyRequest().permitAll() - ) + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + + http.authorizeHttpRequests( + authorizeHttpRequests -> authorizeHttpRequests.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() + .requestMatchers(HttpMethod.POST, "/registration/request").permitAll() + .requestMatchers("/registration/**").authenticated().anyRequest().permitAll()) .httpBasic(basic -> basic.authenticationEntryPoint(new CustomAuthenticationEntryPoint())) - .csrf(AbstractHttpConfigurer::disable) - .cors(Customizer.withDefaults()); + .csrf(AbstractHttpConfigurer::disable).cors(Customizer.withDefaults()); return http.build(); - } + } @Bean - public UserDetailsService userDetailsService() { - UserDetails admin = - User.builder() - .username(adminUsername) - .password(passwordEncoder().encode(adminPassword)) - .roles("ADMIN") - .build(); + public UserDetailsService userDetailsService() { - return new InMemoryUserDetailsManager(admin); - } + UserDetails admin = User.builder().username(adminUsername).password(passwordEncoder().encode(adminPassword)) + .roles("ADMIN").build(); + + return new InMemoryUserDetailsManager(admin); + } @Bean public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); } @Bean public WebMvcConfigurer corsConfigurer() { + return new WebMvcConfigurer() { @Override public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedOriginPatterns("*") - .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") - .allowedHeaders("*") + + registry.addMapping("/**").allowedOriginPatterns("*") + .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS").allowedHeaders("*") .allowCredentials(true); } }; @@ -174,7 +164,9 @@ public void addCorsMappings(CorsRegistry registry) { private class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint { @Override - public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { + public void commence(HttpServletRequest request, HttpServletResponse response, + AuthenticationException authException) throws IOException { + response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setHeader("WWW-Authenticate", ""); response.getWriter().write("Unauthorized"); diff --git a/backend/src/main/java/eu/possiblex/portal/application/configuration/BoundaryExceptionHandler.java b/backend/src/main/java/eu/possiblex/portal/application/configuration/BoundaryExceptionHandler.java index f1ad844..57c3c83 100644 --- a/backend/src/main/java/eu/possiblex/portal/application/configuration/BoundaryExceptionHandler.java +++ b/backend/src/main/java/eu/possiblex/portal/application/configuration/BoundaryExceptionHandler.java @@ -73,7 +73,7 @@ public ResponseEntity handleMethodArgumentNotValid(@NonNull MethodArgume logError(ex); Map errors = new HashMap<>(); - ex.getBindingResult().getAllErrors().forEach((error) -> { + ex.getBindingResult().getAllErrors().forEach(error -> { String fieldName = ((FieldError) error).getField(); String errorMessage = error.getDefaultMessage(); errors.put(fieldName, errorMessage); diff --git a/backend/src/main/java/eu/possiblex/portal/application/control/ParticipantRegistrationRestApiMapper.java b/backend/src/main/java/eu/possiblex/portal/application/control/ParticipantRegistrationRestApiMapper.java index 5f541d6..ca2c62d 100644 --- a/backend/src/main/java/eu/possiblex/portal/application/control/ParticipantRegistrationRestApiMapper.java +++ b/backend/src/main/java/eu/possiblex/portal/application/control/ParticipantRegistrationRestApiMapper.java @@ -1,8 +1,6 @@ package eu.possiblex.portal.application.control; import eu.possiblex.portal.application.entity.CreateRegistrationRequestTO; -import eu.possiblex.portal.application.entity.credentials.gx.participants.GxLegalRegistrationNumberCredentialSubject; -import eu.possiblex.portal.business.entity.credentials.px.GxNestedLegalRegistrationNumberCredentialSubject; import eu.possiblex.portal.business.entity.credentials.px.PxExtendedLegalParticipantCredentialSubject; import org.mapstruct.Mapper; import org.mapstruct.Mapping; diff --git a/backend/src/main/java/eu/possiblex/portal/application/entity/credentials/px/participants/PxParticipantExtensionCredentialSubject.java b/backend/src/main/java/eu/possiblex/portal/application/entity/credentials/px/participants/PxParticipantExtensionCredentialSubject.java index e7363e4..f8a8ed9 100644 --- a/backend/src/main/java/eu/possiblex/portal/application/entity/credentials/px/participants/PxParticipantExtensionCredentialSubject.java +++ b/backend/src/main/java/eu/possiblex/portal/application/entity/credentials/px/participants/PxParticipantExtensionCredentialSubject.java @@ -39,7 +39,7 @@ public class PxParticipantExtensionCredentialSubject extends PojoCredentialSubje @JsonProperty("px:mailAddress") @JsonSerialize(using = StringSerializer.class) @JsonDeserialize(using = StringDeserializer.class) - @Pattern(regexp = "^((?!\\.)[\\w\\-_.]*[^.])(@\\w+)(\\.\\w+(\\.\\w+)?[^.\\W])$", message = "Mail address must be a valid email address") + @Pattern(regexp = "^((?!\\.)[\\w\\-.]*[^.])(@[\\w-]+)(\\.\\w+(\\.\\w+)?\\w)$", message = "Mail address must be a valid email address") private String mailAddress; @JsonProperty("type") diff --git a/backend/src/main/java/eu/possiblex/portal/business/control/ParticipantRegistrationServiceMapper.java b/backend/src/main/java/eu/possiblex/portal/business/control/ParticipantRegistrationServiceMapper.java index 5bd791b..66fc2de 100644 --- a/backend/src/main/java/eu/possiblex/portal/business/control/ParticipantRegistrationServiceMapper.java +++ b/backend/src/main/java/eu/possiblex/portal/business/control/ParticipantRegistrationServiceMapper.java @@ -1,14 +1,8 @@ package eu.possiblex.portal.business.control; -import eu.possiblex.portal.application.entity.AddressTO; -import eu.possiblex.portal.application.entity.ParticipantDidDataTO; -import eu.possiblex.portal.application.entity.RegistrationNumberTO; import eu.possiblex.portal.application.entity.RegistrationRequestEntryTO; -import eu.possiblex.portal.application.entity.credentials.gx.datatypes.GxVcard; -import eu.possiblex.portal.application.entity.credentials.gx.participants.GxLegalRegistrationNumberCredentialSubject; import eu.possiblex.portal.business.entity.ParticipantRegistrationRequestBE; import eu.possiblex.portal.business.entity.credentials.px.PxExtendedLegalParticipantCredentialSubject; -import eu.possiblex.portal.business.entity.did.ParticipantDidBE; import org.mapstruct.Mapper; import org.mapstruct.Mapping; diff --git a/backend/src/main/java/eu/possiblex/portal/utilities/LogUtils.java b/backend/src/main/java/eu/possiblex/portal/utilities/LogUtils.java index 4f8dede..f3f8f34 100644 --- a/backend/src/main/java/eu/possiblex/portal/utilities/LogUtils.java +++ b/backend/src/main/java/eu/possiblex/portal/utilities/LogUtils.java @@ -6,8 +6,11 @@ @Slf4j /* * Some util functions for logging. - */ -public class LogUtils { + */ public class LogUtils { + + private LogUtils() { + // private constructor to prevent instantiation + } /** * Serialize an object to JSON. diff --git a/backend/src/test/java/eu/possiblex/portal/PortalApplicationTests.java b/backend/src/test/java/eu/possiblex/portal/PortalApplicationTests.java index f4b53fc..f47fb15 100644 --- a/backend/src/test/java/eu/possiblex/portal/PortalApplicationTests.java +++ b/backend/src/test/java/eu/possiblex/portal/PortalApplicationTests.java @@ -5,12 +5,12 @@ import org.springframework.test.context.TestPropertySource; @SpringBootTest -@TestPropertySource(properties = {"version.no = thisistheversion", "version.date = 21.03.2022"}) +@TestPropertySource(properties = { "version.no = thisistheversion", "version.date = 21.03.2022" }) class PortalApplicationTests { @Test void contextLoads() { - + // basic context loading test } } diff --git a/backend/src/test/java/eu/possiblex/portal/application/boundary/CommonPortalModuleTest.java b/backend/src/test/java/eu/possiblex/portal/application/boundary/CommonPortalModuleTest.java index 923bc1b..4486563 100644 --- a/backend/src/test/java/eu/possiblex/portal/application/boundary/CommonPortalModuleTest.java +++ b/backend/src/test/java/eu/possiblex/portal/application/boundary/CommonPortalModuleTest.java @@ -20,7 +20,7 @@ @TestPropertySource(properties = { "version.no = thisistheversion", "version.date = 21.03.2022", "fh.catalog.ui-url = http://localhost:8080" }) @Import(CommonPortalRestApiImpl.class) -public class CommonPortalModuleTest { +class CommonPortalModuleTest { @Autowired private MockMvc mockMvc; diff --git a/backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationEntityMapperTest.java b/backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationEntityMapperTest.java index fd9bab8..9149ff6 100644 --- a/backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationEntityMapperTest.java +++ b/backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationEntityMapperTest.java @@ -1,6 +1,7 @@ package eu.possiblex.portal.persistence.dao; import eu.possiblex.portal.application.entity.credentials.gx.datatypes.GxVcard; +import eu.possiblex.portal.application.entity.credentials.gx.participants.GxLegalRegistrationNumberCredentialSubject; import eu.possiblex.portal.business.entity.ParticipantRegistrationRequestBE; import eu.possiblex.portal.business.entity.credentials.px.GxNestedLegalRegistrationNumberCredentialSubject; import eu.possiblex.portal.business.entity.credentials.px.PxExtendedLegalParticipantCredentialSubject; @@ -28,6 +29,50 @@ class ParticipantRegistrationEntityMapperTest { @Autowired private ParticipantRegistrationEntityMapper participantRegistrationServiceMapper; + private static void assertAddressIsEqual(GxVcard expected, VcardEntity actual) { + + assertEquals(expected.getCountryCode(), actual.getCountryCode()); + assertEquals(expected.getCountrySubdivisionCode(), actual.getCountrySubdivisionCode()); + assertEquals(expected.getStreetAddress(), actual.getStreetAddress()); + assertEquals(expected.getLocality(), actual.getLocality()); + assertEquals(expected.getPostalCode(), actual.getPostalCode()); + } + + private static void assertAddressIsEqual(VcardEntity expected, GxVcard actual) { + + assertEquals(expected.getCountryCode(), actual.getCountryCode()); + assertEquals(expected.getCountrySubdivisionCode(), actual.getCountrySubdivisionCode()); + assertEquals(expected.getStreetAddress(), actual.getStreetAddress()); + assertEquals(expected.getLocality(), actual.getLocality()); + assertEquals(expected.getPostalCode(), actual.getPostalCode()); + } + + private static void assertRegistrationNumberIsEqual(GxNestedLegalRegistrationNumberCredentialSubject expected, + RegistrationNumberEntity actual) { + + assertEquals(expected.getEori(), actual.getEori()); + assertEquals(expected.getVatID(), actual.getVatID()); + assertEquals(expected.getLeiCode(), actual.getLeiCode()); + } + + private static void assertRegistrationNumberIsEqual(RegistrationNumberEntity expected, + GxLegalRegistrationNumberCredentialSubject actual) { + + assertEquals(expected.getEori(), actual.getEori()); + assertEquals(expected.getVatID(), actual.getVatID()); + assertEquals(expected.getLeiCode(), actual.getLeiCode()); + } + + private static void assertConnectorCertificateIsEqual(OmejdnConnectorCertificateEntity expected, + OmejdnConnectorCertificateBE actual) { + + assertEquals(expected.getClientId(), actual.getClientId()); + assertEquals(expected.getClientName(), actual.getClientName()); + assertEquals(expected.getScope(), actual.getScope()); + assertEquals(expected.getKeystore(), actual.getKeystore()); + assertEquals(expected.getPassword(), actual.getPassword()); + } + @Test void mapParticipantCredentialSubjectToEntity() { // given @@ -52,23 +97,10 @@ void mapParticipantCredentialSubjectToEntity() { assertEquals(cs.getDescription(), entity.getDescription()); assertEquals(cs.getMailAddress(), entity.getEmailAddress()); - assertEquals(cs.getLegalAddress().getCountryCode(), entity.getLegalAddress().getCountryCode()); - assertEquals(cs.getLegalAddress().getCountrySubdivisionCode(), - entity.getLegalAddress().getCountrySubdivisionCode()); - assertEquals(cs.getLegalAddress().getStreetAddress(), entity.getLegalAddress().getStreetAddress()); - assertEquals(cs.getLegalAddress().getLocality(), entity.getLegalAddress().getLocality()); - assertEquals(cs.getLegalAddress().getPostalCode(), entity.getLegalAddress().getPostalCode()); - - assertEquals(cs.getHeadquarterAddress().getCountryCode(), entity.getHeadquarterAddress().getCountryCode()); - assertEquals(cs.getHeadquarterAddress().getCountrySubdivisionCode(), - entity.getHeadquarterAddress().getCountrySubdivisionCode()); - assertEquals(cs.getHeadquarterAddress().getStreetAddress(), entity.getHeadquarterAddress().getStreetAddress()); - assertEquals(cs.getHeadquarterAddress().getLocality(), entity.getHeadquarterAddress().getLocality()); - assertEquals(cs.getHeadquarterAddress().getPostalCode(), entity.getHeadquarterAddress().getPostalCode()); - - assertEquals(cs.getLegalRegistrationNumber().getEori(), entity.getLegalRegistrationNumber().getEori()); - assertEquals(cs.getLegalRegistrationNumber().getVatID(), entity.getLegalRegistrationNumber().getVatID()); - assertEquals(cs.getLegalRegistrationNumber().getLeiCode(), entity.getLegalRegistrationNumber().getLeiCode()); + assertAddressIsEqual(cs.getLegalAddress(), entity.getLegalAddress()); + assertAddressIsEqual(cs.getHeadquarterAddress(), entity.getHeadquarterAddress()); + + assertRegistrationNumberIsEqual(cs.getLegalRegistrationNumber(), entity.getLegalRegistrationNumber()); } @Test @@ -89,33 +121,11 @@ void mapParticipantEntityToParticipantRegistrationRequestBe() { assertEquals(entity.getStatus().name(), be.getStatus().name()); assertEquals(entity.getVpLink(), be.getVpLink()); - assertEquals(entity.getLegalRegistrationNumber().getEori(), be.getLegalRegistrationNumber().getEori()); - assertEquals(entity.getLegalRegistrationNumber().getVatID(), be.getLegalRegistrationNumber().getVatID()); - assertEquals(entity.getLegalRegistrationNumber().getLeiCode(), be.getLegalRegistrationNumber().getLeiCode()); - - assertEquals(entity.getLegalAddress().getCountryCode(), be.getLegalAddress().getCountryCode()); - assertEquals(entity.getLegalAddress().getCountrySubdivisionCode(), - be.getLegalAddress().getCountrySubdivisionCode()); - assertEquals(entity.getLegalAddress().getStreetAddress(), be.getLegalAddress().getStreetAddress()); - assertEquals(entity.getLegalAddress().getLocality(), be.getLegalAddress().getLocality()); - assertEquals(entity.getLegalAddress().getPostalCode(), be.getLegalAddress().getPostalCode()); - - assertEquals(entity.getHeadquarterAddress().getCountryCode(), be.getHeadquarterAddress().getCountryCode()); - assertEquals(entity.getHeadquarterAddress().getCountrySubdivisionCode(), - be.getHeadquarterAddress().getCountrySubdivisionCode()); - assertEquals(entity.getHeadquarterAddress().getStreetAddress(), be.getHeadquarterAddress().getStreetAddress()); - assertEquals(entity.getHeadquarterAddress().getLocality(), be.getHeadquarterAddress().getLocality()); - assertEquals(entity.getHeadquarterAddress().getPostalCode(), be.getHeadquarterAddress().getPostalCode()); - - assertEquals(entity.getOmejdnConnectorCertificate().getClientId(), - be.getOmejdnConnectorCertificate().getClientId()); - assertEquals(entity.getOmejdnConnectorCertificate().getClientName(), - be.getOmejdnConnectorCertificate().getClientName()); - assertEquals(entity.getOmejdnConnectorCertificate().getKeystore(), - be.getOmejdnConnectorCertificate().getKeystore()); - assertEquals(entity.getOmejdnConnectorCertificate().getPassword(), - be.getOmejdnConnectorCertificate().getPassword()); - assertEquals(entity.getOmejdnConnectorCertificate().getScope(), be.getOmejdnConnectorCertificate().getScope()); + assertRegistrationNumberIsEqual(entity.getLegalRegistrationNumber(), be.getLegalRegistrationNumber()); + assertAddressIsEqual(entity.getLegalAddress(), be.getLegalAddress()); + assertAddressIsEqual(entity.getHeadquarterAddress(), be.getHeadquarterAddress()); + + assertConnectorCertificateIsEqual(entity.getOmejdnConnectorCertificate(), be.getOmejdnConnectorCertificate()); assertEquals(entity.getDidData().getDid(), be.getDidData().getDid()); assertEquals(entity.getDidData().getVerificationMethod(), be.getDidData().getVerificationMethod()); diff --git a/backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationRequestDAOFake.java b/backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationRequestDAOFake.java index 56a32dc..4231947 100644 --- a/backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationRequestDAOFake.java +++ b/backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationRequestDAOFake.java @@ -94,13 +94,7 @@ public void saveParticipantRegistrationRequest(PxExtendedLegalParticipantCredent @Override public void acceptRegistrationRequest(String id) { - if (id.equals(NON_EXISTING_NAME)) { - throw new ParticipantEntityNotFoundException("Participant not found"); - } - - if (id.equals(BAD_TRANSITION_NAME)) { - throw new ParticipantEntityStateTransitionException("Bad Transition"); - } + handleIdExceptions(id); // request worked } @@ -108,13 +102,7 @@ public void acceptRegistrationRequest(String id) { @Override public void rejectRegistrationRequest(String id) { - if (id.equals(NON_EXISTING_NAME)) { - throw new ParticipantEntityNotFoundException("Participant not found"); - } - - if (id.equals(BAD_TRANSITION_NAME)) { - throw new ParticipantEntityStateTransitionException("Bad Transition"); - } + handleIdExceptions(id); // request worked } @@ -122,13 +110,7 @@ public void rejectRegistrationRequest(String id) { @Override public void deleteRegistrationRequest(String id) { - if (id.equals(NON_EXISTING_NAME)) { - throw new ParticipantEntityNotFoundException("Participant not found"); - } - - if (id.equals(BAD_TRANSITION_NAME)) { - throw new ParticipantEntityStateTransitionException("Bad Transition"); - } + handleIdExceptions(id); // request worked } @@ -137,11 +119,9 @@ public void deleteRegistrationRequest(String id) { public void completeRegistrationRequest(String id, ParticipantDidBE did, String vpLink, OmejdnConnectorCertificateBE certificate) { - if (id.equals(NON_EXISTING_NAME)) { - throw new ParticipantEntityNotFoundException("Participant not found"); - } + handleIdExceptions(id); - if (id.equals(BAD_TRANSITION_NAME) || id.equals(BAD_COMPLETION_NAME)) { + if (id.equals(BAD_COMPLETION_NAME)) { throw new ParticipantEntityStateTransitionException("Bad Transition"); } @@ -158,4 +138,15 @@ public ParticipantRegistrationRequestBE getRegistrationRequestByName(String name return getExampleParticipant(); } + + private void handleIdExceptions(String id) { + + if (id.equals(NON_EXISTING_NAME)) { + throw new ParticipantEntityNotFoundException("Participant not found"); + } + + if (id.equals(BAD_TRANSITION_NAME)) { + throw new ParticipantEntityStateTransitionException("Bad Transition"); + } + } } diff --git a/backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationRequestDAOTest.java b/backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationRequestDAOTest.java index cfbca21..59546fb 100644 --- a/backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationRequestDAOTest.java +++ b/backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationRequestDAOTest.java @@ -117,19 +117,25 @@ void completeRegistrationRequestSuccess() { @Test void completeRegistrationRequestNotExistingParticipant() { + ParticipantDidBE participantDidBE = new ParticipantDidBE("validDid", "validVerificationMethod"); + OmejdnConnectorCertificateBE omejdnConnectorCertificateBE = new OmejdnConnectorCertificateBE("validClientId", + "validPassword", "validKeystore", "123", "1234"); + assertThrows(ParticipantEntityNotFoundException.class, () -> participantRegistrationRequestDAO.completeRegistrationRequest("notExistingParticipant", - new ParticipantDidBE("validDid", "validVerificationMethod"), "validVpLink", - new OmejdnConnectorCertificateBE("validClientId", "validPassword", "validKeystore", "123", "1234"))); + participantDidBE, "validVpLink", omejdnConnectorCertificateBE)); } @Test void completeRegistrationRequestNotAcceptedParticipant() { + ParticipantDidBE participantDidBE = new ParticipantDidBE("validDid", "validVerificationMethod"); + OmejdnConnectorCertificateBE omejdnConnectorCertificateBE = new OmejdnConnectorCertificateBE("validClientId", + "validPassword", "validKeystore", "123", "1234"); + assertThrows(ParticipantEntityStateTransitionException.class, () -> participantRegistrationRequestDAO.completeRegistrationRequest(EXAMPLE_PARTICIPANT_NAME, - new ParticipantDidBE("validDid", "validVerificationMethod"), "validVpLink", - new OmejdnConnectorCertificateBE("validClientId", "validPassword", "validKeystore", "123", "1234"))); + participantDidBE, "validVpLink", omejdnConnectorCertificateBE)); } @Test diff --git a/frontend/Dockerfile b/frontend/Dockerfile index a3d2043..f5be5bf 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -4,10 +4,13 @@ ARG ACTIVEPROFILE # install chrome headless RUN apt-get update && \ apt-get -y upgrade && \ - apt-get install -yq curl libgconf-2-4 gnupg wget + apt-get install -yq curl gnupg libgconf-2-4 wget RUN curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb stable main' >> /etc/apt/sources.list.d/google-chrome.list -RUN apt-get update && apt-get install -y --no-install-recommends google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + fonts-ipafont-gothic fonts-kacst fonts-thai-tlwg \ + fonts-wqy-zenhei google-chrome-stable WORKDIR /home/gradle/src COPY --chown=gradle:gradle . . diff --git a/frontend/build.gradle.kts b/frontend/build.gradle.kts index 20ed795..6996ed7 100644 --- a/frontend/build.gradle.kts +++ b/frontend/build.gradle.kts @@ -62,14 +62,3 @@ tasks { args.set(listOf("run", "test", "--", "--no-watch", "--no-progress", "--browsers=ChromeHeadlessNoSandbox")) } } - -// run npm test only with build task -tasks.register("npmTestConditional") { - if (gradle.startParameter.getTaskNames().contains("build")) { - println("do npm tests") - dependsOn(tasks.getByName("npmFeTest")) - } else { - println("skip npm tests") - dependsOn(tasks.getByName("npmBuild")) - } -} diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 00c1362..4b54174 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -8,6 +8,9 @@ import {WizardExtensionModule} from './wizard-extension/wizard-extension.module' import {WizardAppModule} from './sdwizard/wizardapp.module'; import { + AccordionButtonDirective, + AccordionComponent, + AccordionItemComponent, AvatarModule, BadgeModule, BreadcrumbModule, @@ -27,16 +30,12 @@ import { SharedModule, SidebarModule, TabsModule, - UtilitiesModule, - AccordionComponent, - AccordionItemComponent, TemplateIdDirective, - AccordionButtonDirective + UtilitiesModule } from '@coreui/angular'; import {DefaultLayoutComponent} from './containers'; import {NgOptimizedImage} from "@angular/common"; -import {HomeModule} from "./views/home/home.module"; -import { AuthInterceptor } from './interceptors/auth.interceptor'; +import {AuthInterceptor} from './interceptors/auth.interceptor'; import {MaterialModule} from "./sdwizard/material.module"; @NgModule({ diff --git a/frontend/src/app/containers/default-layout/default-layout.component.ts b/frontend/src/app/containers/default-layout/default-layout.component.ts index 2680f0d..ecc35b5 100644 --- a/frontend/src/app/containers/default-layout/default-layout.component.ts +++ b/frontend/src/app/containers/default-layout/default-layout.component.ts @@ -16,7 +16,7 @@ export class DefaultLayoutComponent implements OnInit { versionNumber: string = ''; versionDate: string = ''; - constructor(private router: Router, private apiService: ApiService, protected auth: AuthService) { + constructor(private readonly router: Router, private readonly apiService: ApiService, protected auth: AuthService) { this.router.events.subscribe(event => { if (event instanceof NavigationEnd) { this.isAdminPage = event.urlAfterRedirects.includes('administration/management'); diff --git a/frontend/src/app/interceptors/auth.interceptor.ts b/frontend/src/app/interceptors/auth.interceptor.ts index 8c4138d..6d9e1b2 100644 --- a/frontend/src/app/interceptors/auth.interceptor.ts +++ b/frontend/src/app/interceptors/auth.interceptor.ts @@ -1,18 +1,19 @@ -import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import {Observable, catchError, throwError} from 'rxjs'; +import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http'; +import {Injectable} from '@angular/core'; +import {Observable} from 'rxjs'; import {Router} from "@angular/router"; import {AuthService} from "../services/mgmt/auth/auth.service"; @Injectable() export class AuthInterceptor implements HttpInterceptor { - constructor(private router: Router, private auth: AuthService) {} + constructor(private readonly router: Router, private readonly auth: AuthService) { + } intercept(req: HttpRequest, next: HttpHandler): Observable> { // basic authentification for /registration/** path except POST /registration/request - if (req.url.includes("/registration/") && !(req.url.match("\/registration\/request$") && req.method === "POST")) { - var authToken = this.auth.getToken(); + if (req.url.includes("/registration/") && !(/\/registration\/request$/.exec(req.url) && req.method === "POST")) { + const authToken = this.auth.getToken(); if (authToken) { req = req.clone({ setHeaders: { diff --git a/frontend/src/app/sdwizard/shared/utils.ts b/frontend/src/app/sdwizard/shared/utils.ts index 58a4168..08a9f92 100644 --- a/frontend/src/app/sdwizard/shared/utils.ts +++ b/frontend/src/app/sdwizard/shared/utils.ts @@ -70,7 +70,7 @@ export class Utils { return result; } - static filterInPlace = (array, predicate) => { + static readonly filterInPlace = (array, predicate) => { let end = 0; array.forEach(obj => { if (predicate(obj)) { @@ -85,10 +85,10 @@ export class Utils { return input; } - static hasRequiredField = (abstractControl: AbstractControl): boolean => { + static readonly hasRequiredField = (abstractControl: AbstractControl): boolean => { if (abstractControl.validator) { const validator = abstractControl.validator({} as AbstractControl); - if (validator && validator.required) { + if (validator?.required) { return true; } } diff --git a/frontend/src/app/services/mgmt/api/angular-http-client.ts b/frontend/src/app/services/mgmt/api/angular-http-client.ts index d8fc57c..2a55075 100644 --- a/frontend/src/app/services/mgmt/api/angular-http-client.ts +++ b/frontend/src/app/services/mgmt/api/angular-http-client.ts @@ -5,7 +5,7 @@ import {HttpClient, RestResponse} from './backend'; export class AngularHttpClientImpl implements HttpClient { - constructor(private http: AngularHttpClient, private baseUrl: string | undefined = undefined) { + constructor(private readonly http: AngularHttpClient, private readonly baseUrl: string | undefined = undefined) { } request(requestConfig: { diff --git a/frontend/src/app/services/mgmt/api/api.service.ts b/frontend/src/app/services/mgmt/api/api.service.ts index 80c1682..ea680e7 100644 --- a/frontend/src/app/services/mgmt/api/api.service.ts +++ b/frontend/src/app/services/mgmt/api/api.service.ts @@ -9,9 +9,9 @@ import {AngularHttpClientImpl} from "./angular-http-client"; }) export class ApiService extends RestApplicationClient { - private baseUrl: string = environment.api_url; + private readonly baseUrl: string = environment.api_url; - constructor(private http: HttpClient) { + constructor(private readonly http: HttpClient) { super(new AngularHttpClientImpl(http, environment.api_url)); } diff --git a/frontend/src/app/services/mgmt/auth/auth.service.ts b/frontend/src/app/services/mgmt/auth/auth.service.ts index 1092ccf..e14dbba 100644 --- a/frontend/src/app/services/mgmt/auth/auth.service.ts +++ b/frontend/src/app/services/mgmt/auth/auth.service.ts @@ -1,6 +1,6 @@ -import { Injectable } from '@angular/core'; +import {Injectable} from '@angular/core'; -const TOKEN_NAME : string = 'authToken'; +const TOKEN_NAME: string = 'authToken'; @Injectable({ providedIn: 'root' @@ -11,7 +11,7 @@ export class AuthService { private isAuthenticated = !!sessionStorage.getItem(TOKEN_NAME); login(username: string, password: string): void { - var authToken = btoa(username + ':' + password); + const authToken = btoa(username + ':' + password); sessionStorage.setItem(TOKEN_NAME, authToken); this.isAuthenticated = true; } diff --git a/frontend/src/app/views/administration/registration-request/registration-request.component.ts b/frontend/src/app/views/administration/registration-request/registration-request.component.ts index 264cae6..4bf5d40 100644 --- a/frontend/src/app/views/administration/registration-request/registration-request.component.ts +++ b/frontend/src/app/views/administration/registration-request/registration-request.component.ts @@ -23,7 +23,7 @@ export class RegistrationRequestComponent implements OnInit, OnChanges { isClickableDelete: boolean = true; - constructor(private apiService: ApiService) { + constructor(private readonly apiService: ApiService) { } ngOnInit() { @@ -37,10 +37,6 @@ export class RegistrationRequestComponent implements OnInit, OnChanges { computeButtonStates() { switch (this.request.status) { case IRequestStatus.NEW: - this.isClickableAccept = true; - this.isClickableReject = true; - this.isClickableDelete = true; - break; case IRequestStatus.ACCEPTED: this.isClickableAccept = true; this.isClickableReject = true; diff --git a/frontend/src/app/views/impressum/impressum.component.scss b/frontend/src/app/views/impressum/impressum.component.scss index 770d370..8675497 100644 --- a/frontend/src/app/views/impressum/impressum.component.scss +++ b/frontend/src/app/views/impressum/impressum.component.scss @@ -3,7 +3,6 @@ justify-content: start; align-items: start; height: auto; - //background-color: white; text-align: left; } diff --git a/frontend/src/app/views/login/login.component.ts b/frontend/src/app/views/login/login.component.ts index 4d1d414..3fafc38 100644 --- a/frontend/src/app/views/login/login.component.ts +++ b/frontend/src/app/views/login/login.component.ts @@ -11,10 +11,10 @@ export class LoginComponent { username: string = ''; password: string = ''; - constructor(private router: Router, private auth: AuthService) {} + constructor(private readonly router: Router, private readonly auth: AuthService) { + } login(username: string, password: string) { - var authToken = btoa(username + ':' + password); this.auth.login(username, password); this.username = ''; this.password = ''; diff --git a/frontend/src/app/wizard-extension/base-wizard-extension/base-wizard-extension.component.ts b/frontend/src/app/wizard-extension/base-wizard-extension/base-wizard-extension.component.ts index 0331e0b..ceec17e 100644 --- a/frontend/src/app/wizard-extension/base-wizard-extension/base-wizard-extension.component.ts +++ b/frontend/src/app/wizard-extension/base-wizard-extension/base-wizard-extension.component.ts @@ -38,12 +38,12 @@ export class BaseWizardExtensionComponent { protected shaclFile: ShaclFile; protected filteredShapes: Shape[]; protected wizardVisible: boolean = false; - @ViewChild("wizard") private wizard: DynamicFormComponent; - private shapeInitialized: BehaviorSubject = new BehaviorSubject(false); - private wizardMutex: Mutex = new Mutex(); + @ViewChild("wizard") private readonly wizard: DynamicFormComponent; + private readonly shapeInitialized: BehaviorSubject = new BehaviorSubject(false); + private readonly wizardMutex: Mutex = new Mutex(); private disabledFields: string[] = []; - private createDateTimer: NodeJS.Timeout = undefined; + private readonly createDateTimer: NodeJS.Timeout = undefined; constructor(protected formFieldService: FormfieldControlService, protected exportService: ExportService, diff --git a/frontend/src/app/wizard-extension/participant-wizard-extension/participant-wizard-extension.component.ts b/frontend/src/app/wizard-extension/participant-wizard-extension/participant-wizard-extension.component.ts index c78552a..ae93caa 100644 --- a/frontend/src/app/wizard-extension/participant-wizard-extension/participant-wizard-extension.component.ts +++ b/frontend/src/app/wizard-extension/participant-wizard-extension/participant-wizard-extension.component.ts @@ -22,12 +22,12 @@ import {commonMessages} from "../../../environments/common-messages"; export class ParticipantWizardExtensionComponent { @ViewChild("participantRegistrationStatusMessage") public participantRegistrationStatusMessage!: StatusMessageComponent; public prefillDone: BehaviorSubject = new BehaviorSubject(false); - @ViewChild("pxParticipantExtensionWizard") private pxParticipantExtensionWizard: BaseWizardExtensionComponent; - @ViewChild("gxParticipantWizard") private gxParticipantWizard: BaseWizardExtensionComponent; - @ViewChild("gxRegistrationNumberWizard") private gxRegistrationNumberWizard: BaseWizardExtensionComponent; + @ViewChild("pxParticipantExtensionWizard") private readonly pxParticipantExtensionWizard: BaseWizardExtensionComponent; + @ViewChild("gxParticipantWizard") private readonly gxParticipantWizard: BaseWizardExtensionComponent; + @ViewChild("gxRegistrationNumberWizard") private readonly gxRegistrationNumberWizard: BaseWizardExtensionComponent; constructor( - private apiService: ApiService + private readonly apiService: ApiService ) { }