[KEYCLOAK-5900] - Returning error response when resource does not exist

This commit is contained in:
pedroigor 2017-11-28 19:45:49 -02:00
parent 3afb635110
commit c5b06f23e9

View file

@ -211,16 +211,22 @@ public class EntitlementService {
break;
}
Resource resource;
Resource resource = null;
if (requestedResource.getResourceSetId() != null) {
resource = storeFactory.getResourceStore().findById(requestedResource.getResourceSetId(), resourceServer.getId());
} else {
if (resource == null) {
throw new ErrorResponseException("invalid_resource", "Resource with id [" + requestedResource.getResourceSetId() + "] does not exist.", Status.FORBIDDEN);
}
} else if (requestedResource.getResourceSetName() != null) {
resource = storeFactory.getResourceStore().findByName(requestedResource.getResourceSetName(), resourceServer.getId());
if (resource == null) {
throw new ErrorResponseException("invalid_resource", "Resource with name [" + requestedResource.getResourceSetName() + "] does not exist.", Status.FORBIDDEN);
}
}
if (resource == null && (requestedResource.getScopes() == null || requestedResource.getScopes().isEmpty())) {
throw new ErrorResponseException("invalid_resource", "Resource with id [" + requestedResource.getResourceSetId() + "] or name [" + requestedResource.getResourceSetName() + "] does not exist.", Status.FORBIDDEN);
throw new ErrorResponseException("invalid_request", "You must provide a resource and/or scopes.", Status.FORBIDDEN);
}
Set<ScopeRepresentation> requestedScopes = requestedResource.getScopes().stream().map(ScopeRepresentation::new).collect(Collectors.toSet());