Search in sources :

Example 41 with Parameter

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

the class U2FRegisteredDevicesEndpoint method delete.

/**
 * Delete.
 *
 * @param username the username
 */
@DeleteOperation
@Operation(summary = "Delete all registered devices", parameters = { @Parameter(name = "username", required = true) })
public void delete(@Selector final String username) {
    val registeredDevices = new ArrayList<>(u2fDeviceRepository.getObject().getRegisteredDevices(username));
    registeredDevices.forEach(u2fDeviceRepository.getObject()::deleteRegisteredDevice);
}
Also used : lombok.val(lombok.val) ArrayList(java.util.ArrayList) DeleteOperation(org.springframework.boot.actuate.endpoint.annotation.DeleteOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) DeleteOperation(org.springframework.boot.actuate.endpoint.annotation.DeleteOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 42 with Parameter

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

the class WebAuthnRegisteredDevicesEndpoint method delete.

/**
 * Delete.
 *
 * @param username     the username
 * @param credentialId the credential id
 * @throws Exception the exception
 */
@Operation(summary = "Remove device registration for username and credential id", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "credentialId", required = true) })
@DeleteMapping(path = "{username}/{credentialId}", produces = MediaType.APPLICATION_JSON_VALUE)
public void delete(@PathVariable final String username, @PathVariable final String credentialId) throws Exception {
    val ba = ByteArray.fromBase64Url(credentialId);
    registrationStorage.getObject().getRegistrationByUsernameAndCredentialId(username, ba).ifPresent(registration -> registrationStorage.getObject().removeRegistrationByUsername(username, registration));
}
Also used : lombok.val(lombok.val) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 43 with Parameter

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

the class WebAuthnRegisteredDevicesEndpoint method write.

/**
 * Write.
 *
 * @param username the username
 * @param record   the record
 * @return the boolean
 * @throws Exception the exception
 */
@PostMapping(path = "{username}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Add device registration for username", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "record", required = true) })
public boolean write(@PathVariable final String username, @RequestParam final String record) throws Exception {
    val json = EncodingUtils.decodeBase64ToString(record);
    val registration = WebAuthnUtils.getObjectMapper().readValue(json, CredentialRegistration.class);
    return registrationStorage.getObject().addRegistrationByUsername(username, registration);
}
Also used : lombok.val(lombok.val) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 44 with Parameter

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

the class DuoSecurityAdminApiEndpoint method getUser.

/**
 * Fetch duo user account from admin api.
 *
 * @param username   the username
 * @param providerId the provider id
 * @return the map
 */
@GetMapping(path = "/{username}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Fetch Duo Security user account from Duo Admin API", parameters = { @Parameter(name = "username", required = true, in = ParameterIn.PATH), @Parameter(name = "providerId") })
public Map<String, DuoSecurityUserAccount> getUser(@PathVariable("username") final String username, @RequestParam(required = false) final String providerId) {
    val results = new LinkedHashMap<String, DuoSecurityUserAccount>();
    val providers = applicationContext.getBeansOfType(DuoSecurityMultifactorAuthenticationProvider.class).values();
    providers.stream().filter(Objects::nonNull).map(DuoSecurityMultifactorAuthenticationProvider.class::cast).filter(provider -> StringUtils.isBlank(providerId) || provider.matches(providerId)).filter(provider -> provider.getDuoAuthenticationService().getAdminApiService().isPresent()).forEach(Unchecked.consumer(p -> {
        val duoService = p.getDuoAuthenticationService().getAdminApiService().get();
        duoService.getDuoSecurityUserAccount(username).ifPresent(user -> results.put(p.getId(), user));
    }));
    return results;
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) PathVariable(org.springframework.web.bind.annotation.PathVariable) PostMapping(org.springframework.web.bind.annotation.PostMapping) RequestParam(org.springframework.web.bind.annotation.RequestParam) Unchecked(org.jooq.lambda.Unchecked) MediaType(org.springframework.http.MediaType) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) ApplicationContext(org.springframework.context.ApplicationContext) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) ParameterIn(io.swagger.v3.oas.annotations.enums.ParameterIn) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) RestControllerEndpoint(org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint) LinkedHashMap(java.util.LinkedHashMap) Objects(java.util.Objects) Operation(io.swagger.v3.oas.annotations.Operation) List(java.util.List) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) DuoSecurityUserAccount(org.apereo.cas.adaptors.duo.DuoSecurityUserAccount) Objects(java.util.Objects) LinkedHashMap(java.util.LinkedHashMap) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 45 with Parameter

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

the class DuoSecurityAdminApiEndpoint method createBypassCodes.

/**
 * Create bypass codes.
 *
 * @param username   the username
 * @param providerId the provider id
 * @param userId     the user id
 * @return the map
 */
@Operation(summary = "Create bypass codes using Duo Admin API", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "providerId"), @Parameter(name = "userId") })
@PostMapping(path = "/bypassCodes", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, List<Long>> createBypassCodes(@RequestParam(value = "username", required = false) final String username, @RequestParam(value = "providerId", required = false) final String providerId, @RequestParam(value = "userId", required = false) final String userId) {
    val results = new LinkedHashMap<String, List<Long>>();
    val providers = applicationContext.getBeansOfType(DuoSecurityMultifactorAuthenticationProvider.class).values();
    providers.stream().filter(Objects::nonNull).map(DuoSecurityMultifactorAuthenticationProvider.class::cast).filter(provider -> StringUtils.isBlank(providerId) || provider.matches(providerId)).filter(provider -> provider.getDuoAuthenticationService().getAdminApiService().isPresent()).forEach(Unchecked.consumer(p -> {
        val duoService = p.getDuoAuthenticationService().getAdminApiService().get();
        val uid = StringUtils.isBlank(userId) ? duoService.getDuoSecurityUserAccount(username).map(DuoSecurityUserAccount::getUserId).orElse(StringUtils.EMPTY) : userId;
        if (StringUtils.isNotBlank(uid)) {
            val codes = duoService.createDuoSecurityBypassCodesFor(uid);
            results.put(p.getId(), codes);
        }
    }));
    return results;
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) PathVariable(org.springframework.web.bind.annotation.PathVariable) PostMapping(org.springframework.web.bind.annotation.PostMapping) RequestParam(org.springframework.web.bind.annotation.RequestParam) Unchecked(org.jooq.lambda.Unchecked) MediaType(org.springframework.http.MediaType) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) ApplicationContext(org.springframework.context.ApplicationContext) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) ParameterIn(io.swagger.v3.oas.annotations.enums.ParameterIn) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) RestControllerEndpoint(org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint) LinkedHashMap(java.util.LinkedHashMap) Objects(java.util.Objects) Operation(io.swagger.v3.oas.annotations.Operation) List(java.util.List) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) DuoSecurityUserAccount(org.apereo.cas.adaptors.duo.DuoSecurityUserAccount) Objects(java.util.Objects) LinkedHashMap(java.util.LinkedHashMap) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)59 Parameter (io.swagger.v3.oas.models.parameters.Parameter)48 Test (org.testng.annotations.Test)39 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)33 Operation (io.swagger.v3.oas.models.Operation)28 lombok.val (lombok.val)26 OpenAPI (io.swagger.v3.oas.models.OpenAPI)20 Map (java.util.Map)18 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 Parameter (io.swagger.v3.oas.annotations.Parameter)12 StringSchema (io.swagger.v3.oas.models.media.StringSchema)12 LinkedHashMap (java.util.LinkedHashMap)12 RequestParameters (io.vertx.ext.web.api.RequestParameters)11 HashMap (java.util.HashMap)11