Merge pull request #4760 from pedroigor/KEYCLOAK-5900

[KEYCLOAK-5900] - Returning error response when resource does not exist
This commit is contained in:
Pedro Igor 2017-11-29 10:38:44 -02:00 committed by GitHub
commit d22c58ee30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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());