use of io.jans.as.model.uma.persistence.UmaResource in project jans by JanssenProject.
the class UmaResourcesResource method patchResource.
@PATCH
@Consumes(MediaType.APPLICATION_JSON_PATCH_JSON)
@ProtectedApi(scopes = { ApiAccessConstants.UMA_RESOURCES_WRITE_ACCESS })
@Path(ApiConstants.ID_PATH)
public Response patchResource(@PathParam(ApiConstants.ID) @NotNull String id, @NotNull String pathString) throws JsonPatchException, IOException {
log.debug("UMA_RESOURCE to be patched - id = " + id + " , pathString = " + pathString);
UmaResource existingResource = findOrThrow(id);
existingResource = Jackson.applyPatch(pathString, existingResource);
umaResourceService.updateResource(existingResource);
return Response.ok(existingResource).build();
}
use of io.jans.as.model.uma.persistence.UmaResource in project jans by JanssenProject.
the class UmaResourceService method getResourceById.
public UmaResource getResourceById(String id) {
prepareBranch();
try {
final String key = getDnForResource(id);
final UmaResource resource = cacheService.getWithPut(key, () -> ldapEntryManager.find(UmaResource.class, key), RESOURCE_CACHE_EXPIRATION_IN_SECONDS);
if (resource != null) {
return resource;
}
} catch (Exception e) {
log.error(String.format("Failed to find resource set with id: %s", id), e);
}
log.error("Failed to find resource set with id: {}", id);
throw errorResponseFactory.createWebApplicationException(Response.Status.NOT_FOUND, UmaErrorResponseType.NOT_FOUND, "Failed to find resource set with id: " + id);
}
use of io.jans.as.model.uma.persistence.UmaResource in project jans by JanssenProject.
the class UmaValidationService method validatePermission.
public void validatePermission(io.jans.as.model.uma.UmaPermission permission, Client client) {
String resourceId = permission.getResourceId();
if (StringHelper.isEmpty(resourceId)) {
log.error("Resource id is empty");
throw errorResponseFactory.createWebApplicationException(BAD_REQUEST, INVALID_RESOURCE_ID, "Resource id is empty");
}
try {
UmaResource resource = resourceService.getResourceById(resourceId);
if (resource == null) {
log.error("Resource isn't registered or there are two resources with same Id");
throw errorResponseFactory.createWebApplicationException(BAD_REQUEST, INVALID_RESOURCE_ID, "Resource is not registered.");
}
for (String s : permission.getScopes()) {
if (resource.getScopes().contains(s)) {
continue;
}
final Scope spontaneousScope = umaScopeService.getOrCreate(client, s, Sets.newHashSet(umaScopeService.getScopeIdsByDns(resource.getScopes())));
if (spontaneousScope == null) {
log.error("Scope isn't registered and is not allowed by spontaneous scopes. Scope: {}", s);
throw errorResponseFactory.createWebApplicationException(BAD_REQUEST, INVALID_SCOPE, "At least one of the scopes isn't registered");
}
}
return;
} catch (EntryPersistenceException ex) {
log.error(ex.getMessage(), ex);
}
log.error("Resource isn't registered");
throw errorResponseFactory.createWebApplicationException(BAD_REQUEST, INVALID_RESOURCE_ID, "Resource isn't registered");
}
use of io.jans.as.model.uma.persistence.UmaResource in project jans by JanssenProject.
the class UmaResourcesResource method findOrThrow.
private UmaResource findOrThrow(String id) {
try {
UmaResource existingResource = umaResourceService.getResourceById(id);
checkResourceNotNull(existingResource, UMA_RESOURCE);
return existingResource;
} catch (EntryPersistenceException e) {
throw new NotFoundException(getNotFoundError(UMA_RESOURCE));
}
}
use of io.jans.as.model.uma.persistence.UmaResource in project jans by JanssenProject.
the class UmaResourcesResource method deleteUmaResource.
@DELETE
@Path(ApiConstants.ID_PATH)
@ProtectedApi(scopes = { ApiAccessConstants.UMA_RESOURCES_DELETE_ACCESS })
public Response deleteUmaResource(@PathParam(value = ApiConstants.ID) @NotNull String id) {
log.debug("UMA_RESOURCE to delete - id = " + id);
UmaResource umaResource = findOrThrow(id);
umaResourceService.remove(umaResource);
return Response.status(Response.Status.NO_CONTENT).build();
}
Aggregations