@Test @WithMockUser("Alice") void testRequest() { LeaveRequest leaveRequest = service.request("Alice", of(2019, 11, 30), of(2019, 12, 03)); verify(repository).save(leaveRequest); }
@PreAuthorize("#employee == authentication.name or hasRole('HR')") public LeaveRequest request(String employee, LocalDate from, LocalDate to) { LeaveRequest leaveRequest = LeaveRequest.builder() .employee(employee) .fromDate(from) .toDate(to) .build(); return repo.save(leaveRequest); }
LeaveRequestService { @PreAuthorize("#employee == authentication.name or hasRole('HR')") public LeaveRequest request(String employee, LocalDate from, LocalDate to) { LeaveRequest leaveRequest = LeaveRequest.builder() .employee(employee) .fromDate(from) .toDate(to) .build(); return repo.save(leaveRequest); } }
LeaveRequestService { @PreAuthorize("#employee == authentication.name or hasRole('HR')") public LeaveRequest request(String employee, LocalDate from, LocalDate to) { LeaveRequest leaveRequest = LeaveRequest.builder() .employee(employee) .fromDate(from) .toDate(to) .build(); return repo.save(leaveRequest); }  }
LeaveRequestService { @PreAuthorize("#employee == authentication.name or hasRole('HR')") public LeaveRequest request(String employee, LocalDate from, LocalDate to) { LeaveRequest leaveRequest = LeaveRequest.builder() .employee(employee) .fromDate(from) .toDate(to) .build(); return repo.save(leaveRequest); }  @PreAuthorize("#employee == authentication.name or hasRole('HR')") LeaveRequest request(String employee, LocalDate from, LocalDate to); @RolesAllowed("HR") Optional<LeaveRequest> approve(UUID id); @RolesAllowed("HR") Optional<LeaveRequest> deny(UUID id); @PostAuthorize("returnObject.orElse(null)?.employee == authentication.name or hasRole('HR')") Optional<LeaveRequest> retrieve(UUID id); @PreAuthorize("#employee == authentication.name or hasRole('HR')") List<LeaveRequest> retrieveFor(String employee); @RolesAllowed("HR") List<LeaveRequest> retrieveAll(); }
LeaveRequestService { @PreAuthorize("#employee == authentication.name or hasRole('HR')") public LeaveRequest request(String employee, LocalDate from, LocalDate to) { LeaveRequest leaveRequest = LeaveRequest.builder() .employee(employee) .fromDate(from) .toDate(to) .build(); return repo.save(leaveRequest); }  @PreAuthorize("#employee == authentication.name or hasRole('HR')") LeaveRequest request(String employee, LocalDate from, LocalDate to); @RolesAllowed("HR") Optional<LeaveRequest> approve(UUID id); @RolesAllowed("HR") Optional<LeaveRequest> deny(UUID id); @PostAuthorize("returnObject.orElse(null)?.employee == authentication.name or hasRole('HR')") Optional<LeaveRequest> retrieve(UUID id); @PreAuthorize("#employee == authentication.name or hasRole('HR')") List<LeaveRequest> retrieveFor(String employee); @RolesAllowed("HR") List<LeaveRequest> retrieveAll();  }