|
5 | 5 | import org.owasp.webwolf.user.UserRepository; |
6 | 6 | import org.owasp.webwolf.user.WebGoatUser; |
7 | 7 | import org.springframework.http.HttpStatus; |
| 8 | +import org.springframework.http.ResponseEntity; |
8 | 9 | import org.springframework.security.core.context.SecurityContextHolder; |
9 | | -import org.springframework.web.bind.annotation.*; |
| 10 | +import org.springframework.web.bind.annotation.GetMapping; |
| 11 | +import org.springframework.web.bind.annotation.PostMapping; |
| 12 | +import org.springframework.web.bind.annotation.RequestBody; |
| 13 | +import org.springframework.web.bind.annotation.RestController; |
10 | 14 | import org.springframework.web.servlet.ModelAndView; |
11 | 15 |
|
12 | 16 | import java.util.List; |
| 17 | +import java.util.concurrent.Callable; |
13 | 18 |
|
14 | 19 | /** |
15 | 20 | * @author nbaars |
@@ -37,13 +42,16 @@ public ModelAndView mail() { |
37 | 42 | } |
38 | 43 |
|
39 | 44 | @PostMapping(value = "/mail") |
40 | | - @ResponseStatus(HttpStatus.CREATED) |
41 | | - public void sendEmail(@RequestBody Email email) { |
42 | | - if (userRepository.findByUsername(email.getRecipient()) != null) { |
43 | | - mailboxRepository.save(email); |
44 | | - } else { |
45 | | - log.trace("Mail received for unknown user: {}", email.getRecipient()); |
46 | | - } |
| 45 | + public Callable<ResponseEntity<?>> sendEmail(@RequestBody Email email) { |
| 46 | + return () -> { |
| 47 | + if (userRepository.findByUsername(email.getRecipient()) != null) { |
| 48 | + mailboxRepository.save(email); |
| 49 | + return ResponseEntity.status(HttpStatus.CREATED).build(); |
| 50 | + } else { |
| 51 | + log.trace("Mail received for unknown user: {}", email.getRecipient()); |
| 52 | + return ResponseEntity.notFound().build(); |
| 53 | + } |
| 54 | + }; |
47 | 55 | } |
48 | 56 |
|
49 | 57 | } |
0 commit comments