Spring WebFlux's ServerWebExchange comes prepared for security by providing a getPrincipal() API that returns Mono<Principal>. While the default version, straight out of Spring Framework, supplies Mono.empty(), Spring Security automatically hooks in a filter to supply a real value via WebSessionSecurityContextRepository.
With Spring Security and Spring Session hooked into all our web calls, we can leverage this information every time a new image is uploaded.
First of all, we can adjust our Image domain object as follows:
@Data @AllArgsConstructor public class Image { @Id private String id; private String name; private String owner; }
This last code is the same POJO that we've used throughout this book with one change:
- It now has a String owner property. This lets us associate an image with whoever...