Skip to content

Commit

Permalink
human bla
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Gorzala committed Jan 14, 2024
1 parent 09a8608 commit 26a6896
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class AuthenticatedUser implements UserDetails {
private UUID userId;

private Optional<UUID> optionalDancerId = Optional.empty();

private String email;

private String password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
}

private Authentication onlyCaptchaVerified() {

SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority("ROLE_HUMAN");
List<GrantedAuthority> authorities = List.of(simpleGrantedAuthority);
AuthenticatedUser authenticatedUser = new AuthenticatedUser(
null,
null,
true,
null,
Optional.empty(),
authorities
);


Authentication authentication = new Authentication() {
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Expand All @@ -74,7 +87,7 @@ public Object getDetails() {

@Override
public Object getPrincipal() {
return null;
return authenticatedUser;
}

@Override
Expand Down

0 comments on commit 26a6896

Please sign in to comment.