Search in sources :

Example 6 with UmaResource

use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxTrust by GluuFederation.

the class UmaResourceWebResource method addClientToUmaResource.

@POST
@Operation(summary = "Add UMA resource client", description = "add client to uma resource")
@ApiResponses(value = { @ApiResponse(responseCode = "201", content = @Content(schema = @Schema(implementation = UmaResource.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@Path(ApiConstants.ID_PARAM_PATH + ApiConstants.CLIENTS + ApiConstants.INUM_PARAM_PATH)
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response addClientToUmaResource(@PathParam(ApiConstants.ID) @NotNull String id, @PathParam(ApiConstants.INUM) @NotNull String clientInum) {
    try {
        log(logger, "Add client " + clientInum + " to uma resource " + id);
        Objects.requireNonNull(id, "Uma id should not be null");
        Objects.requireNonNull(clientInum, "Client inum should not be null");
        List<UmaResource> resources = umaResourcesService.findResourcesById(id);
        OxAuthClient client = clientService.getClientByInum(clientInum);
        if (resources != null && !resources.isEmpty() && client != null) {
            UmaResource umaResource = resources.get(0);
            List<String> clientsDn = new ArrayList<String>();
            if (umaResource.getClients() != null) {
                clientsDn.addAll(umaResource.getClients());
            }
            clientsDn.add(clientService.getDnForClient(clientInum));
            umaResource.setClients(clientsDn);
            umaResourcesService.updateResource(umaResource);
            return Response.status(Response.Status.CREATED).entity(umaResourcesService.findResourcesById(id).get(0)).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) ArrayList(java.util.ArrayList) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 7 with UmaResource

use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxTrust by GluuFederation.

the class UmaResourceWebResource method getUmaResourceClients.

@GET
@Path(ApiConstants.ID_PARAM_PATH + ApiConstants.CLIENTS)
@Operation(summary = "Get clients of UMA resources", description = "Get clients of uma resource")
@ProtectedApi(scopes = { READ_ACCESS })
public Response getUmaResourceClients(@PathParam(ApiConstants.ID) @NotNull String id) {
    try {
        log(logger, "Get clients of uma resource having id " + id);
        Objects.requireNonNull(id, "id should not be null");
        List<UmaResource> resources = umaResourcesService.findResourcesById(id);
        if (resources != null && !resources.isEmpty()) {
            UmaResource resource = resources.get(0);
            List<String> clientsDn = resource.getClients();
            List<OxAuthClient> clients = new ArrayList<OxAuthClient>();
            if (clientsDn != null) {
                for (String clientDn : clientsDn) {
                    clients.add(clientService.getClientByDn(clientDn));
                }
            }
            return Response.ok(clients).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) ArrayList(java.util.ArrayList) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation)

Example 8 with UmaResource

use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxTrust by GluuFederation.

the class UmaResourceWebResource method addScopeToUmaResource.

@POST
@Operation(summary = "Add UMA resource scope", description = "add scope to uma resource")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = UmaResource.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@Path(ApiConstants.ID_PARAM_PATH + ApiConstants.SCOPES + ApiConstants.INUM_PARAM_PATH)
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response addScopeToUmaResource(@PathParam(ApiConstants.ID) @NotNull String id, @PathParam(ApiConstants.INUM) @NotNull String scopeInum) {
    log(logger, "Add scope " + scopeInum + " to uma resource " + id);
    try {
        Objects.requireNonNull(id, "Uma id should not be null");
        Objects.requireNonNull(scopeInum, "scope inum should not be null");
        List<UmaResource> resources = umaResourcesService.findResourcesById(id);
        Scope umaScope = scopeDescriptionService.getUmaScopeByInum(scopeInum);
        if (resources != null && !resources.isEmpty() && umaScope != null) {
            UmaResource umaResource = resources.get(0);
            List<String> scopesDn = new ArrayList<String>();
            if (umaResource.getScopes() != null) {
                scopesDn.addAll(umaResource.getScopes());
            }
            scopesDn.add(scopeDescriptionService.getDnForScope(scopeInum));
            umaResource.setScopes(scopesDn);
            umaResourcesService.updateResource(umaResource);
            return Response.ok(umaResourcesService.findResourcesById(id).get(0)).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : Scope(org.oxauth.persistence.model.Scope) ArrayList(java.util.ArrayList) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 9 with UmaResource

use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxTrust by GluuFederation.

the class UmaResourceWebResource method removeClientToUmaResource.

@DELETE
@Operation(summary = "Remove UMA resource client", description = "Remove client from uma resource")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = UmaResource.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@Path(ApiConstants.ID_PARAM_PATH + ApiConstants.CLIENTS + ApiConstants.INUM_PARAM_PATH)
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response removeClientToUmaResource(@PathParam(ApiConstants.ID) @NotNull String id, @PathParam(ApiConstants.INUM) @NotNull String clientInum) {
    try {
        log(logger, "Remove client " + clientInum + " from uma resource " + id);
        Objects.requireNonNull(id, "Uma id should not be null");
        Objects.requireNonNull(clientInum, "Client inum should not be null");
        List<UmaResource> resources = umaResourcesService.findResourcesById(id);
        OxAuthClient client = clientService.getClientByInum(clientInum);
        if (resources != null && !resources.isEmpty() && client != null) {
            UmaResource umaResource = resources.get(0);
            List<String> clientsDn = new ArrayList<String>();
            if (umaResource.getClients() != null) {
                clientsDn.addAll(umaResource.getClients());
            }
            clientsDn.remove(clientService.getDnForClient(clientInum));
            umaResource.setClients(clientsDn);
            umaResourcesService.updateResource(umaResource);
            return Response.ok(umaResourcesService.findResourcesById(id).get(0)).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) ArrayList(java.util.ArrayList) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 10 with UmaResource

use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxTrust by GluuFederation.

the class UmaResourceWebResource method removeScopeToUmaResource.

@DELETE
@Operation(summary = "Remove UMA resource scope", description = "remove a scope from uma resource")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = UmaResource.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@Path(ApiConstants.ID_PARAM_PATH + ApiConstants.SCOPES + ApiConstants.INUM_PARAM_PATH)
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response removeScopeToUmaResource(@PathParam(ApiConstants.ID) @NotNull String id, @PathParam(ApiConstants.INUM) @NotNull String scopeInum) {
    try {
        log(logger, "Remove scope " + scopeInum + " from uma resource " + id);
        Objects.requireNonNull(id, "Uma id should not be null");
        Objects.requireNonNull(scopeInum, "scope inum should not be null");
        List<UmaResource> resources = umaResourcesService.findResourcesById(id);
        Scope umaScope = scopeDescriptionService.getUmaScopeByInum(scopeInum);
        if (resources != null && !resources.isEmpty() && umaScope != null) {
            UmaResource umaResource = resources.get(0);
            List<String> scopesDn = new ArrayList<String>();
            if (umaResource.getScopes() != null) {
                scopesDn.addAll(umaResource.getScopes());
            }
            scopesDn.remove(scopeDescriptionService.getDnForScope(scopeInum));
            umaResource.setScopes(scopesDn);
            umaResourcesService.updateResource(umaResource);
            return Response.ok(umaResourcesService.findResourcesById(id).get(0)).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : Scope(org.oxauth.persistence.model.Scope) ArrayList(java.util.ArrayList) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

UmaResource (org.gluu.oxauth.model.uma.persistence.UmaResource)13 Operation (io.swagger.v3.oas.annotations.Operation)6 ArrayList (java.util.ArrayList)6 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)6 OxAuthClient (org.gluu.oxtrust.model.OxAuthClient)5 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)4 Scope (org.oxauth.persistence.model.Scope)4 BaseComponentTest (org.gluu.oxauth.BaseComponentTest)2 Client (org.gluu.oxauth.model.registration.Client)2 Test (org.testng.annotations.Test)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 DisplayNameEntry (org.gluu.model.DisplayNameEntry)1 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)1 EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)1 Filter (org.gluu.search.filter.Filter)1