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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations