Add extra informational message when a failure occurs while sending an email from WebGoat to WebWolf.
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
package org.owasp.webwolf.mailbox;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@ -13,6 +16,8 @@ import java.time.format.DateTimeFormatter;
|
||||
* @since 8/20/17.
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
public class Email implements Serializable {
|
||||
@ -20,7 +25,7 @@ public class Email implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private LocalDateTime time;
|
||||
private LocalDateTime time = LocalDateTime.now();
|
||||
@Column(length = 1024)
|
||||
private String contents;
|
||||
private String sender;
|
||||
@ -28,7 +33,7 @@ public class Email implements Serializable {
|
||||
private String recipient;
|
||||
|
||||
public String getSummary() {
|
||||
return "-" + this.contents.substring(0, 50);
|
||||
return "-" + this.contents.substring(0, Math.min(50, contents.length()));
|
||||
}
|
||||
|
||||
public LocalDateTime getTimestamp() {
|
||||
|
@ -7,6 +7,7 @@ import org.owasp.webwolf.user.WebGoatUser;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@ -25,12 +26,11 @@ import java.util.concurrent.Callable;
|
||||
@Slf4j
|
||||
public class MailboxController {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final MailboxRepository mailboxRepository;
|
||||
|
||||
@GetMapping(value = "/WebWolf/mail")
|
||||
public ModelAndView mail() {
|
||||
WebGoatUser user = (WebGoatUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
List<Email> emails = mailboxRepository.findByRecipientOrderByTimeDesc(user.getUsername());
|
||||
if (emails != null && !emails.isEmpty()) {
|
||||
@ -44,13 +44,8 @@ public class MailboxController {
|
||||
@PostMapping(value = "/mail")
|
||||
public Callable<ResponseEntity<?>> sendEmail(@RequestBody Email email) {
|
||||
return () -> {
|
||||
if (userRepository.findByUsername(email.getRecipient()) != null) {
|
||||
mailboxRepository.save(email);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||
} else {
|
||||
log.trace("Mail received for unknown user: {}", email.getRecipient());
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
mailboxRepository.save(email);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user