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;
}
use of io.swagger.v3.oas.models.Operation in project cas by apereo.
the class CasServerDiscoveryProfileEndpoint method discovery.
/**
* Discovery.
*
* @return the map
*/
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@Operation(summary = "Produce CAS discovery profile")
public Map<String, Object> discovery() {
val results = new HashMap<String, Object>();
results.put("profile", casServerProfileRegistrar.getProfile());
return results;
}
Aggregations