use of org.apereo.cas.adaptors.yubikey.YubiKeyAccount in project cas by apereo.
the class MongoDbYubiKeyAccountRegistry method getAccount.
@Override
public Optional<YubiKeyAccount> getAccount(final String uid) {
final Query query = new Query();
query.addCriteria(Criteria.where("username").is(uid));
final YubiKeyAccount account = this.mongoTemplate.findOne(query, YubiKeyAccount.class, this.collectionName);
if (account != null) {
return Optional.of(new YubiKeyAccount(account.getId(), getCipherExecutor().decode(account.getPublicId()), account.getUsername()));
}
return Optional.empty();
}
use of org.apereo.cas.adaptors.yubikey.YubiKeyAccount in project cas by apereo.
the class YubiKeyAccountRegistryEndpoint method export.
/**
* Export.
*
* @return the response entity
*/
@GetMapping(path = "/export", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
@Operation(summary = "Export all Yubikey accounts as a zip file")
public ResponseEntity<Resource> export() {
val accounts = registry.getObject().getAccounts();
val resource = CompressionUtils.toZipFile(accounts.stream(), Unchecked.function(entry -> {
val acct = (YubiKeyAccount) entry;
val fileName = String.format("%s-%s", acct.getUsername(), acct.getId());
val sourceFile = File.createTempFile(fileName, ".json");
MAPPER.writeValue(sourceFile, acct);
return sourceFile;
}), "yubikeybaccts");
val headers = new HttpHeaders();
headers.setContentDisposition(ContentDisposition.attachment().filename(Objects.requireNonNull(resource.getFilename())).build());
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
}
use of org.apereo.cas.adaptors.yubikey.YubiKeyAccount 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 org.apereo.cas.adaptors.yubikey.YubiKeyAccount in project cas by apereo.
the class JpaYubiKeyAccountRegistry method registerAccountFor.
@Override
public boolean registerAccountFor(final String uid, final String token) {
if (getAccountValidator().isValid(uid, token)) {
final String yubikeyPublicId = getAccountValidator().getTokenPublicId(token);
final YubiKeyAccount account = new YubiKeyAccount();
account.setPublicId(getCipherExecutor().encode(yubikeyPublicId));
account.setUsername(uid);
return this.entityManager.merge(account) != null;
}
return false;
}
use of org.apereo.cas.adaptors.yubikey.YubiKeyAccount in project cas by apereo.
the class MongoDbYubiKeyAccountRegistry method registerAccountFor.
@Override
public boolean registerAccountFor(final String uid, final String token) {
if (getAccountValidator().isValid(uid, token)) {
final String yubikeyPublicId = getAccountValidator().getTokenPublicId(token);
final YubiKeyAccount account = new YubiKeyAccount();
account.setPublicId(getCipherExecutor().encode(yubikeyPublicId));
account.setUsername(uid);
this.mongoTemplate.save(account, this.collectionName);
return true;
}
return false;
}
Aggregations