Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

191 lesen und schreiben der stimmzettelumschläge #663

Merged
merged 25 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a0cbdd8
stimmzettelumschlaege implementiert
dragonfly28 Dec 18, 2024
86fc6e3
authorities and keycloak migration added
dragonfly28 Dec 18, 2024
874dbc5
service tests added
dragonfly28 Dec 19, 2024
cfb03ad
controller tests added
dragonfly28 Dec 19, 2024
c0c7a1a
Doku aktualisiert
dragonfly28 Dec 19, 2024
7d968bc
Update wls-ergebnismeldung-service/src/test/java/de/muenchen/oss/wahl…
dragonfly28 Dec 19, 2024
755b851
mvn spotless:apply
dragonfly28 Dec 19, 2024
56d83b5
Merge remote-tracking branch 'origin/191-lesen-und-schreiben-der-stim…
dragonfly28 Dec 19, 2024
c88c2f2
Wiremock not needed
dragonfly28 Dec 20, 2024
2d1569a
use LocalDateTimeComparators instead of truncating test data
dragonfly28 Dec 20, 2024
77aed0a
check for wahlbezirkArt from Authentication added
dragonfly28 Dec 20, 2024
b8fc3ec
Merge branch 'dev' into 191-lesen-und-schreiben-der-stimmzettelumschläge
dragonfly28 Dec 20, 2024
8b0b2cd
renamed after merging with dev
dragonfly28 Dec 20, 2024
75b67a5
tests mit security erforderlich wegen der Wahlbezirkart-Bestimmung üb…
dragonfly28 Jan 7, 2025
c4f2cf4
mvn spotless:apply
dragonfly28 Jan 7, 2025
218fea5
mvn spotless:apply
dragonfly28 Jan 7, 2025
30acd6a
Merge branch 'dev' into 191-lesen-und-schreiben-der-stimmzettelumschläge
dragonfly28 Jan 8, 2025
fafd046
Reihenfolge geändert
dragonfly28 Jan 8, 2025
7160980
Merge remote-tracking branch 'origin/191-lesen-und-schreiben-der-stim…
dragonfly28 Jan 8, 2025
9e84777
- Method renamed
dragonfly28 Jan 8, 2025
5066f02
Update wls-ergebnismeldung-service/src/test/java/de/muenchen/oss/wahl…
dragonfly28 Jan 8, 2025
5381fd4
test restructured according to our naming conventions
dragonfly28 Jan 8, 2025
8f08296
mvn spotless:apply
dragonfly28 Jan 8, 2025
124c022
comment from review added
dragonfly28 Jan 8, 2025
a933f73
Merge branch 'dev' into 191-lesen-und-schreiben-der-stimmzettelumschläge
dragonfly28 Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stack/keycloak/migration/keycloak-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ includes:
- path: add-authorities-ergebnismeldung-awerte.yml
- path: add-authorities-ergebnismeldung-status.yml
- path: add-authorities-ergebnismeldung-wahlscheine.yml
- path: add-authorities-ergebnismeldung-begruendung.yml
- path: add-authorities-ergebnismeldung-stimmzettelumschlaege.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.common.security;

import java.util.Optional;
import org.springframework.context.annotation.Profile;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

@Component
@Profile("no-security")
public class AnonymousHandler implements AuthenticationHandler {
@Override
public boolean canHandle(Authentication authentication) {
return authentication instanceof AnonymousAuthenticationToken;
}

@Override
public Optional<String> getDetail(String detailKey, Authentication authentication) {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.common.security;

import java.util.Optional;
import org.springframework.security.core.Authentication;

public interface AuthenticationHandler {

boolean canHandle(Authentication authentication);

Optional<String> getDetail(String detailKey, Authentication authentication);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.common.security;

import java.util.Optional;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
import org.springframework.stereotype.Component;

@Component
public class JWTHandler implements AuthenticationHandler {

@Override
public boolean canHandle(final Authentication authentication) {
return authentication instanceof JwtAuthenticationToken;
}

public Optional<String> getDetail(final String detailKey, final Authentication authentication) {
if (authentication instanceof JwtAuthenticationToken jwtToken) {
return Optional.ofNullable(jwtToken.getToken().getClaimAsString(detailKey));
} else {
return Optional.empty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class ExceptionConstants {
"postStimmzettelumschlaege: Parameter unvollstaendig");
public static final ExceptionDataWrapper STIMMZETTELUMSCHLAEGE_UNSAVEABLE = new ExceptionDataWrapper("619",
"postStimmzettelumschlaege: Die Stimmzettelumschlaege konnten nicht gespeichert werden.");
public static final ExceptionDataWrapper WAHLBEZIRKART_NOT_LOADABLE = new ExceptionDataWrapper("800",
"Die Wahlbezirkart des Principals konnte nicht geladen werden.");

public static final ExceptionDataWrapper KOMMUNIKATIONSFEHLER_MIT_MONITORING = new ExceptionDataWrapper("100",
"Bei der Kommunikation mit dem MonitoringService kam es zu einem Fehler.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.service.stimmzettelumschlaege;

import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.common.security.AuthenticationHandler;
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.stimmzettelumschlaege.StimmzettelumschlaegeRepository;
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.exception.ExceptionConstants;
import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory;
import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID;
import java.util.Collection;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

Expand All @@ -17,10 +20,13 @@
@Slf4j
public class StimmzettelumschlaegeService {

private static final String WAHLBEZIRK_ART_USER_DETAIL_KEY = "wahlbezirksArt";

private final StimmzettelumschlaegeRepository stimmzettelumschlaegeRepository;
private final StimmzettelumschlaegeModelMapper stimmzettelumschlaegeModelMapper;
private final StimmzettelumschlaegeValidator stimmzettelumschlaegeValidator;
private final ExceptionFactory exceptionFactory;
private final Collection<AuthenticationHandler> authenticationHandlers;

@PreAuthorize("hasAuthority('Ergebnismeldung_BUSINESSACTION_GetStimmzettelumschlaege')")
public Optional<StimmzettelumschlaegeModel> getStimmzettelumschlaege(final BezirkUndWahlID id) {
Expand All @@ -43,6 +49,8 @@ public void setStimmzettelumschlaege(@P("param") final BezirkUndWahlID id, final
stimmzettelumschlaegeValidator.validBezirkUndWahlIdOrThrow(id,
exceptionFactory.createFachlicheWlsException(ExceptionConstants.POST_STIMMZETTELUMSCHLAEGE_PARAMETER_UNVOLLSTAENDIG));
stimmzettelumschlaegeValidator.validStimmzettelumschlaegeOrThrow(stimmzettelumschlaege);
val wahlbezirkArtOfRequest = getWahlbezirkArt();
stimmzettelumschlaegeValidator.validHasBWBRequiredEroeffnungsUhrzeitOrThrow(wahlbezirkArtOfRequest, stimmzettelumschlaege.urneneroeffnungsUhrzeit());

try {
stimmzettelumschlaegeRepository.save(stimmzettelumschlaegeModelMapper.toEntity(stimmzettelumschlaege));
Expand All @@ -51,4 +59,15 @@ public void setStimmzettelumschlaege(@P("param") final BezirkUndWahlID id, final
throw exceptionFactory.createTechnischeWlsException(ExceptionConstants.STIMMZETTELUMSCHLAEGE_UNSAVEABLE);
}
}

private WahlbezirkArtModel getWahlbezirkArt() {
val currentAuthentication = SecurityContextHolder.getContext().getAuthentication();
val authenticationHandler = authenticationHandlers.stream().filter(handler -> handler.canHandle(currentAuthentication)).findFirst();
try {
val wahlbezirkOfUser = authenticationHandler.get().getDetail(WAHLBEZIRK_ART_USER_DETAIL_KEY, currentAuthentication);
return wahlbezirkOfUser.map(WahlbezirkArtModel::valueOf).get();
} catch (Exception e) {
throw exceptionFactory.createTechnischeWlsException(ExceptionConstants.WAHLBEZIRKART_NOT_LOADABLE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException;
import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory;
import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID;
import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
Expand All @@ -26,4 +27,10 @@ public void validStimmzettelumschlaegeOrThrow(final StimmzettelumschlaegeModel s
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.POST_STIMMZETTELUMSCHLAEGE_PARAMETER_UNVOLLSTAENDIG);
}
}

public void validHasBWBRequiredEroeffnungsUhrzeitOrThrow(final WahlbezirkArtModel wahlbezirkArt, LocalDateTime urnenEroeffnungsUhrzeit) {
if (wahlbezirkArt.equals(WahlbezirkArtModel.BWB) && urnenEroeffnungsUhrzeit == null) {
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.POST_STIMMZETTELUMSCHLAEGE_PARAMETER_UNVOLLSTAENDIG);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.service.stimmzettelumschlaege;

public enum WahlbezirkArtModel {
UWB, BWB
}
Loading
Loading