Skip to content

Commit

Permalink
PI-872: adjust to code suggestions from sonarlint (#60)
Browse files Browse the repository at this point in the history
* clean up java classes

* cleanup frontend issues
  • Loading branch information
M-Busk authored Feb 13, 2025
1 parent d59c2da commit c26b12d
Show file tree
Hide file tree
Showing 26 changed files with 161 additions and 174 deletions.
14 changes: 10 additions & 4 deletions backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
};
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ResponseEntity<Object> handleMethodArgumentNotValid(@NonNull MethodArgume
logError(ex);

Map<String, String> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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());
Expand Down
Loading

0 comments on commit c26b12d

Please sign in to comment.