Search in sources :

Example 1 with UmaResource

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();
}
Also used : UmaResource(io.jans.as.model.uma.persistence.UmaResource) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Example 2 with UmaResource

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);
}
Also used : UmaResource(io.jans.as.model.uma.persistence.UmaResource)

Example 3 with UmaResource

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");
}
Also used : Scope(io.jans.as.persistence.model.Scope) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) UmaResource(io.jans.as.model.uma.persistence.UmaResource)

Example 4 with UmaResource

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));
    }
}
Also used : EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) UmaResource(io.jans.as.model.uma.persistence.UmaResource)

Example 5 with UmaResource

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();
}
Also used : UmaResource(io.jans.as.model.uma.persistence.UmaResource) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Aggregations

UmaResource (io.jans.as.model.uma.persistence.UmaResource)8 ProtectedApi (io.jans.configapi.core.rest.ProtectedApi)3 Client (io.jans.as.common.model.registration.Client)2 BaseComponentTest (io.jans.as.server.BaseComponentTest)2 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)2 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 Test (org.testng.annotations.Test)2 Scope (io.jans.as.persistence.model.Scope)1 WebApplicationException (javax.ws.rs.WebApplicationException)1