use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException in project spring-boot by spring-projects.
the class ReactiveCloudFoundrySecurityInterceptorTests method preHandleWhenApplicationIdIsNullShouldReturnError.
@Test
void preHandleWhenApplicationIdIsNullShouldReturnError() {
this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, this.securityService, null);
MockServerWebExchange request = MockServerWebExchange.from(MockServerHttpRequest.get("/a").header(HttpHeaders.AUTHORIZATION, "bearer " + mockAccessToken()).build());
StepVerifier.create(this.interceptor.preHandle(request, "/a")).consumeErrorWith((ex) -> assertThat(((CloudFoundryAuthorizationException) ex).getReason()).isEqualTo(Reason.SERVICE_UNAVAILABLE)).verify();
}
use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException in project spring-boot by spring-projects.
the class CloudFoundryMvcWebEndpointIntegrationTests method linksToOtherEndpointsForbidden.
@Test
void linksToOtherEndpointsForbidden() {
CloudFoundryAuthorizationException exception = new CloudFoundryAuthorizationException(Reason.INVALID_TOKEN, "invalid-token");
willThrow(exception).given(tokenValidator).validate(any());
load(TestEndpointConfiguration.class, (client) -> client.get().uri("/cfApplication").accept(MediaType.APPLICATION_JSON).header("Authorization", "bearer " + mockAccessToken()).exchange().expectStatus().isUnauthorized());
}
use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException in project spring-boot by spring-projects.
the class CloudFoundryWebFluxEndpointIntegrationTests method linksToOtherEndpointsForbidden.
@Test
void linksToOtherEndpointsForbidden() {
CloudFoundryAuthorizationException exception = new CloudFoundryAuthorizationException(Reason.INVALID_TOKEN, "invalid-token");
willThrow(exception).given(tokenValidator).validate(any());
this.contextRunner.run(withWebTestClient((client) -> client.get().uri("/cfApplication").accept(MediaType.APPLICATION_JSON).header("Authorization", "bearer " + mockAccessToken()).exchange().expectStatus().isUnauthorized()));
}
use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException in project spring-boot by spring-projects.
the class CloudFoundrySecurityService method getUaaUrl.
/**
* Return the URL of the UAA.
* @return the UAA url
*/
String getUaaUrl() {
if (this.uaaUrl == null) {
try {
Map<?, ?> response = this.restTemplate.getForObject(this.cloudControllerUrl + "/info", Map.class);
this.uaaUrl = (String) response.get("token_endpoint");
} catch (HttpStatusCodeException ex) {
throw new CloudFoundryAuthorizationException(Reason.SERVICE_UNAVAILABLE, "Unable to fetch token keys from UAA");
}
}
return this.uaaUrl;
}
use of org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException in project spring-boot by spring-projects.
the class CloudFoundrySecurityService method getAccessLevel.
/**
* Return the access level that should be granted to the given token.
* @param token the token
* @param applicationId the cloud foundry application ID
* @return the access level that should be granted
* @throws CloudFoundryAuthorizationException if the token is not authorized
*/
AccessLevel getAccessLevel(String token, String applicationId) throws CloudFoundryAuthorizationException {
try {
URI uri = getPermissionsUri(applicationId);
RequestEntity<?> request = RequestEntity.get(uri).header("Authorization", "bearer " + token).build();
Map<?, ?> body = this.restTemplate.exchange(request, Map.class).getBody();
if (Boolean.TRUE.equals(body.get("read_sensitive_data"))) {
return AccessLevel.FULL;
}
return AccessLevel.RESTRICTED;
} catch (HttpClientErrorException ex) {
if (ex.getStatusCode().equals(HttpStatus.FORBIDDEN)) {
throw new CloudFoundryAuthorizationException(Reason.ACCESS_DENIED, "Access denied");
}
throw new CloudFoundryAuthorizationException(Reason.INVALID_TOKEN, "Invalid token", ex);
} catch (HttpServerErrorException ex) {
throw new CloudFoundryAuthorizationException(Reason.SERVICE_UNAVAILABLE, "Cloud controller not reachable");
}
}
Aggregations