Search in sources :

Example 41 with Operation

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

the class YubiKeyAccountRegistryEndpoint method importAccount.

/**
 * Import account.
 *
 * @param request the request
 * @return the http status
 * @throws Exception the exception
 */
@Operation(summary = "Import a Yubikey account as a JSON document")
@PostMapping(path = "/import", consumes = MediaType.APPLICATION_JSON_VALUE)
public HttpStatus importAccount(final HttpServletRequest request) throws Exception {
    val requestBody = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
    LOGGER.trace("Submitted account: [{}]", requestBody);
    val account = MAPPER.readValue(requestBody, new TypeReference<YubiKeyAccount>() {
    });
    LOGGER.trace("Storing account: [{}]", account);
    registry.getObject().save(account);
    return HttpStatus.CREATED;
}
Also used : lombok.val(lombok.val) YubiKeyAccount(org.apereo.cas.adaptors.yubikey.YubiKeyAccount) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 42 with Operation

use of io.swagger.v3.oas.models.Operation 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 43 with Operation

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

Example 44 with Operation

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

the class DuoSecurityPingEndpoint method pingDuo.

/**
 * Ping duo and return availability result.
 *
 * @param providerId the provider id, if any.
 * @return the map
 */
@ReadOperation(produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Ping Duo Security given the provider id", parameters = { @Parameter(name = "providerId") })
public Map<?, ?> pingDuo(@Nullable final String providerId) {
    val resolver = SpringExpressionLanguageValueResolver.getInstance();
    val results = new LinkedHashMap<>();
    val providers = applicationContext.getBeansOfType(DuoSecurityMultifactorAuthenticationProvider.class).values();
    providers.stream().filter(Objects::nonNull).map(DuoSecurityMultifactorAuthenticationProvider.class::cast).filter(provider -> StringUtils.isBlank(providerId) || provider.matches(providerId)).forEach(p -> {
        val duoService = p.getDuoAuthenticationService();
        val available = duoService.ping();
        results.put(p.getId(), CollectionUtils.wrap("duoApiHost", resolver.resolve(duoService.getProperties().getDuoApiHost()), "name", p.getFriendlyName(), "availability", available));
    });
    return results;
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) 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) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) LinkedHashMap(java.util.LinkedHashMap) Objects(java.util.Objects) Operation(io.swagger.v3.oas.annotations.Operation) SpringExpressionLanguageValueResolver(org.apereo.cas.util.spring.SpringExpressionLanguageValueResolver) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Nullable(org.springframework.lang.Nullable) 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 45 with Operation

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

the class DuoSecurityUserAccountStatusEndpoint method fetchAccountStatus.

/**
 * Fetch account status map.
 *
 * @param username   the username
 * @param providerId the provider id
 * @return the map
 */
@ReadOperation(produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Fetch Duo Security user account status", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "providerId") })
public Map<?, ?> fetchAccountStatus(@Selector final String username, @Nullable final String providerId) {
    val resolver = SpringExpressionLanguageValueResolver.getInstance();
    val results = new LinkedHashMap<>();
    val providers = applicationContext.getBeansOfType(DuoSecurityMultifactorAuthenticationProvider.class).values();
    providers.stream().filter(Objects::nonNull).map(DuoSecurityMultifactorAuthenticationProvider.class::cast).filter(provider -> StringUtils.isBlank(providerId) || provider.matches(providerId)).forEach(p -> {
        val duoService = p.getDuoAuthenticationService();
        val accountStatus = duoService.getUserAccount(username);
        results.put(p.getId(), CollectionUtils.wrap("duoApiHost", resolver.resolve(duoService.getProperties().getDuoApiHost()), "name", p.getFriendlyName(), "accountStatus", accountStatus));
    });
    return results;
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) 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) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) Parameter(io.swagger.v3.oas.annotations.Parameter) LinkedHashMap(java.util.LinkedHashMap) Objects(java.util.Objects) Operation(io.swagger.v3.oas.annotations.Operation) SpringExpressionLanguageValueResolver(org.apereo.cas.util.spring.SpringExpressionLanguageValueResolver) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Nullable(org.springframework.lang.Nullable) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) 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)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)151 Operation (io.swagger.v3.oas.models.Operation)108 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 OpenAPI (io.swagger.v3.oas.models.OpenAPI)79 Test (org.testng.annotations.Test)68 PathItem (io.swagger.v3.oas.models.PathItem)53 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)50 ArrayList (java.util.ArrayList)45 lombok.val (lombok.val)42 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)34 Map (java.util.Map)34 HashMap (java.util.HashMap)33 LinkedHashMap (java.util.LinkedHashMap)29 Test (org.junit.Test)29 OpenAPI3RequestValidationHandlerImpl (io.vertx.ext.web.api.contract.openapi3.impl.OpenAPI3RequestValidationHandlerImpl)28 Paths (io.swagger.v3.oas.models.Paths)27 Components (io.swagger.v3.oas.models.Components)26 Schema (io.swagger.v3.oas.models.media.Schema)24 Produces (javax.ws.rs.Produces)21 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)20