Skip to content

Commit c26b12d

Browse files
authored
PI-872: adjust to code suggestions from sonarlint (#60)
* clean up java classes * cleanup frontend issues
1 parent d59c2da commit c26b12d

File tree

26 files changed

+161
-174
lines changed

26 files changed

+161
-174
lines changed

backend/build.gradle.kts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,24 @@ dependencies {
4343
implementation(libs.titaniumJsonLd)
4444
implementation(libs.jakartaJson)
4545
implementation(libs.postgresql)
46-
compileOnly(libs.lombok)
47-
annotationProcessor(libs.lombokMapStructBinding)
4846
implementation(libs.mapStruct)
47+
48+
annotationProcessor(libs.lombokMapStructBinding)
4949
annotationProcessor(libs.mapStructProcessor)
50-
developmentOnly(libs.springBootDevtools)
51-
runtimeOnly(libs.therApi)
5250
annotationProcessor(libs.lombok)
5351
annotationProcessor(libs.therApiScribe)
52+
53+
developmentOnly(libs.springBootDevtools)
54+
55+
runtimeOnly(libs.therApi)
56+
57+
compileOnly(libs.lombok)
58+
5459
testImplementation(libs.springBootStarterTest)
5560
testImplementation(libs.reactorTest)
5661
testImplementation(libs.h2)
5762
testImplementation(libs.springSecurityTest)
63+
5864
testRuntimeOnly(libs.jUnit)
5965
}
6066

backend/src/main/java/eu/possiblex/portal/application/configuration/AppConfigurer.java

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
import io.netty.handler.ssl.SslContext;
88
import io.netty.handler.ssl.SslContextBuilder;
99
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
10-
11-
import jakarta.servlet.FilterChain;
12-
import jakarta.servlet.ServletException;
1310
import jakarta.servlet.http.HttpServletRequest;
1411
import jakarta.servlet.http.HttpServletResponse;
1512
import org.springframework.beans.factory.annotation.Value;
@@ -27,16 +24,14 @@
2724
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
2825
import org.springframework.security.crypto.password.PasswordEncoder;
2926
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
27+
import org.springframework.security.web.AuthenticationEntryPoint;
3028
import org.springframework.security.web.SecurityFilterChain;
31-
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
32-
import org.springframework.web.filter.OncePerRequestFilter;
3329
import org.springframework.web.reactive.function.client.ExchangeStrategies;
3430
import org.springframework.web.reactive.function.client.WebClient;
3531
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
3632
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
3733
import org.springframework.web.servlet.config.annotation.CorsRegistry;
3834
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
39-
import org.springframework.security.web.AuthenticationEntryPoint;
4035
import reactor.netty.http.client.HttpClient;
4136

4237
import javax.net.ssl.SSLException;
@@ -126,46 +121,41 @@ public TechnicalFhCatalogClient fhCatalogClient() {
126121
}
127122

128123
@Bean
129-
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
130-
http.authorizeHttpRequests((authorizeHttpRequests) ->
131-
authorizeHttpRequests
132-
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
133-
.requestMatchers(HttpMethod.POST, "/registration/request").permitAll()
134-
.requestMatchers("/registration/**").authenticated()
135-
.anyRequest().permitAll()
136-
)
124+
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
125+
126+
http.authorizeHttpRequests(
127+
authorizeHttpRequests -> authorizeHttpRequests.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
128+
.requestMatchers(HttpMethod.POST, "/registration/request").permitAll()
129+
.requestMatchers("/registration/**").authenticated().anyRequest().permitAll())
137130
.httpBasic(basic -> basic.authenticationEntryPoint(new CustomAuthenticationEntryPoint()))
138-
.csrf(AbstractHttpConfigurer::disable)
139-
.cors(Customizer.withDefaults());
131+
.csrf(AbstractHttpConfigurer::disable).cors(Customizer.withDefaults());
140132
return http.build();
141-
}
133+
}
142134

143135
@Bean
144-
public UserDetailsService userDetailsService() {
145-
UserDetails admin =
146-
User.builder()
147-
.username(adminUsername)
148-
.password(passwordEncoder().encode(adminPassword))
149-
.roles("ADMIN")
150-
.build();
136+
public UserDetailsService userDetailsService() {
151137

152-
return new InMemoryUserDetailsManager(admin);
153-
}
138+
UserDetails admin = User.builder().username(adminUsername).password(passwordEncoder().encode(adminPassword))
139+
.roles("ADMIN").build();
140+
141+
return new InMemoryUserDetailsManager(admin);
142+
}
154143

155144
@Bean
156145
public PasswordEncoder passwordEncoder() {
146+
157147
return new BCryptPasswordEncoder();
158148
}
159149

160150
@Bean
161151
public WebMvcConfigurer corsConfigurer() {
152+
162153
return new WebMvcConfigurer() {
163154
@Override
164155
public void addCorsMappings(CorsRegistry registry) {
165-
registry.addMapping("/**")
166-
.allowedOriginPatterns("*")
167-
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
168-
.allowedHeaders("*")
156+
157+
registry.addMapping("/**").allowedOriginPatterns("*")
158+
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS").allowedHeaders("*")
169159
.allowCredentials(true);
170160
}
171161
};
@@ -174,7 +164,9 @@ public void addCorsMappings(CorsRegistry registry) {
174164
private class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {
175165

176166
@Override
177-
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
167+
public void commence(HttpServletRequest request, HttpServletResponse response,
168+
AuthenticationException authException) throws IOException {
169+
178170
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
179171
response.setHeader("WWW-Authenticate", "");
180172
response.getWriter().write("Unauthorized");

backend/src/main/java/eu/possiblex/portal/application/configuration/BoundaryExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public ResponseEntity<Object> handleMethodArgumentNotValid(@NonNull MethodArgume
7373
logError(ex);
7474

7575
Map<String, String> errors = new HashMap<>();
76-
ex.getBindingResult().getAllErrors().forEach((error) -> {
76+
ex.getBindingResult().getAllErrors().forEach(error -> {
7777
String fieldName = ((FieldError) error).getField();
7878
String errorMessage = error.getDefaultMessage();
7979
errors.put(fieldName, errorMessage);

backend/src/main/java/eu/possiblex/portal/application/control/ParticipantRegistrationRestApiMapper.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package eu.possiblex.portal.application.control;
22

33
import eu.possiblex.portal.application.entity.CreateRegistrationRequestTO;
4-
import eu.possiblex.portal.application.entity.credentials.gx.participants.GxLegalRegistrationNumberCredentialSubject;
5-
import eu.possiblex.portal.business.entity.credentials.px.GxNestedLegalRegistrationNumberCredentialSubject;
64
import eu.possiblex.portal.business.entity.credentials.px.PxExtendedLegalParticipantCredentialSubject;
75
import org.mapstruct.Mapper;
86
import org.mapstruct.Mapping;

backend/src/main/java/eu/possiblex/portal/application/entity/credentials/px/participants/PxParticipantExtensionCredentialSubject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class PxParticipantExtensionCredentialSubject extends PojoCredentialSubje
3939
@JsonProperty("px:mailAddress")
4040
@JsonSerialize(using = StringSerializer.class)
4141
@JsonDeserialize(using = StringDeserializer.class)
42-
@Pattern(regexp = "^((?!\\.)[\\w\\-_.]*[^.])(@\\w+)(\\.\\w+(\\.\\w+)?[^.\\W])$", message = "Mail address must be a valid email address")
42+
@Pattern(regexp = "^((?!\\.)[\\w\\-.]*[^.])(@[\\w-]+)(\\.\\w+(\\.\\w+)?\\w)$", message = "Mail address must be a valid email address")
4343
private String mailAddress;
4444

4545
@JsonProperty("type")

backend/src/main/java/eu/possiblex/portal/business/control/ParticipantRegistrationServiceMapper.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
package eu.possiblex.portal.business.control;
22

3-
import eu.possiblex.portal.application.entity.AddressTO;
4-
import eu.possiblex.portal.application.entity.ParticipantDidDataTO;
5-
import eu.possiblex.portal.application.entity.RegistrationNumberTO;
63
import eu.possiblex.portal.application.entity.RegistrationRequestEntryTO;
7-
import eu.possiblex.portal.application.entity.credentials.gx.datatypes.GxVcard;
8-
import eu.possiblex.portal.application.entity.credentials.gx.participants.GxLegalRegistrationNumberCredentialSubject;
94
import eu.possiblex.portal.business.entity.ParticipantRegistrationRequestBE;
105
import eu.possiblex.portal.business.entity.credentials.px.PxExtendedLegalParticipantCredentialSubject;
11-
import eu.possiblex.portal.business.entity.did.ParticipantDidBE;
126
import org.mapstruct.Mapper;
137
import org.mapstruct.Mapping;
148

backend/src/main/java/eu/possiblex/portal/utilities/LogUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
@Slf4j
77
/*
88
* Some util functions for logging.
9-
*/
10-
public class LogUtils {
9+
*/ public class LogUtils {
10+
11+
private LogUtils() {
12+
// private constructor to prevent instantiation
13+
}
1114

1215
/**
1316
* Serialize an object to JSON.

backend/src/test/java/eu/possiblex/portal/PortalApplicationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import org.springframework.test.context.TestPropertySource;
66

77
@SpringBootTest
8-
@TestPropertySource(properties = {"version.no = thisistheversion", "version.date = 21.03.2022"})
8+
@TestPropertySource(properties = { "version.no = thisistheversion", "version.date = 21.03.2022" })
99
class PortalApplicationTests {
1010

1111
@Test
1212
void contextLoads() {
13-
13+
// basic context loading test
1414
}
1515

1616
}

backend/src/test/java/eu/possiblex/portal/application/boundary/CommonPortalModuleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@TestPropertySource(properties = { "version.no = thisistheversion", "version.date = 21.03.2022",
2121
"fh.catalog.ui-url = http://localhost:8080" })
2222
@Import(CommonPortalRestApiImpl.class)
23-
public class CommonPortalModuleTest {
23+
class CommonPortalModuleTest {
2424

2525
@Autowired
2626
private MockMvc mockMvc;

backend/src/test/java/eu/possiblex/portal/persistence/dao/ParticipantRegistrationEntityMapperTest.java

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package eu.possiblex.portal.persistence.dao;
22

33
import eu.possiblex.portal.application.entity.credentials.gx.datatypes.GxVcard;
4+
import eu.possiblex.portal.application.entity.credentials.gx.participants.GxLegalRegistrationNumberCredentialSubject;
45
import eu.possiblex.portal.business.entity.ParticipantRegistrationRequestBE;
56
import eu.possiblex.portal.business.entity.credentials.px.GxNestedLegalRegistrationNumberCredentialSubject;
67
import eu.possiblex.portal.business.entity.credentials.px.PxExtendedLegalParticipantCredentialSubject;
@@ -28,6 +29,50 @@ class ParticipantRegistrationEntityMapperTest {
2829
@Autowired
2930
private ParticipantRegistrationEntityMapper participantRegistrationServiceMapper;
3031

32+
private static void assertAddressIsEqual(GxVcard expected, VcardEntity actual) {
33+
34+
assertEquals(expected.getCountryCode(), actual.getCountryCode());
35+
assertEquals(expected.getCountrySubdivisionCode(), actual.getCountrySubdivisionCode());
36+
assertEquals(expected.getStreetAddress(), actual.getStreetAddress());
37+
assertEquals(expected.getLocality(), actual.getLocality());
38+
assertEquals(expected.getPostalCode(), actual.getPostalCode());
39+
}
40+
41+
private static void assertAddressIsEqual(VcardEntity expected, GxVcard actual) {
42+
43+
assertEquals(expected.getCountryCode(), actual.getCountryCode());
44+
assertEquals(expected.getCountrySubdivisionCode(), actual.getCountrySubdivisionCode());
45+
assertEquals(expected.getStreetAddress(), actual.getStreetAddress());
46+
assertEquals(expected.getLocality(), actual.getLocality());
47+
assertEquals(expected.getPostalCode(), actual.getPostalCode());
48+
}
49+
50+
private static void assertRegistrationNumberIsEqual(GxNestedLegalRegistrationNumberCredentialSubject expected,
51+
RegistrationNumberEntity actual) {
52+
53+
assertEquals(expected.getEori(), actual.getEori());
54+
assertEquals(expected.getVatID(), actual.getVatID());
55+
assertEquals(expected.getLeiCode(), actual.getLeiCode());
56+
}
57+
58+
private static void assertRegistrationNumberIsEqual(RegistrationNumberEntity expected,
59+
GxLegalRegistrationNumberCredentialSubject actual) {
60+
61+
assertEquals(expected.getEori(), actual.getEori());
62+
assertEquals(expected.getVatID(), actual.getVatID());
63+
assertEquals(expected.getLeiCode(), actual.getLeiCode());
64+
}
65+
66+
private static void assertConnectorCertificateIsEqual(OmejdnConnectorCertificateEntity expected,
67+
OmejdnConnectorCertificateBE actual) {
68+
69+
assertEquals(expected.getClientId(), actual.getClientId());
70+
assertEquals(expected.getClientName(), actual.getClientName());
71+
assertEquals(expected.getScope(), actual.getScope());
72+
assertEquals(expected.getKeystore(), actual.getKeystore());
73+
assertEquals(expected.getPassword(), actual.getPassword());
74+
}
75+
3176
@Test
3277
void mapParticipantCredentialSubjectToEntity() {
3378
// given
@@ -52,23 +97,10 @@ void mapParticipantCredentialSubjectToEntity() {
5297
assertEquals(cs.getDescription(), entity.getDescription());
5398
assertEquals(cs.getMailAddress(), entity.getEmailAddress());
5499

55-
assertEquals(cs.getLegalAddress().getCountryCode(), entity.getLegalAddress().getCountryCode());
56-
assertEquals(cs.getLegalAddress().getCountrySubdivisionCode(),
57-
entity.getLegalAddress().getCountrySubdivisionCode());
58-
assertEquals(cs.getLegalAddress().getStreetAddress(), entity.getLegalAddress().getStreetAddress());
59-
assertEquals(cs.getLegalAddress().getLocality(), entity.getLegalAddress().getLocality());
60-
assertEquals(cs.getLegalAddress().getPostalCode(), entity.getLegalAddress().getPostalCode());
61-
62-
assertEquals(cs.getHeadquarterAddress().getCountryCode(), entity.getHeadquarterAddress().getCountryCode());
63-
assertEquals(cs.getHeadquarterAddress().getCountrySubdivisionCode(),
64-
entity.getHeadquarterAddress().getCountrySubdivisionCode());
65-
assertEquals(cs.getHeadquarterAddress().getStreetAddress(), entity.getHeadquarterAddress().getStreetAddress());
66-
assertEquals(cs.getHeadquarterAddress().getLocality(), entity.getHeadquarterAddress().getLocality());
67-
assertEquals(cs.getHeadquarterAddress().getPostalCode(), entity.getHeadquarterAddress().getPostalCode());
68-
69-
assertEquals(cs.getLegalRegistrationNumber().getEori(), entity.getLegalRegistrationNumber().getEori());
70-
assertEquals(cs.getLegalRegistrationNumber().getVatID(), entity.getLegalRegistrationNumber().getVatID());
71-
assertEquals(cs.getLegalRegistrationNumber().getLeiCode(), entity.getLegalRegistrationNumber().getLeiCode());
100+
assertAddressIsEqual(cs.getLegalAddress(), entity.getLegalAddress());
101+
assertAddressIsEqual(cs.getHeadquarterAddress(), entity.getHeadquarterAddress());
102+
103+
assertRegistrationNumberIsEqual(cs.getLegalRegistrationNumber(), entity.getLegalRegistrationNumber());
72104
}
73105

74106
@Test
@@ -89,33 +121,11 @@ void mapParticipantEntityToParticipantRegistrationRequestBe() {
89121
assertEquals(entity.getStatus().name(), be.getStatus().name());
90122
assertEquals(entity.getVpLink(), be.getVpLink());
91123

92-
assertEquals(entity.getLegalRegistrationNumber().getEori(), be.getLegalRegistrationNumber().getEori());
93-
assertEquals(entity.getLegalRegistrationNumber().getVatID(), be.getLegalRegistrationNumber().getVatID());
94-
assertEquals(entity.getLegalRegistrationNumber().getLeiCode(), be.getLegalRegistrationNumber().getLeiCode());
95-
96-
assertEquals(entity.getLegalAddress().getCountryCode(), be.getLegalAddress().getCountryCode());
97-
assertEquals(entity.getLegalAddress().getCountrySubdivisionCode(),
98-
be.getLegalAddress().getCountrySubdivisionCode());
99-
assertEquals(entity.getLegalAddress().getStreetAddress(), be.getLegalAddress().getStreetAddress());
100-
assertEquals(entity.getLegalAddress().getLocality(), be.getLegalAddress().getLocality());
101-
assertEquals(entity.getLegalAddress().getPostalCode(), be.getLegalAddress().getPostalCode());
102-
103-
assertEquals(entity.getHeadquarterAddress().getCountryCode(), be.getHeadquarterAddress().getCountryCode());
104-
assertEquals(entity.getHeadquarterAddress().getCountrySubdivisionCode(),
105-
be.getHeadquarterAddress().getCountrySubdivisionCode());
106-
assertEquals(entity.getHeadquarterAddress().getStreetAddress(), be.getHeadquarterAddress().getStreetAddress());
107-
assertEquals(entity.getHeadquarterAddress().getLocality(), be.getHeadquarterAddress().getLocality());
108-
assertEquals(entity.getHeadquarterAddress().getPostalCode(), be.getHeadquarterAddress().getPostalCode());
109-
110-
assertEquals(entity.getOmejdnConnectorCertificate().getClientId(),
111-
be.getOmejdnConnectorCertificate().getClientId());
112-
assertEquals(entity.getOmejdnConnectorCertificate().getClientName(),
113-
be.getOmejdnConnectorCertificate().getClientName());
114-
assertEquals(entity.getOmejdnConnectorCertificate().getKeystore(),
115-
be.getOmejdnConnectorCertificate().getKeystore());
116-
assertEquals(entity.getOmejdnConnectorCertificate().getPassword(),
117-
be.getOmejdnConnectorCertificate().getPassword());
118-
assertEquals(entity.getOmejdnConnectorCertificate().getScope(), be.getOmejdnConnectorCertificate().getScope());
124+
assertRegistrationNumberIsEqual(entity.getLegalRegistrationNumber(), be.getLegalRegistrationNumber());
125+
assertAddressIsEqual(entity.getLegalAddress(), be.getLegalAddress());
126+
assertAddressIsEqual(entity.getHeadquarterAddress(), be.getHeadquarterAddress());
127+
128+
assertConnectorCertificateIsEqual(entity.getOmejdnConnectorCertificate(), be.getOmejdnConnectorCertificate());
119129

120130
assertEquals(entity.getDidData().getDid(), be.getDidData().getDid());
121131
assertEquals(entity.getDidData().getVerificationMethod(), be.getDidData().getVerificationMethod());

0 commit comments

Comments
 (0)