use of com.webauthn4j.springframework.security.webauthn.sample.app.api.AuthenticatorForm in project webauthn4j-spring-security by webauthn4j.
the class AppSpecificMapper method mapToAuthenticatorListForUpdate.
private List<AuthenticatorEntity> mapToAuthenticatorListForUpdate(List<AuthenticatorForm> authenticatorForms, List<AuthenticatorEntity> authenticatorEntities) {
int[] sortedKeptIds = authenticatorForms.stream().filter(authenticator -> authenticator.getId() != null).mapToInt(AuthenticatorForm::getId).sorted().toArray();
for (AuthenticatorForm authenticatorForm : authenticatorForms) {
Integer id = authenticatorForm.getId();
// addExtension new authenticator
if (id == null) {
authenticatorEntities.add(mapForCreate(authenticatorForm));
} else // update existing authenticator
{
AuthenticatorEntity correspondingAuthenticatorEntity = authenticatorEntities.stream().filter(item -> item.getId().equals(id)).findFirst().orElseThrow(() -> new WebAuthnSampleEntityNotFoundException("Corresponding authenticator is not found."));
mapForUpdate(authenticatorForm, correspondingAuthenticatorEntity);
}
}
// delete authenticatorEntities if it is not included in authenticatorForms
authenticatorEntities.removeIf(authenticatorEntity -> {
Integer id = authenticatorEntity.getId();
if (id == null) {
return false;
}
return Arrays.binarySearch(sortedKeptIds, id) < 0;
});
return authenticatorEntities;
}
use of com.webauthn4j.springframework.security.webauthn.sample.app.api.AuthenticatorForm in project webauthn4j-spring-security by webauthn4j.
the class AppSpecificMapper method mapToAuthenticatorForm.
private AuthenticatorForm mapToAuthenticatorForm(AuthenticatorEntity authenticatorEntity) {
AuthenticatorForm authenticatorForm = new AuthenticatorForm();
authenticatorForm.setId(authenticatorEntity.getId());
authenticatorForm.setCredentialId(Base64UrlUtil.encodeToString(authenticatorEntity.getAttestedCredentialData().getCredentialId()));
authenticatorForm.setName(authenticatorEntity.getName());
return authenticatorForm;
}
use of com.webauthn4j.springframework.security.webauthn.sample.app.api.AuthenticatorForm in project webauthn4j-spring-security by webauthn4j.
the class AppSpecificMapper method mapForUpdate.
public UserEntity mapForUpdate(ProfileUpdateForm profileUpdateForm, UserEntity userEntity) {
userEntity.setUserHandle(mapFromBase64Url(profileUpdateForm.getUserHandle()));
userEntity.setFirstName(profileUpdateForm.getFirstName());
userEntity.setLastName(profileUpdateForm.getLastName());
userEntity.setEmailAddress(profileUpdateForm.getEmailAddress());
// authenticators
List<AuthenticatorForm> authenticatorForms = profileUpdateForm.getAuthenticators();
mapToAuthenticatorListForUpdate(authenticatorForms, userEntity.getAuthenticators());
userEntity.getAuthenticators().forEach(authenticatorEntity -> authenticatorEntity.setUser(userEntity));
// authorities
List<AuthorityEntity> authorities = userEntity.getAuthorities();
if (profileUpdateForm.isSingleFactorAuthenticationAllowed() == true) {
if (authorities.stream().anyMatch(authorityEntity -> authorityEntity.getAuthority().equals("SINGLE_FACTOR_AUTHN_ALLOWED"))) {
// nop
} else {
authorities.add(new AuthorityEntity(null, "SINGLE_FACTOR_AUTHN_ALLOWED"));
}
} else {
authorities.clear();
}
return userEntity;
}
Aggregations