From 1cda31d742cf428a9a997f90895d73a7e8493502 Mon Sep 17 00:00:00 2001 From: Marc Gorzala Date: Sun, 14 Jan 2024 17:43:56 +0100 Subject: [PATCH] bug fix (maybe) --- .../net/dancier/dancer/contact/ContactService.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/dancier/dancer/contact/ContactService.java b/src/main/java/net/dancier/dancer/contact/ContactService.java index ac3097b..6a6b5b7 100644 --- a/src/main/java/net/dancier/dancer/contact/ContactService.java +++ b/src/main/java/net/dancier/dancer/contact/ContactService.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import static net.dancier.dancer.authentication.Constants.ROLE_USER; @@ -28,9 +29,13 @@ public class ContactService { void send(ContactDto contactDto, AuthenticatedUser authenticatedUserOfSender) { log.info("Having authenticated: {}", authenticatedUserOfSender); - String senderMailAddress = authenticatedUserOfSender.getAuthorities().contains(ROLE_USER) - ? authenticatedUserOfSender.getEmail() - : contactDto.getSender(); + String senderMailAddress; + if (authenticatedUserOfSender.getAuthorities().stream().map(GrantedAuthority::getAuthority).anyMatch(s -> s.equals(ROLE_USER))) { + log.info("Overwriting sender..."); + senderMailAddress = authenticatedUserOfSender.getEmail(); + } else { + senderMailAddress = contactDto.getSender(); + } log.info("Using this: {} as sender address", senderMailAddress); SimpleMailMessage mailToSender = mailCreationService.createDancierMessageFromTemplate( senderMailAddress,