Search in sources :

Example 71 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi in project oxTrust by GluuFederation.

the class GluuRadiusClientWebResource method updateRadiusClient.

@PUT
@Operation(summary = "Update existing radius client", description = "Update existing radius client")
@ApiResponses({ @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = RadiusClient.class)), description = "Success"), @ApiResponse(responseCode = "400", description = "Malformed Request. Missing parameter"), @ApiResponse(responseCode = "403", description = "Gluu Radius is not installed"), @ApiResponse(responseCode = "404", description = "Radius client not found"), @ApiResponse(responseCode = "500", description = "Internal server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updateRadiusClient(RadiusClient client) {
    try {
        if (ProductInstallationChecker.isGluuRadiusInstalled() == false)
            return Response.status(Response.Status.FORBIDDEN).build();
        Objects.requireNonNull(client);
        if (client.getInum() == null)
            return Response.status(Response.Status.BAD_REQUEST).entity("Missing radius client inum").build();
        String inum = client.getInum();
        RadiusClient existingclient = gluuRadiusClientService.getRadiusClientByInum(inum);
        if (existingclient == null)
            return Response.status(Response.Status.NOT_FOUND).build();
        if (client.getIpAddress() != null)
            existingclient.setIpAddress(client.getIpAddress());
        if (client.getName() != null)
            existingclient.setName(client.getName());
        if (client.getPriority() != null)
            existingclient.setPriority(client.getPriority());
        if (client.getSecret() != null && !StringUtils.equals(client.getSecret(), existingclient.getSecret())) {
            String encryptedsecret = encryptionService.encrypt(client.getSecret());
            existingclient.setSecret(encryptedsecret);
        }
        gluuRadiusClientService.updateRadiusClient(existingclient);
        return Response.ok(gluuRadiusClientService.getRadiusClientByInum(inum)).build();
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : RadiusClient(org.gluu.radius.model.RadiusClient) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 72 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi in project oxTrust by GluuFederation.

the class GluuRadiusClientWebResource method deleteRadiusClient.

@DELETE
@Operation(summary = "Delete radius client", description = "Deletes a radius client")
@Path(ApiConstants.INUM_PARAM_PATH)
@ApiResponses({ @ApiResponse(responseCode = "204", description = "Success"), @ApiResponse(responseCode = "403", description = "Gluu Radius is not installed"), @ApiResponse(responseCode = "404", description = "Radius client not found"), @ApiResponse(responseCode = "500", description = "Internal server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response deleteRadiusClient(@PathParam(ApiConstants.INUM) @NotNull String inum) {
    try {
        if (ProductInstallationChecker.isGluuRadiusInstalled() == false)
            return Response.status(Response.Status.FORBIDDEN).build();
        RadiusClient client = gluuRadiusClientService.getRadiusClientByInum(inum);
        if (client == null)
            return Response.status(Response.Status.NOT_FOUND).build();
        gluuRadiusClientService.deleteRadiusClient(client);
        return Response.status(Response.Status.NO_CONTENT).build();
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : RadiusClient(org.gluu.radius.model.RadiusClient) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 73 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi in project oxTrust by GluuFederation.

the class BaseUmaProtectionService method getRequestedScopes.

public List<String> getRequestedScopes(ResourceInfo resourceInfo) {
    Class<?> resourceClass = resourceInfo.getResourceClass();
    ProtectedApi typeAnnotation = resourceClass.getAnnotation(ProtectedApi.class);
    List<String> scopes = new ArrayList<String>();
    if (typeAnnotation == null) {
        addMethodScopes(resourceInfo, scopes);
    } else {
        scopes.addAll(Stream.of(typeAnnotation.scopes()).collect(Collectors.toList()));
        addMethodScopes(resourceInfo, scopes);
    }
    return scopes;
}
Also used : ArrayList(java.util.ArrayList) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 74 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi in project oxTrust by GluuFederation.

the class AttributeWebResource method deleteAttribute.

@DELETE
@Path(ApiConstants.INUM_PARAM_PATH)
@Operation(summary = "Delete gluu attribute", description = "Deletes a gluu attribute")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response deleteAttribute(@PathParam(ApiConstants.INUM) @NotNull String inum) {
    log(logger, "Processing deleteAttribute()");
    try {
        Preconditions.checkNotNull(inum);
        GluuAttribute gluuAttribute = attributeService.getAttributeByInum(inum);
        if (gluuAttribute != null) {
            attributeService.removeAttribute(gluuAttribute);
            return Response.ok().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 : GluuAttribute(org.gluu.model.GluuAttribute) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 75 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi in project oxTrust by GluuFederation.

the class AttributeWebResource method updateAttribute.

@PUT
@Operation(summary = "Update new attribute", description = "Updates a gluu attribute")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = GluuAttribute.class)), description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updateAttribute(GluuAttribute gluuAttribute) {
    log(logger, "Processing updateAttribute()");
    try {
        Preconditions.checkNotNull(gluuAttribute, "Attempt to update null attribute");
        String inum = gluuAttribute.getInum();
        GluuAttribute existingAttribute = attributeService.getAttributeByInum(inum);
        if (existingAttribute != null) {
            gluuAttribute.setInum(existingAttribute.getInum());
            attributeService.updateAttribute(gluuAttribute);
            return Response.ok(attributeService.getAttributeByInum(existingAttribute.getInum())).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 : GluuAttribute(org.gluu.model.GluuAttribute) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)75 Operation (io.swagger.v3.oas.annotations.Operation)50 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)47 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Response (javax.ws.rs.core.Response)21 ArrayList (java.util.ArrayList)20 DefaultValue (javax.ws.rs.DefaultValue)20 HeaderParam (javax.ws.rs.HeaderParam)20 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)20 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)19 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)19 ListViewResponse (org.gluu.persist.model.ListViewResponse)19 URI (java.net.URI)17 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)17 Path (javax.ws.rs.Path)16 Consumes (javax.ws.rs.Consumes)11 GluuGroup (org.gluu.oxtrust.model.GluuGroup)10 OxAuthClient (org.gluu.oxtrust.model.OxAuthClient)10 Scope (org.oxauth.persistence.model.Scope)10