Search in sources :

Example 26 with ApiResponses

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

the class OxTrustJsonSettingWebResource method getOxtrustJsonSettings.

@GET
@Operation(summary = "Get json oxtrust settings", description = "Get json oxtrust settings")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = OxTrustJsonSetting.class)), description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { READ_ACCESS })
public Response getOxtrustJsonSettings() {
    try {
        log(logger, "Processing oxtrust json settings retrival");
        this.oxTrustappConfiguration = jsonConfigurationService.getOxTrustappConfiguration();
        OxTrustJsonSetting setting = new OxTrustJsonSetting();
        setting.setOrgName(this.oxTrustappConfiguration.getOrganizationName());
        setting.setSupportEmail(this.oxTrustappConfiguration.getOrgSupportEmail());
        setting.setAuthenticationRecaptchaEnabled(this.oxTrustappConfiguration.isAuthenticationRecaptchaEnabled());
        setting.setCleanServiceInterval(this.oxTrustappConfiguration.getCleanServiceInterval());
        setting.setEnforceEmailUniqueness(this.oxTrustappConfiguration.getEnforceEmailUniqueness());
        setting.setPasswordResetRequestExpirationTime(this.oxTrustappConfiguration.getPasswordResetRequestExpirationTime());
        setting.setLoggingLevel(this.oxTrustappConfiguration.getLoggingLevel());
        return Response.ok(setting).build();
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : OxTrustJsonSetting(org.gluu.oxtrust.api.server.model.OxTrustJsonSetting) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 27 with ApiResponses

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

the class PeopleWebResource method getPersonByInum.

@GET
@Path(ApiConstants.INUM_PARAM_PATH)
@Operation(summary = "Get person by inum", description = "Get a person by inum")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = GluuPersonApi.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { READ_ACCESS })
public Response getPersonByInum(@PathParam(ApiConstants.INUM) @NotNull String inum) {
    log(logger, "Get person " + inum);
    try {
        Objects.requireNonNull(inum, "inum should not be null");
        GluuCustomPerson person = personService.getPersonByInum(inum);
        if (person != null) {
            return Response.ok(convert(Arrays.asList(person)).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 : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) 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.annotations.responses.ApiResponses 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 29 with ApiResponses

use of io.swagger.v3.oas.annotations.responses.ApiResponses 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 30 with ApiResponses

use of io.swagger.v3.oas.annotations.responses.ApiResponses in project carbon-apimgt by wso2.

the class RestApiCommonUtil method generateOpenAPIForAsync.

/**
 * Generate a basic OpenAPI definition with given details.
 *
 * @param name             name of the API.
 * @param version          version of the API.
 * @param context          context of the API.
 * @param callbackEndpoint callback URL of the async API.
 * @return OpenAPI definition as String.
 * @throws JsonProcessingException Error occurred while generating the OpenAPI.
 */
public static String generateOpenAPIForAsync(String name, String version, String context, String callbackEndpoint) throws JsonProcessingException {
    OpenAPI openAPI = new OpenAPI();
    Info info = new Info();
    info.setTitle(name);
    info.setDescription("API Definition of " + name);
    info.setVersion(version);
    openAPI.setInfo(info);
    ArrayList<Server> servers = new ArrayList<>();
    Server server = new Server();
    server.setUrl("/");
    servers.add(server);
    openAPI.setServers(Arrays.asList(server));
    Paths paths = new Paths();
    PathItem pathItem = new PathItem();
    Operation operation = new Operation();
    ApiResponses apiResponses = new ApiResponses();
    ApiResponse apiResponse = new ApiResponse();
    apiResponse.setDescription("Default response");
    apiResponses.addApiResponse("default", apiResponse);
    operation.setResponses(apiResponses);
    pathItem.setPost(operation);
    paths.addPathItem("/*", pathItem);
    openAPI.paths(paths);
    List<String> urls = new ArrayList<>();
    urls.add(callbackEndpoint);
    Map<String, Object> tempMap = new HashMap();
    tempMap.put("type", "http");
    tempMap.put("urls", urls);
    openAPI.addExtension(X_WSO2_PRODUCTION_ENDPOINTS, tempMap);
    openAPI.addExtension(X_WSO2_SANDBOX_ENDPOINTS, tempMap);
    openAPI.addExtension(X_WSO2_AUTH_HEADER, "Authorization");
    openAPI.addExtension(X_WSO2_BASEPATH, context + "/" + version);
    openAPI.addExtension(X_WSO2_DISABLE_SECURITY, true);
    return Json.mapper().writeValueAsString(openAPI);
}
Also used : Server(io.swagger.v3.oas.models.servers.Server) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Operation(io.swagger.v3.oas.models.Operation) Info(io.swagger.v3.oas.models.info.Info) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) PathItem(io.swagger.v3.oas.models.PathItem) Paths(io.swagger.v3.oas.models.Paths) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ApiResponses(io.swagger.v3.oas.models.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)47 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)47 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)46 Operation (io.swagger.v3.oas.models.Operation)39 OpenAPI (io.swagger.v3.oas.models.OpenAPI)34 PathItem (io.swagger.v3.oas.models.PathItem)34 Test (org.testng.annotations.Test)31 ArrayList (java.util.ArrayList)23 Schema (io.swagger.v3.oas.models.media.Schema)22 StringSchema (io.swagger.v3.oas.models.media.StringSchema)21 Content (io.swagger.v3.oas.models.media.Content)20 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