Skip to content

Commit

Permalink
Merge pull request #58 from dancier/upgrade-boot
Browse files Browse the repository at this point in the history
human bla
  • Loading branch information
gorzala committed Jan 14, 2024
2 parents 70ef8f6 + 26a6896 commit 0061f7b
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 0061f7b

Please sign in to comment.