use of io.jans.fido2.model.entry.Fido2RegistrationEntry in project jans by JanssenProject.
the class AssertionService method prepareAllowedCredentials.
private Pair<ArrayNode, String> prepareAllowedCredentials(String documentDomain, String username) {
// TODO: Add property to enable/disable U2F -> Fido2 migration
List<DeviceRegistration> existingFidoRegistrations = deviceRegistrationService.findAllRegisteredByUsername(username, documentDomain);
if (existingFidoRegistrations.size() > 0) {
deviceRegistrationService.migrateToFido2(existingFidoRegistrations, documentDomain, username);
}
List<Fido2RegistrationEntry> existingFido2Registrations = registrationPersistenceService.findAllRegisteredByUsername(username);
List<Fido2RegistrationEntry> allowedFido2Registrations = existingFido2Registrations.parallelStream().filter(f -> StringHelper.equals(documentDomain, f.getRegistrationData().getDomain())).filter(f -> StringHelper.isNotEmpty(f.getRegistrationData().getPublicKeyId())).collect(Collectors.toList());
allowedFido2Registrations.forEach((value) -> {
log.debug("attestation request:" + value.getRegistrationData().getAttenstationRequest());
});
List<JsonNode> allowedFido2Keys = allowedFido2Registrations.parallelStream().map(f -> dataMapperService.convertValue(new PublicKeyCredentialDescriptor(f.getRegistrationData().getType(), (f.getRegistrationData().getAttestationType().equalsIgnoreCase(AttestationFormat.apple.getFmt()) || f.getRegistrationData().getAttenstationRequest().contains(AuthenticatorAttachment.PLATFORM.getAttachment())) ? new String[] { "internal" } : new String[] { "usb", "ble", "nfc" }, f.getRegistrationData().getPublicKeyId()), JsonNode.class)).collect(Collectors.toList());
Optional<Fido2RegistrationEntry> fidoRegistration = allowedFido2Registrations.parallelStream().filter(f -> StringUtils.isNotEmpty(f.getRegistrationData().getApplicationId())).findAny();
String applicationId = null;
if (fidoRegistration.isPresent()) {
applicationId = fidoRegistration.get().getRegistrationData().getApplicationId();
}
ArrayNode allowedCredentials = dataMapperService.createArrayNode();
allowedCredentials.addAll(allowedFido2Keys);
return Pair.of(allowedCredentials, applicationId);
}
use of io.jans.fido2.model.entry.Fido2RegistrationEntry in project jans by JanssenProject.
the class AttestationService method prepareExcludeCredentials.
private ArrayNode prepareExcludeCredentials(String documentDomain, String username) {
List<Fido2RegistrationEntry> existingRegistrations = registrationPersistenceService.findAllRegisteredByUsername(username);
List<JsonNode> excludedKeys = existingRegistrations.parallelStream().filter(f -> StringHelper.equals(documentDomain, f.getRegistrationData().getDomain())).filter(f -> StringHelper.isNotEmpty(f.getRegistrationData().getPublicKeyId())).map(f -> dataMapperService.convertValue(new PublicKeyCredentialDescriptor(f.getRegistrationData().getType(), new String[] { "usb", "ble", "nfc", "internal" }, f.getRegistrationData().getPublicKeyId()), JsonNode.class)).collect(Collectors.toList());
ArrayNode excludedCredentials = dataMapperService.createArrayNode();
excludedCredentials.addAll(excludedKeys);
return excludedCredentials;
}
use of io.jans.fido2.model.entry.Fido2RegistrationEntry in project jans by JanssenProject.
the class RegistrationPersistenceService method findAllByUsername.
public List<Fido2RegistrationEntry> findAllByUsername(String username) {
String userInum = userService.getUserInum(username);
if (userInum == null) {
return Collections.emptyList();
}
String baseDn = getBaseDnForFido2RegistrationEntries(userInum);
if (persistenceEntryManager.hasBranchesSupport(baseDn)) {
if (!containsBranch(baseDn)) {
return Collections.emptyList();
}
}
Filter userFilter = Filter.createEqualityFilter("personInum", userInum);
List<Fido2RegistrationEntry> fido2RegistrationnEntries = persistenceEntryManager.findEntries(baseDn, Fido2RegistrationEntry.class, userFilter);
return fido2RegistrationnEntries;
}
use of io.jans.fido2.model.entry.Fido2RegistrationEntry in project jans by JanssenProject.
the class RegistrationPersistenceService method update.
public void update(Fido2RegistrationEntry registrationEntry) {
Date now = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTime();
Fido2RegistrationData registrationData = registrationEntry.getRegistrationData();
registrationData.setUpdatedDate(now);
registrationData.setUpdatedBy(registrationData.getUsername());
registrationEntry.setPublicKeyId(registrationData.getPublicKeyId());
registrationEntry.setRegistrationStatus(registrationData.getStatus());
persistenceEntryManager.merge(registrationEntry);
}
use of io.jans.fido2.model.entry.Fido2RegistrationEntry in project jans by JanssenProject.
the class RegistrationPersistenceService method findByChallenge.
public List<Fido2RegistrationEntry> findByChallenge(String challenge) {
String baseDn = getBaseDnForFido2RegistrationEntries(null);
Filter codeChallengFilter = Filter.createEqualityFilter("jansCodeChallenge", challenge);
Filter codeChallengHashCodeFilter = Filter.createEqualityFilter("jansCodeChallengeHash", String.valueOf(getChallengeHashCode(challenge)));
Filter filter = Filter.createANDFilter(codeChallengFilter, codeChallengHashCodeFilter);
List<Fido2RegistrationEntry> fido2RegistrationnEntries = persistenceEntryManager.findEntries(baseDn, Fido2RegistrationEntry.class, filter);
return fido2RegistrationnEntries;
}
Aggregations