use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.
the class ParameterSerializationTest method testReadOnlyParameter.
@Test(description = "should mark a parameter as readOnly")
public void testReadOnlyParameter() throws Exception {
final QueryParameter qp = new QueryParameter();
qp.setSchema(new StringSchema().readOnly(true));
final String json = "{" + " \"in\":\"query\"," + " \"schema\":{" + " \"type\":\"string\"," + " \"readOnly\":true" + " }" + "}";
SerializationMatchers.assertEqualsToJson(qp, json);
}
use of io.swagger.v3.oas.models.parameters.Parameter in project swagger-core by swagger-api.
the class ParameterSerializationTest method serializeIntegerArrayPathParameter.
@Test(description = "it should serialize a PathParameter with integer array")
public void serializeIntegerArrayPathParameter() {
final Parameter p = new PathParameter().schema(new ArraySchema().items(new IntegerSchema()));
final String json = "{\"in\":\"path\",\"required\":true,\"schema\":{\"type\":\"array\",\"items\":{\"type\":\"integer\",\"format\":\"int32\"}}}\n";
SerializationMatchers.assertEqualsToJson(p, json);
}
use of io.swagger.v3.oas.models.parameters.Parameter 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);
}
use of io.swagger.v3.oas.models.parameters.Parameter in project cas by apereo.
the class OidcJwksEndpointController method handleRequestInternal.
/**
* Handle request for jwk set.
*
* @param request the request
* @param response the response
* @param state the state
* @return the jwk set
*/
@GetMapping(value = { '/' + OidcConstants.BASE_OIDC_URL + '/' + OidcConstants.JWKS_URL, "/**/" + OidcConstants.JWKS_URL }, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Produces the collection of keys from the keystore", parameters = { @Parameter(name = "state", description = "Filter keys by their state name", required = false) })
public ResponseEntity<String> handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response, @RequestParam(value = "state", required = false) final String state) {
val webContext = new JEEContext(request, response);
if (!getConfigurationContext().getOidcRequestSupport().isValidIssuerForEndpoint(webContext, OidcConstants.JWKS_URL)) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
try {
val resource = oidcJsonWebKeystoreGeneratorService.generate();
val jsonJwks = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8);
val jsonWebKeySet = new JsonWebKeySet(jsonJwks);
val servicesManager = getConfigurationContext().getServicesManager();
servicesManager.getAllServicesOfType(OidcRegisteredService.class).stream().filter(s -> {
val serviceJwks = SpringExpressionLanguageValueResolver.getInstance().resolve(s.getJwks());
return StringUtils.isNotBlank(serviceJwks);
}).forEach(service -> {
val set = OidcJsonWebKeyStoreUtils.getJsonWebKeySet(service, getConfigurationContext().getApplicationContext(), Optional.empty());
set.ifPresent(keys -> keys.getJsonWebKeys().forEach(jsonWebKeySet::addJsonWebKey));
});
if (StringUtils.isNotBlank(state)) {
jsonWebKeySet.getJsonWebKeys().removeIf(key -> {
val st = OidcJsonWebKeystoreRotationService.JsonWebKeyLifecycleStates.getJsonWebKeyState(key).name();
return !state.equalsIgnoreCase(st);
});
}
val body = jsonWebKeySet.toJson(JsonWebKey.OutputControlLevel.PUBLIC_ONLY);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
return new ResponseEntity<>(body, HttpStatus.OK);
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
return new ResponseEntity<>(StringEscapeUtils.escapeHtml4(e.getMessage()), HttpStatus.BAD_REQUEST);
}
}
use of io.swagger.v3.oas.models.parameters.Parameter in project cas by apereo.
the class SamlRegisteredServiceCachedMetadataEndpoint method getCachedMetadataObject.
/**
* Gets cached metadata object.
*
* @param serviceId the service id
* @param entityId the entity id
* @return the cached metadata object
*/
@ReadOperation
@Operation(summary = "Get SAML2 cached metadata", parameters = { @Parameter(name = "serviceId", required = true), @Parameter(name = "entityId") })
public Map<String, Object> getCachedMetadataObject(final String serviceId, @Nullable final String entityId) {
try {
val registeredService = findRegisteredService(serviceId);
val issuer = StringUtils.defaultIfBlank(entityId, registeredService.getServiceId());
val criteriaSet = new CriteriaSet();
criteriaSet.add(new EntityIdCriterion(issuer));
criteriaSet.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
val metadataResolver = cachingMetadataResolver.resolve(registeredService, criteriaSet);
val iteration = metadataResolver.resolve(criteriaSet).spliterator();
return StreamSupport.stream(iteration, false).map(entity -> Pair.of(entity.getEntityID(), SamlUtils.transformSamlObject(openSamlConfigBean, entity).toString())).collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
return CollectionUtils.wrap("error", e.getMessage());
}
}
Aggregations