diff --git a/src/main/java/net/dancier/dancer/contact/ContactController.java b/src/main/java/net/dancier/dancer/contact/ContactController.java index 5d8f1c5..b990cec 100644 --- a/src/main/java/net/dancier/dancer/contact/ContactController.java +++ b/src/main/java/net/dancier/dancer/contact/ContactController.java @@ -30,7 +30,6 @@ public class ContactController { @Secured({ROLE_HUMAN}) public ResponseEntity sentMail(@RequestBody ContactDto contactDto, @CurrentUser AuthenticatedUser currentUser) { - log.info("Sending {} to {}.", contactDto.getMessage(), contactDto.getSender()); contactService.send(contactDto, currentUser); return ResponseEntity.status(HttpStatus.CREATED).build(); diff --git a/src/main/java/net/dancier/dancer/contact/ContactService.java b/src/main/java/net/dancier/dancer/contact/ContactService.java index 0f7a86b..2491e68 100644 --- a/src/main/java/net/dancier/dancer/contact/ContactService.java +++ b/src/main/java/net/dancier/dancer/contact/ContactService.java @@ -27,7 +27,7 @@ public class ContactService { private final ApplicationEventPublisher applicationEventPublisher; void send(ContactDto contactDto, AuthenticatedUser authenticatedUserOfSender) { - String senderMailAddress = (authenticatedUserOfSender.getAuthorities().contains(ROLE_USER)) + String senderMailAddress = authenticatedUserOfSender.getAuthorities().contains(ROLE_USER) ? authenticatedUserOfSender.getEmail() : contactDto.getSender(); SimpleMailMessage mailToSender = mailCreationService.createDancierMessageFromTemplate( diff --git a/src/main/java/net/dancier/dancer/security/AuthenticatedUser.java b/src/main/java/net/dancier/dancer/security/AuthenticatedUser.java index 05c75ab..a5724c4 100644 --- a/src/main/java/net/dancier/dancer/security/AuthenticatedUser.java +++ b/src/main/java/net/dancier/dancer/security/AuthenticatedUser.java @@ -16,6 +16,7 @@ public class AuthenticatedUser implements UserDetails { private UUID userId; private Optional optionalDancerId = Optional.empty(); + private String email; private String password; diff --git a/src/main/java/net/dancier/dancer/security/JwtAuthenticationFilter.java b/src/main/java/net/dancier/dancer/security/JwtAuthenticationFilter.java index 3aaaf8d..afff317 100644 --- a/src/main/java/net/dancier/dancer/security/JwtAuthenticationFilter.java +++ b/src/main/java/net/dancier/dancer/security/JwtAuthenticationFilter.java @@ -55,6 +55,19 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse } private Authentication onlyCaptchaVerified() { + + SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority("ROLE_HUMAN"); + List authorities = List.of(simpleGrantedAuthority); + AuthenticatedUser authenticatedUser = new AuthenticatedUser( + null, + null, + true, + null, + Optional.empty(), + authorities + ); + + Authentication authentication = new Authentication() { @Override public Collection getAuthorities() { @@ -74,7 +87,7 @@ public Object getDetails() { @Override public Object getPrincipal() { - return null; + return authenticatedUser; } @Override