Search in sources :

Example 71 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project Singularity by HubSpot.

the class PriorityResource method createPriorityFreeze.

@POST
@Path("/freeze")
@Operation(summary = "Stop scheduling tasks below a certain priority level", responses = { @ApiResponse(responseCode = "200", description = "The priority freeze request was accepted"), @ApiResponse(responseCode = "400", description = "There was a validation error with the priority freeze request") })
public SingularityPriorityFreezeParent createPriorityFreeze(@Parameter(hidden = true) @Auth SingularityUser user, @RequestBody(description = "the new priority freeze to create") SingularityPriorityFreeze priorityFreezeRequest) {
    authorizationHelper.checkAdminAuthorization(user);
    priorityFreezeRequest = singularityValidator.checkSingularityPriorityFreeze(priorityFreezeRequest);
    final SingularityPriorityFreezeParent priorityFreezeRequestParent = new SingularityPriorityFreezeParent(priorityFreezeRequest, System.currentTimeMillis(), user.getEmail());
    priorityManager.createPriorityFreeze(priorityFreezeRequestParent);
    if (priorityFreezeRequest.isKillTasks()) {
        priorityManager.setPriorityKill();
    }
    return priorityFreezeRequestParent;
}
Also used : SingularityPriorityFreezeParent(com.hubspot.singularity.SingularityPriorityFreezeParent) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Operation(io.swagger.v3.oas.annotations.Operation)

Example 72 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project cas by apereo.

the class SSOSamlIdPPostProfileHandlerEndpoint method producePost.

/**
 * Produce response entity.
 *
 * @param request  the request
 * @param response the response
 * @param map      the RequestBody
 * @return the response entity
 */
@PostMapping(produces = MediaType.APPLICATION_XML_VALUE)
@ResponseBody
@Operation(summary = "Produce SAML2 response entity", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "password", required = true), @Parameter(name = SamlProtocolConstants.PARAMETER_ENTITY_ID, required = true), @Parameter(name = "encrypt") })
public ResponseEntity<Object> producePost(final HttpServletRequest request, final HttpServletResponse response, @RequestBody final Map<String, String> map) {
    val username = map.get("username");
    val password = map.get("password");
    val entityId = map.get(SamlProtocolConstants.PARAMETER_ENTITY_ID);
    val encrypt = Boolean.parseBoolean(map.get("encrypt"));
    return produce(request, response, username, password, entityId, encrypt);
}
Also used : lombok.val(lombok.val) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 73 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project cas by apereo.

the class AmazonSecurityTokenServiceEndpoint method fetchCredentials.

/**
 * Fetch credentials.
 *
 * @param duration     the duration
 * @param tokenCode    the token code
 * @param profile      the profile
 * @param serialNumber the serial number
 * @param roleArn      the role arn
 * @param requestBody  the request body
 * @param request      the request
 * @param response     the response
 * @return the map
 */
@PostMapping
@Operation(summary = "Fetch temporary credentials from Amazon Security Token Service", parameters = { @Parameter(name = "duration"), @Parameter(name = "tokenCode"), @Parameter(name = "profile"), @Parameter(name = "serialNumber"), @Parameter(name = "roleArn"), @Parameter(name = "requestBody"), @Parameter(name = "request"), @Parameter(name = "response") })
public ResponseEntity<String> fetchCredentials(@RequestParam(required = false, defaultValue = "PT1H") final String duration, @RequestParam(value = "token", required = false) final String tokenCode, @RequestParam(required = false) final String profile, @RequestParam(required = false) final String serialNumber, @RequestParam(required = false) final String roleArn, @RequestBody final MultiValueMap<String, String> requestBody, final HttpServletRequest request, final HttpServletResponse response) {
    var authenticationResult = (AuthenticationResult) null;
    try {
        authenticationResult = restAuthenticationService.authenticate(requestBody, request, response).orElseThrow(AuthenticationException::new);
    } catch (final Exception e) {
        LoggingUtils.error(LOGGER, e);
        return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Authentication failed");
    }
    val amz = casProperties.getAmazonSts();
    val principal = authenticationResult.getAuthentication().getPrincipal();
    LOGGER.debug("Authenticated principal: [{}]", principal);
    val authz = authorizePrincipal(amz, principal);
    if (authz.isPresent()) {
        return authz.get();
    }
    val credentials = ChainingAWSCredentialsProvider.getInstance(amz.getCredentialAccessKey(), amz.getCredentialSecretKey(), amz.getProfilePath(), StringUtils.defaultString(profile, amz.getProfileName()));
    val builder = StsClient.builder();
    AmazonClientConfigurationBuilder.prepareClientBuilder(builder, credentials, amz);
    val client = builder.build();
    if (amz.isRbacEnabled()) {
        val attributeValues = principal.getAttributes().get(amz.getPrincipalAttributeName());
        LOGGER.debug("Found roles [{}]", attributeValues);
        if (attributeValues.size() > 1) {
            if (StringUtils.isBlank(roleArn)) {
                return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Found multiple roles and none is specified. Current roles: " + attributeValues);
            }
            if (attributeValues.stream().noneMatch(value -> RegexUtils.find(roleArn, value.toString()))) {
                return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Specified role is not allowed. Current roles:" + attributeValues);
            }
        }
        val role = StringUtils.defaultString(roleArn, attributeValues.get(0).toString());
        LOGGER.debug("Using role [{}]", role);
        val roleRequest = AssumeRoleRequest.builder().durationSeconds(Long.valueOf(Beans.newDuration(duration).toSeconds()).intValue()).roleArn(role).roleSessionName(UUID.randomUUID().toString()).serialNumber(serialNumber).tokenCode(tokenCode).build();
        val sessionResult = client.assumeRole(roleRequest);
        val stsCredentials = sessionResult.credentials();
        return createOutputResponse(amz, stsCredentials);
    }
    val sessionTokenRequest = GetSessionTokenRequest.builder().durationSeconds(Long.valueOf(Beans.newDuration(duration).toSeconds()).intValue()).serialNumber(serialNumber).tokenCode(tokenCode).build();
    val sessionResult = client.getSessionToken(sessionTokenRequest);
    val stsCredentials = sessionResult.credentials();
    return createOutputResponse(amz, stsCredentials);
}
Also used : lombok.val(lombok.val) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 74 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project cas by apereo.

the class GoogleAuthenticatorTokenCredentialRepositoryEndpoint method importAccount.

/**
 * Import account.
 *
 * @param request the request
 * @return the http status
 * @throws Exception the exception
 */
@PostMapping(path = "/import", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Import account as a JSON document", parameters = { @Parameter(name = "request") })
public HttpStatus importAccount(final HttpServletRequest request) throws Exception {
    val requestBody = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
    LOGGER.trace("Submitted account: [{}]", requestBody);
    val serializer = new GoogleAuthenticatorAccountSerializer();
    val account = serializer.from(requestBody);
    LOGGER.trace("Storing account: [{}]", account);
    repository.getObject().save(account);
    return HttpStatus.CREATED;
}
Also used : lombok.val(lombok.val) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 75 with RequestBody

use of io.swagger.v3.oas.annotations.parameters.RequestBody in project carbon-apimgt by wso2.

the class OASParserUtil method setReferenceObjectDefinitions.

private static void setReferenceObjectDefinitions(final OpenAPI destOpenAPI, SwaggerUpdateContext context) {
    processReferenceObjectMap(context);
    Components components = destOpenAPI.getComponents();
    Set<Components> aggregatedComponents = context.getAggregatedComponents();
    for (Components sourceComponents : aggregatedComponents) {
        Map<String, Set<String>> referenceObjectMap = context.getReferenceObjectMapping();
        for (Map.Entry<String, Set<String>> refCategoryEntry : referenceObjectMap.entrySet()) {
            String category = refCategoryEntry.getKey();
            if (REQUEST_BODIES.equalsIgnoreCase(category)) {
                Map<String, RequestBody> sourceRequestBodies = sourceComponents.getRequestBodies();
                if (sourceRequestBodies != null) {
                    for (String refKey : refCategoryEntry.getValue()) {
                        RequestBody requestBody = sourceRequestBodies.get(refKey);
                        if (requestBody != null) {
                            components.addRequestBodies(refKey, requestBody);
                        }
                    }
                }
            }
            if (SCHEMAS.equalsIgnoreCase(category)) {
                Map<String, Schema> sourceSchemas = sourceComponents.getSchemas();
                if (sourceSchemas != null) {
                    for (String refKey : refCategoryEntry.getValue()) {
                        Schema schema = sourceSchemas.get(refKey);
                        if (schema != null) {
                            components.addSchemas(refKey, schema);
                        }
                    }
                }
            }
            if (PARAMETERS.equalsIgnoreCase(category)) {
                Map<String, Parameter> parameters = sourceComponents.getParameters();
                if (parameters != null) {
                    for (String refKey : refCategoryEntry.getValue()) {
                        Parameter parameter = parameters.get(refKey);
                        if (parameter != null) {
                            components.addParameters(refKey, parameter);
                        }
                    }
                }
            }
            if (RESPONSES.equalsIgnoreCase(category)) {
                Map<String, ApiResponse> responses = sourceComponents.getResponses();
                if (responses != null) {
                    for (String refKey : refCategoryEntry.getValue()) {
                        ApiResponse response = responses.get(refKey);
                        if (response != null) {
                            components.addResponses(refKey, response);
                        }
                    }
                }
            }
            if (HEADERS.equalsIgnoreCase(category)) {
                Map<String, Header> headers = sourceComponents.getHeaders();
                if (headers != null) {
                    for (String refKey : refCategoryEntry.getValue()) {
                        Header header = headers.get(refKey);
                        if (header != null) {
                            components.addHeaders(refKey, header);
                        }
                    }
                }
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Components(io.swagger.v3.oas.models.Components) Header(io.swagger.v3.oas.models.headers.Header) Parameter(io.swagger.v3.oas.models.parameters.Parameter) RefParameter(io.swagger.models.parameters.RefParameter) Map(java.util.Map) HashMap(java.util.HashMap) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody)

Aggregations

Test (org.testng.annotations.Test)67 OpenAPI (io.swagger.v3.oas.models.OpenAPI)62 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)59 Schema (io.swagger.v3.oas.models.media.Schema)46 Operation (io.swagger.v3.oas.annotations.Operation)41 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)40 MediaType (io.swagger.v3.oas.models.media.MediaType)36 StringSchema (io.swagger.v3.oas.models.media.StringSchema)35 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)32 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)32 Content (io.swagger.v3.oas.models.media.Content)31 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)28 Operation (io.swagger.v3.oas.models.Operation)27 PathItem (io.swagger.v3.oas.models.PathItem)23 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)21 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)19 Parameter (io.swagger.v3.oas.models.parameters.Parameter)15 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)14 Components (io.swagger.v3.oas.models.Components)13 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)12