|  | 
| 40 | 40 | import org.springframework.context.annotation.Bean; | 
| 41 | 41 | import org.springframework.context.annotation.Configuration; | 
| 42 | 42 | import org.springframework.context.annotation.Role; | 
| 43 |  | -import org.springframework.http.HttpStatusCode; | 
| 44 |  | -import org.springframework.http.ResponseEntity; | 
| 45 | 43 | import org.springframework.security.access.AccessDeniedException; | 
| 46 | 44 | import org.springframework.security.access.PermissionEvaluator; | 
| 47 | 45 | import org.springframework.security.access.annotation.Secured; | 
|  | 
| 67 | 65 | import org.springframework.security.test.context.support.WithMockUser; | 
| 68 | 66 | import org.springframework.stereotype.Component; | 
| 69 | 67 | import org.springframework.test.context.junit.jupiter.SpringExtension; | 
| 70 |  | -import org.springframework.web.servlet.ModelAndView; | 
| 71 | 68 | 
 | 
| 72 | 69 | import static org.assertj.core.api.Assertions.assertThat; | 
| 73 | 70 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | 
| @@ -364,48 +361,6 @@ public void findByIdWhenUnauthorizedResultThenDenies() { | 
| 364 | 361 | 		assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> flight.getAltitude().block()); | 
| 365 | 362 | 	} | 
| 366 | 363 | 
 | 
| 367 |  | -	@Test | 
| 368 |  | -	@WithMockUser(authorities = "airplane:read") | 
| 369 |  | -	public void findByIdWhenAuthorizedResponseEntityThenAuthorizes() { | 
| 370 |  | -		this.spring.register(AuthorizeResultConfig.class).autowire(); | 
| 371 |  | -		FlightRepository flights = this.spring.getContext().getBean(FlightRepository.class); | 
| 372 |  | -		Flight flight = flights.webFindById("1").block().getBody(); | 
| 373 |  | -		assertThatNoException().isThrownBy(() -> flight.getAltitude().block()); | 
| 374 |  | -		assertThatNoException().isThrownBy(() -> flight.getSeats().block()); | 
| 375 |  | -	} | 
| 376 |  | - | 
| 377 |  | -	@Test | 
| 378 |  | -	@WithMockUser(authorities = "seating:read") | 
| 379 |  | -	public void findByIdWhenUnauthorizedResponseEntityThenDenies() { | 
| 380 |  | -		this.spring.register(AuthorizeResultConfig.class).autowire(); | 
| 381 |  | -		FlightRepository flights = this.spring.getContext().getBean(FlightRepository.class); | 
| 382 |  | -		Flight flight = flights.webFindById("1").block().getBody(); | 
| 383 |  | -		assertThatNoException().isThrownBy(() -> flight.getSeats().block()); | 
| 384 |  | -		assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> flight.getAltitude().block()); | 
| 385 |  | -	} | 
| 386 |  | - | 
| 387 |  | -	@Test | 
| 388 |  | -	@WithMockUser(authorities = "airplane:read") | 
| 389 |  | -	public void findByIdWhenAuthorizedModelAndViewThenAuthorizes() { | 
| 390 |  | -		this.spring.register(AuthorizeResultConfig.class).autowire(); | 
| 391 |  | -		FlightRepository flights = this.spring.getContext().getBean(FlightRepository.class); | 
| 392 |  | -		Flight flight = (Flight) flights.webViewFindById("1").block().getModel().get("flight"); | 
| 393 |  | -		assertThatNoException().isThrownBy(() -> flight.getAltitude().block()); | 
| 394 |  | -		assertThatNoException().isThrownBy(() -> flight.getSeats().block()); | 
| 395 |  | -		assertThat(flights.webViewFindById("5").block().getModel().get("flight")).isNull(); | 
| 396 |  | -	} | 
| 397 |  | - | 
| 398 |  | -	@Test | 
| 399 |  | -	@WithMockUser(authorities = "seating:read") | 
| 400 |  | -	public void findByIdWhenUnauthorizedModelAndViewThenDenies() { | 
| 401 |  | -		this.spring.register(AuthorizeResultConfig.class).autowire(); | 
| 402 |  | -		FlightRepository flights = this.spring.getContext().getBean(FlightRepository.class); | 
| 403 |  | -		Flight flight = (Flight) flights.webViewFindById("1").block().getModel().get("flight"); | 
| 404 |  | -		assertThatNoException().isThrownBy(() -> flight.getSeats().block()); | 
| 405 |  | -		assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> flight.getAltitude().block()); | 
| 406 |  | -		assertThat(flights.webViewFindById("5").block().getModel().get("flight")).isNull(); | 
| 407 |  | -	} | 
| 408 |  | - | 
| 409 | 364 | 	@Test | 
| 410 | 365 | 	@WithMockUser(authorities = "seating:read") | 
| 411 | 366 | 	public void findAllWhenUnauthorizedResultThenDenies() { | 
| @@ -769,22 +724,6 @@ Mono<Void> remove(String id) { | 
| 769 | 724 | 			return Mono.empty(); | 
| 770 | 725 | 		} | 
| 771 | 726 | 
 | 
| 772 |  | -		Mono<ResponseEntity<Flight>> webFindById(String id) { | 
| 773 |  | -			Flight flight = this.flights.get(id); | 
| 774 |  | -			if (flight == null) { | 
| 775 |  | -				return Mono.just(ResponseEntity.notFound().build()); | 
| 776 |  | -			} | 
| 777 |  | -			return Mono.just(ResponseEntity.ok(flight)); | 
| 778 |  | -		} | 
| 779 |  | - | 
| 780 |  | -		Mono<ModelAndView> webViewFindById(String id) { | 
| 781 |  | -			Flight flight = this.flights.get(id); | 
| 782 |  | -			if (flight == null) { | 
| 783 |  | -				return Mono.just(new ModelAndView("error", HttpStatusCode.valueOf(404))); | 
| 784 |  | -			} | 
| 785 |  | -			return Mono.just(new ModelAndView("flights", Map.of("flight", flight))); | 
| 786 |  | -		} | 
| 787 |  | - | 
| 788 | 727 | 	} | 
| 789 | 728 | 
 | 
| 790 | 729 | 	@AuthorizeReturnObject | 
|  | 
0 commit comments