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

human bla #58

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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