Search in sources :

Example 96 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project cas by apereo.

the class CasConfigurationMetadataServerEndpoint method search.

/**
 * Search for property.
 *
 * @param name the name
 * @return the response entity
 */
@ReadOperation
@Operation(summary = "Get all properties from the repository that match the name", parameters = { @Parameter(name = "name", required = true) })
public List<ConfigurationMetadataSearchResult> search(@Selector final String name) {
    val allProps = repository.getRepository().getAllProperties();
    if (StringUtils.isNotBlank(name) && RegexUtils.isValidRegex(name)) {
        val names = StreamSupport.stream(RelaxedPropertyNames.forCamelCase(name).spliterator(), false).map(Object::toString).collect(Collectors.joining("|"));
        val pattern = RegexUtils.createPattern(names);
        return allProps.entrySet().stream().filter(propEntry -> RegexUtils.find(pattern, propEntry.getKey())).map(propEntry -> new ConfigurationMetadataSearchResult(propEntry.getValue(), repository)).sorted().collect(Collectors.toList());
    }
    return new ArrayList<>(0);
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) ConfigurationMetadataProperty(org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty) Collectors(java.util.stream.Collectors) RegexUtils(org.apereo.cas.util.RegexUtils) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) ArrayList(java.util.ArrayList) Parameter(io.swagger.v3.oas.annotations.Parameter) CasConfigurationMetadataRepository(org.apereo.cas.metadata.CasConfigurationMetadataRepository) Operation(io.swagger.v3.oas.annotations.Operation) List(java.util.List) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) RelaxedPropertyNames(org.apereo.cas.configuration.support.RelaxedPropertyNames) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) ArrayList(java.util.ArrayList) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 97 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter 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 98 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter in project cas by apereo.

the class SamlValidateEndpoint method handle.

/**
 * Handle validation request and produce saml1 payload.
 *
 * @param username the username
 * @param password the password
 * @param service  the service
 * @return the map
 */
@ReadOperation
@Operation(summary = "Handle validation request and produce saml1 payload.", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "password", required = true), @Parameter(name = "service", required = true) })
public Map<String, Object> handle(final String username, final String password, final String service) {
    val credential = new UsernamePasswordCredential(username, password);
    val selectedService = this.serviceFactory.createService(service);
    val result = this.authenticationSystemSupport.finalizeAuthenticationTransaction(selectedService, credential);
    val authentication = result.getAuthentication();
    val registeredService = this.servicesManager.findServiceBy(selectedService);
    val audit = AuditableContext.builder().service(selectedService).authentication(authentication).registeredService(registeredService).build();
    val accessResult = registeredServiceAccessStrategyEnforcer.execute(audit);
    accessResult.throwExceptionIfNeeded();
    val principal = authentication.getPrincipal();
    val context = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(registeredService).service(selectedService).principal(principal).build();
    val attributesToRelease = registeredService.getAttributeReleasePolicy().getAttributes(context);
    val principalId = registeredService.getUsernameAttributeProvider().resolveUsername(principal, selectedService, registeredService);
    val modifiedPrincipal = this.principalFactory.createPrincipal(principalId, attributesToRelease);
    val builder = DefaultAuthenticationBuilder.newInstance(authentication);
    builder.setPrincipal(modifiedPrincipal);
    val finalAuthentication = builder.build();
    val samlResponse = this.samlResponseBuilder.createResponse(selectedService.getId(), selectedService);
    samlResponseBuilder.prepareSuccessfulResponse(samlResponse, selectedService, finalAuthentication, principal, finalAuthentication.getAttributes(), principal.getAttributes());
    val resValidation = new LinkedHashMap<String, Object>();
    val encoded = SamlUtils.transformSamlObject(this.openSamlConfigBean, samlResponse).toString();
    resValidation.put(CasViewConstants.MODEL_ATTRIBUTE_NAME_ASSERTION, encoded);
    resValidation.put(CasViewConstants.MODEL_ATTRIBUTE_NAME_SERVICE, selectedService);
    resValidation.put("registeredService", registeredService);
    return resValidation;
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) LinkedHashMap(java.util.LinkedHashMap) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 99 with Parameter

use of io.swagger.v3.oas.models.parameters.Parameter 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)

Aggregations

Parameter (io.swagger.v3.oas.models.parameters.Parameter)48 Test (org.testng.annotations.Test)39 Operation (io.swagger.v3.oas.models.Operation)28 Operation (io.swagger.v3.oas.annotations.Operation)27 lombok.val (lombok.val)26 OpenAPI (io.swagger.v3.oas.models.OpenAPI)20 Map (java.util.Map)17 ArrayList (java.util.ArrayList)16 ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)15 OpenAPI3RequestValidationHandlerImpl (io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl)14 Test (org.junit.Test)14 PathItem (io.swagger.v3.oas.models.PathItem)13 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)13 StringUtils (org.apache.commons.lang3.StringUtils)13 StringSchema (io.swagger.v3.oas.models.media.StringSchema)12 LinkedHashMap (java.util.LinkedHashMap)12 Parameter (io.swagger.v3.oas.annotations.Parameter)11 RequestParameters (io.vertx.ext.web.api.RequestParameters)11 HashMap (java.util.HashMap)11 Schema (io.swagger.v3.oas.models.media.Schema)10