Skip to content

Commit

Permalink
Merge pull request #509 from it-at-m/169-implementierung-monitoring-w…
Browse files Browse the repository at this point in the history
…ahlbeteiligung

169 implementierung monitoring wahlbeteiligung
  • Loading branch information
dragonfly28 authored Nov 4, 2024
2 parents fc6c281 + b6ce4f3 commit f0b316f
Show file tree
Hide file tree
Showing 51 changed files with 1,605 additions and 421 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
id: add authorities monitoring waehleranzahl
author: dragonfly28
realm: ${SSO_REALM}
changes:
- addRole:
name: Monitoring_BUSINESSACTION_GetWahlbeteiligung
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allMonitoringAuthorities
role: Monitoring_BUSINESSACTION_GetWahlbeteiligung
clientId: ${SSO_CLIENT_ID}

- addRole:
name: Monitoring_BUSINESSACTION_PostWahlbeteiligung
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allMonitoringAuthorities
role: Monitoring_BUSINESSACTION_PostWahlbeteiligung
clientId: ${SSO_CLIENT_ID}

- addRole:
name: Monitoring_READ_Waehleranzahl
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allMonitoringAuthorities
role: Monitoring_READ_Waehleranzahl
clientId: ${SSO_CLIENT_ID}
- addRole:
name: Monitoring_WRITE_Waehleranzahl
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allMonitoringAuthorities
role: Monitoring_WRITE_Waehleranzahl
clientId: ${SSO_CLIENT_ID}
- addRole:
name: Monitoring_DELETE_Waehleranzahl
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allMonitoringAuthorities
role: Monitoring_DELETE_Waehleranzahl
clientId: ${SSO_CLIENT_ID}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
id: create group allMonitoringAuthorities and link wls_all*
author: dragonfly28
realm: ${SSO_REALM}
changes:
- addGroup:
name: allMonitoringAuthorities
- assignGroup:
user: wls_all
group: allMonitoringAuthorities
- assignGroup:
user: wls_all_uwb
group: allMonitoringAuthorities
- assignGroup:
user: wls_all_bwb
group: allMonitoringAuthorities
2 changes: 2 additions & 0 deletions stack/keycloak/migration/keycloak-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ includes:
- path: add-authorities-vorfaelleundvorkommnisse.yml
- path: add-authorities-eai-ergebnismeldung.yml
- path: add-authorities-basisdaten-wahltermindaten.yml
- path: create-group-all-monitoring-authorities.yml
- path: add-authorities-monitoring-waehleranzahl.yml
95 changes: 90 additions & 5 deletions wls-monitoring-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
<!-- Version muss mit der in den spring-boot-dependencies bereitgestellten Lombok-Version übereinstimmen -->
<org.projectlombok.lombok.version>1.18.30</org.projectlombok.lombok.version>
<org.projectlombok.mapstructbinding.version>0.2.0</org.projectlombok.mapstructbinding.version>
<org.mapstruct.version>1.6.2</org.mapstruct.version>
<org.springdoc.version>2.6.0</org.springdoc.version>
<wls.common.version>1.1.0</wls.common.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -77,6 +79,13 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- wls-common -->
<dependency>
<groupId>de.muenchen.oss.wahllokalsystem.wls-common</groupId>
<artifactId>exception</artifactId>
<version>1.1.0</version>
</dependency>

<!-- Caching -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -165,6 +174,18 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${org.springdoc.version}</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.6</version>
</dependency>

<!-- wls-common -->
<dependency>
<groupId>de.muenchen.oss.wahllokalsystem.wls-common</groupId>
<artifactId>security</artifactId>
<version>${wls.common.version}</version>
</dependency>

<!-- Validation -->
<dependency>
Expand All @@ -187,6 +208,11 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -197,6 +223,12 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.muenchen.oss.wahllokalsystem.wls-common</groupId>
<artifactId>testing</artifactId>
<version>${wls.common.version}</version>
<scope>test</scope>
</dependency>

<!-- Logging -->
<dependency>
Expand Down Expand Up @@ -328,14 +360,67 @@
<artifactId>lombok</artifactId>
<version>${org.projectlombok.lombok.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>${org.projectlombok.mapstructbinding.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>
-Amapstruct.defaultComponentModel=spring
</compilerArg>
<compilerArg>
-Amapstruct.unmappedTargetPolicy=ERROR
</compilerArg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.7.0</version>
<executions>
<execution>
<id>generateEAI</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapis/openapi.eai.0.1.0.json</inputSpec>

<generatorName>java</generatorName>
<library>resttemplate</library>

<apiPackage>${project.groupId}.monitoringservice.eai.aou.client</apiPackage>
<modelPackage>${project.groupId}.monitoringservice.eai.aou.model</modelPackage>

<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelDocumentation>false</generateModelDocumentation>

<configOptions>
<hideGenerationTimestamp>false</hideGenerationTimestamp>
<legacyDiscriminatorBehavior>false</legacyDiscriminatorBehavior>
<generateClientAsBean>true</generateClientAsBean>
<useJakartaEe>true</useJakartaEe>
</configOptions>

<globalProperties>
<supportingFiles>
BaseApi.java,ApiClient.java,JavaTimeFormatter.java,Authentication.java,OAuth.java,ApiKeyAuth.java,HttpBasicAuth.java,HttpBearerAuth.java,RFC3339DateFormat.java
</supportingFiles>
</globalProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-scm-plugin</artifactId>
<version>${maven-scm-plugin.version}</version>
Expand All @@ -348,7 +433,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>${surefireArgLine} -Dfile.encoding=${project.build.sourceEncoding}</argLine>
<argLine>${surefireArgLine} -Dfile.encoding=${project.build.sourceEncoding}</argLine>
</configuration>
</plugin>

Expand All @@ -368,10 +453,10 @@
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${sonar.jacoco.reportPath}</destFile>
<!-- Sets the VM argument line used when unit tests are run. -->
<propertyName>surefireArgLine</propertyName>
<append>true</append>
<destFile>${sonar.jacoco.reportPath}</destFile>
<!-- Sets the VM argument line used when unit tests are run. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
@ComponentScan(
basePackages = {
"org.springframework.data.jpa.convert.threeten",
"de.muenchen.oss.wahllokalsystem.monitoringservice"
"de.muenchen.oss.wahllokalsystem.monitoringservice",
"de.muenchen.oss.wahllokalsystem.wls.common.exception",
}
)
@EntityScan(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.muenchen.oss.wahllokalsystem.monitoringservice.client.waehleranzahl;

import de.muenchen.oss.wahllokalsystem.monitoringservice.configuration.Profiles;
import de.muenchen.oss.wahllokalsystem.monitoringservice.service.waehleranzahl.WaehleranzahlClient;
import de.muenchen.oss.wahllokalsystem.monitoringservice.service.waehleranzahl.WaehleranzahlModel;
import de.muenchen.oss.wahllokalsystem.wls.common.exception.WlsException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Profile(Profiles.DUMMY_CLIENTS)
@RequiredArgsConstructor
@Slf4j
public class DummyClientImpl implements WaehleranzahlClient {

@Override
public void postWahlbeteiligung(WaehleranzahlModel waehleranzahlModel) throws WlsException {
log.info("Dummy client postWahlbeteiligung() called instead of EAI with: {}", waehleranzahlModel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.muenchen.oss.wahllokalsystem.monitoringservice.client.waehleranzahl;

import de.muenchen.oss.wahllokalsystem.monitoringservice.configuration.Profiles;
import de.muenchen.oss.wahllokalsystem.monitoringservice.eai.aou.client.WahlbeteiligungControllerApi;
import de.muenchen.oss.wahllokalsystem.monitoringservice.service.waehleranzahl.WaehleranzahlClient;
import de.muenchen.oss.wahllokalsystem.monitoringservice.service.waehleranzahl.WaehleranzahlModel;
import de.muenchen.oss.wahllokalsystem.wls.common.exception.WlsException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Profile(Profiles.NOT + Profiles.DUMMY_CLIENTS)
@RequiredArgsConstructor
@Slf4j
public class WaehleranzahlClientImpl implements WaehleranzahlClient {

private final WahlbeteiligungControllerApi wahlbeteiligungControllerApi;
private final WaehleranzahlClientMapper waehleranzahlClientMapper;

@Override
public void postWahlbeteiligung(final WaehleranzahlModel waehleranzahlModel) throws WlsException {
val wahlbeteiligungsMeldungDTO = waehleranzahlClientMapper.fromModelToRemoteClientDTO(waehleranzahlModel);
try {
wahlbeteiligungControllerApi.saveWahlbeteiligung(wahlbeteiligungsMeldungDTO);
} catch (final Exception exception) {
log.error("Wahllokalzustand nicht gesendet. Exception: ", exception);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.muenchen.oss.wahllokalsystem.monitoringservice.client.waehleranzahl;

import de.muenchen.oss.wahllokalsystem.monitoringservice.eai.aou.model.WahlbeteiligungsMeldungDTO;
import de.muenchen.oss.wahllokalsystem.monitoringservice.service.waehleranzahl.WaehleranzahlModel;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import lombok.val;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper
public interface WaehleranzahlClientMapper {

ZoneId DEFAULT_ZONE_ID = ZoneId.systemDefault();

@Mapping(target = "wahlID", ignore = true)
@Mapping(target = "wahlbezirkID", source = "bezirkUndWahlID.wahlbezirkID")
@Mapping(target = "meldeZeitpunkt", source = "uhrzeit")
WahlbeteiligungsMeldungDTO fromModelToRemoteClientDTO(WaehleranzahlModel waehleranzahlModel);

default OffsetDateTime localDateTimeToOffsetDateTime(LocalDateTime localDateTime) {
return localDateTimeToOffsetDateTime(localDateTime, DEFAULT_ZONE_ID);
}

default OffsetDateTime localDateTimeToOffsetDateTime(LocalDateTime localDateTime, ZoneId zoneId) {
val zoneOffset = zoneId.getRules().getOffset(localDateTime);
return localDateTime.atOffset(zoneOffset);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.muenchen.oss.wahllokalsystem.monitoringservice.configuration;

import de.muenchen.oss.wahllokalsystem.monitoringservice.eai.aou.ApiClient;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class BasePathConfiguration {

@Value("${app.clients.eai.basePath}")
String eaiBasePath;

private final ApiClient eaiApiClient;

@PostConstruct
public void updateBasePaths() {
eaiApiClient.setBasePath(eaiBasePath);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package de.muenchen.oss.wahllokalsystem.monitoringservice.configuration;

import com.fasterxml.jackson.databind.ObjectMapper;
import de.muenchen.oss.wahllokalsystem.wls.common.exception.errorhandler.WlsResponseErrorHandler;
import lombok.val;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
import org.springframework.web.client.RestTemplate;

@Configuration
public class ClientConfiguration {

@Bean
public WlsResponseErrorHandler wlsResponseErrorHandler(final ObjectMapper objectMapper) {
return new WlsResponseErrorHandler(objectMapper);
}

@Bean
public RestTemplate restTemplate(final WlsResponseErrorHandler wlsResponseErrorHandler) {
val restTemplate = new RestTemplate();

restTemplate.setErrorHandler(wlsResponseErrorHandler);
restTemplate.getInterceptors().add((request, body, execution) -> {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
return execution.execute(request, body);
}

if (!(authentication.getCredentials() instanceof AbstractOAuth2Token token)) {
return execution.execute(request, body);
}

request.getHeaders().setBearerAuth(token.getTokenValue());
return execution.execute(request, body);
});

return restTemplate;
}
}
Loading

0 comments on commit f0b316f

Please sign in to comment.