Search in sources :

Example 26 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project oxTrust by GluuFederation.

the class GluuRadiusConfigWebResource method updateServerConfiguration.

@PUT
@Operation(summary = "Get Radius Server Configuration", description = "Update Radius Server Configuration")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ServerConfiguration.class)), description = "Success"), @ApiResponse(responseCode = "403", description = "Gluu Radius is not installed"), @ApiResponse(responseCode = "404", description = "Gluu Radius configuration not found"), @ApiResponse(responseCode = "500", description = "Internal server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updateServerConfiguration(ServerConfiguration newConfig) {
    log(logger, "Update radius server configuration");
    try {
        if (ProductInstallationChecker.isGluuRadiusInstalled() == false)
            return Response.status(Response.Status.FORBIDDEN).build();
        Objects.requireNonNull(newConfig);
        ServerConfiguration oldConfig = gluuRadiusConfigService.getServerConfiguration();
        if (oldConfig == null)
            return Response.status(Response.Status.NOT_FOUND).build();
        if (newConfig.getListenInterface() == null)
            newConfig.setListenInterface(oldConfig.getListenInterface());
        if (newConfig.getAuthPort() == null)
            newConfig.setAuthPort(oldConfig.getAuthPort());
        if (newConfig.getAcctPort() == null)
            newConfig.setAcctPort(oldConfig.getAcctPort());
        if (newConfig.getOpenidBaseUrl() == null)
            newConfig.setOpenidBaseUrl(oldConfig.getOpenidBaseUrl());
        if (newConfig.getOpenidUsername() == null) {
            newConfig.setOpenidUsername(oldConfig.getOpenidUsername());
            newConfig.setOpenidPassword(oldConfig.getOpenidPassword());
        } else {
            OxAuthClient client = clientService.getClientByInum(newConfig.getOpenidUsername());
            if (client == null) {
                newConfig.setOpenidUsername(oldConfig.getOpenidUsername());
                newConfig.setOpenidPassword(oldConfig.getOpenidPassword());
            } else {
                newConfig.setOpenidPassword(client.getEncodedClientSecret());
            }
        }
        String acrValue = newConfig.getAcrValue();
        if (acrValue == null || (acrValue != null && !isValidAcrValue(acrValue)))
            newConfig.setAcrValue(oldConfig.getAcrValue());
        List<String> scopes = newConfig.getScopes();
        if (scopes == null || (scopes != null && scopes.isEmpty()))
            newConfig.setScopes(oldConfig.getScopes());
        else {
            List<String> newscopes = scopes;
            for (String scope : scopes) {
                // if just one scope is invalid , use the old ones (safe)
                if (!isValidScope(scope)) {
                    newscopes = oldConfig.getScopes();
                    break;
                }
            }
            newConfig.setScopes(newscopes);
        }
        if (newConfig.getAuthenticationTimeout() == null || newConfig.getAuthenticationTimeout() <= 0)
            newConfig.setAuthenticationTimeout(oldConfig.getAuthenticationTimeout());
        gluuRadiusConfigService.updateServerConfiguration(newConfig);
        return Response.ok(gluuRadiusConfigService.getServerConfiguration()).build();
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) ServerConfiguration(org.gluu.radius.model.ServerConfiguration) 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)

Example 27 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project oxTrust by GluuFederation.

the class CasProtocolWebResource method update.

@PUT
@Operation(summary = "Update the configuration", description = "Update the configuration")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = CasProtocolDTO.class)), description = "Success") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response update(@Valid CasProtocolDTO casProtocol) {
    log(logger, "Update the configuration");
    try {
        CASProtocolConfiguration casProtocolConfiguration = casProtocolDtoAssembly.fromDto(casProtocol);
        casProtocolConfiguration.save(casService);
        shibbolethService.update(casProtocolConfiguration);
        return getCasConfig();
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : CASProtocolConfiguration(org.gluu.oxtrust.util.CASProtocolConfiguration) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 28 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project oxTrust by GluuFederation.

the class CasProtocolWebResource method getCasConfig.

@GET
@Operation(summary = "Get existing configuration", description = "Get the existing configuration")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = CasProtocolDTO.class)), description = "Success") })
@ProtectedApi(scopes = { READ_ACCESS })
public Response getCasConfig() {
    log(logger, "Get the existing cas configuration");
    try {
        CASProtocolConfiguration casProtocolConfiguration = casProtocolConfigurationProvider.get();
        CasProtocolDTO casProtocolDto = casProtocolDtoAssembly.toDto(casProtocolConfiguration);
        return Response.ok(casProtocolDto).build();
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : CASProtocolConfiguration(org.gluu.oxtrust.util.CASProtocolConfiguration) CasProtocolDTO(org.gluu.oxtrust.api.server.model.CasProtocolDTO) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 29 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project oxTrust by GluuFederation.

the class ClientWebResource method addScopeToClient.

@POST
@Path(ApiConstants.INUM_PARAM_PATH + ApiConstants.SCOPES + ApiConstants.SCOPE_INUM_PARAM_PATH)
@Operation(summary = "Add OIDC client scopes", description = "Add scopes to OIDC client")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = Scope[].class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response addScopeToClient(@PathParam(ApiConstants.INUM) @NotNull String inum, @PathParam(ApiConstants.SCOPE_INUM) @NotNull String sinum) {
    log(logger, "add new scope to client");
    try {
        OxAuthClient client = clientService.getClientByInum(inum);
        Scope scope = scopeService.getScopeByInum(sinum);
        Objects.requireNonNull(client);
        Objects.requireNonNull(scope);
        if (client != null && scope != null) {
            List<String> scopes = new ArrayList<String>(client.getOxAuthScopes());
            String scopeBaseDn = scopeService.getDnForScope(scope.getInum());
            scopes.remove(scopeBaseDn);
            scopes.add(scopeBaseDn);
            client.setOxAuthScopes(scopes);
            clientService.updateClient(client);
            return Response.ok(scopes).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) OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) ArrayList(java.util.ArrayList) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 30 with ApiResponses

use of io.swagger.v3.oas.models.responses.ApiResponses in project oxTrust by GluuFederation.

the class ClientWebResource method getClientByInum.

@GET
@Path(ApiConstants.INUM_PARAM_PATH)
@Operation(summary = "Get OIDC client", description = "Get a specific OIDC client")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = OxAuthClient.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { READ_ACCESS })
public Response getClientByInum(@PathParam(ApiConstants.INUM) @NotNull String inum) {
    log(logger, "Get client " + inum);
    try {
        Objects.requireNonNull(inum);
        OxAuthClient client = clientService.getClientByInum(inum);
        if (client != null) {
            return Response.ok(client).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) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)99 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)48 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)47 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)47 Operation (io.swagger.v3.oas.models.Operation)39 PathItem (io.swagger.v3.oas.models.PathItem)35 OpenAPI (io.swagger.v3.oas.models.OpenAPI)34 Test (org.testng.annotations.Test)31 ArrayList (java.util.ArrayList)23 Schema (io.swagger.v3.oas.models.media.Schema)22 Content (io.swagger.v3.oas.models.media.Content)21 StringSchema (io.swagger.v3.oas.models.media.StringSchema)21 MediaType (io.swagger.v3.oas.models.media.MediaType)20 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)19 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)17 Path (javax.ws.rs.Path)17 Produces (javax.ws.rs.Produces)17 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)16 Components (io.swagger.v3.oas.models.Components)10