use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class ProfileControllerTest method create_test.
@Test
@WithAnonymousUser
public void create_test() throws Exception {
ProfileCreateForm userCreateForm = new ProfileCreateForm();
userCreateForm.setUserHandle("ORZClsZpTvWrYGl7mXL5Wg");
userCreateForm.setFirstName("John");
userCreateForm.setLastName("Doe");
userCreateForm.setEmailAddress("john.doe@example.com");
userCreateForm.setPassword("password");
userCreateForm.setAuthenticators(Collections.emptyList());
userCreateForm.setSingleFactorAuthenticationAllowed(true);
UserEntity userEntity = new UserEntity();
userEntity.setId(1);
userEntity.setUserHandle(Base64UrlUtil.decode("ORZClsZpTvWrYGl7mXL5Wg"));
userEntity.setFirstName("John");
userEntity.setLastName("Doe");
userEntity.setEmailAddress("john.doe@example.com");
userEntity.setAuthenticators(Collections.emptyList());
userEntity.setAuthorities(Collections.singletonList(new AuthorityEntity(0, "SINGLE_FACTOR_AUTHN_ALLOWED")));
when(profileAppService.create(any())).thenReturn(userEntity);
// When
mvc.perform(post("/api/profile").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(userCreateForm)).with(SecurityMockMvcRequestPostProcessors.csrf())).andExpect(status().isOk()).andExpect(jsonPath("$.id", is(1))).andExpect(jsonPath("$.userHandle", is("ORZClsZpTvWrYGl7mXL5Wg"))).andExpect(jsonPath("$.firstName", is("John"))).andExpect(jsonPath("$.lastName", is("Doe"))).andExpect(jsonPath("$.emailAddress", is("john.doe@example.com"))).andExpect(jsonPath("$.authenticators", is(empty()))).andExpect(jsonPath("$.singleFactorAuthenticationAllowed", is(true)));
verify(profileAppService).create(any());
}
use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class PublicKeyCredentialUserEntityProviderImpl method provide.
@Override
public PublicKeyCredentialUserEntity provide(Authentication authentication) {
if (authentication == null) {
return null;
}
String username = authentication.getName();
UserEntity userEntity = userManager.loadUserByUsername(username);
return new PublicKeyCredentialUserEntity(userEntity.getUserHandle(), userEntity.getUsername(), userEntity.getUsername());
}
use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class UserManagerImpl method updateUser.
/**
* {@inheritDoc}
*/
@Override
public void updateUser(UserEntity user) {
UserEntity userEntity = userEntityRepository.findById(user.getId()).orElseThrow(() -> new WebAuthnSampleEntityNotFoundException("User not found"));
userEntityRepository.save(userEntity);
}
use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class UserManagerImpl method changePassword.
/**
* {@inheritDoc}
*/
@Override
public void changePassword(String oldPassword, String newPassword) {
UserEntity currentUserEntity = getCurrentUser();
if (currentUserEntity == null) {
// This would indicate bad coding somewhere
throw new AccessDeniedException("Can't change rawPassword as no Authentication object found in context " + "for current user.");
}
currentUserEntity.setPassword(newPassword);
}
use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class AppSpecificMapper method mapForCreate.
public UserEntity mapForCreate(ProfileCreateForm profileCreateForm) {
UserEntity userEntity = new UserEntity();
userEntity.setId(null);
userEntity.setUserHandle(mapFromBase64Url(profileCreateForm.getUserHandle()));
userEntity.setFirstName(profileCreateForm.getFirstName());
userEntity.setLastName(profileCreateForm.getLastName());
userEntity.setEmailAddress(profileCreateForm.getEmailAddress());
userEntity.setPassword(passwordEncoder.encode(profileCreateForm.getPassword()));
// authenticators
userEntity.setAuthenticators(new ArrayList<>());
mapToAuthenticatorListForCreate(profileCreateForm.getAuthenticators(), userEntity.getAuthenticators());
userEntity.getAuthenticators().forEach(authenticatorEntity -> authenticatorEntity.setUser(userEntity));
// authorities
List<AuthorityEntity> authorities = new ArrayList<>();
if (profileCreateForm.isSingleFactorAuthenticationAllowed() == true) {
authorities.add(new AuthorityEntity(null, "SINGLE_FACTOR_AUTHN_ALLOWED"));
}
userEntity.setAuthorities(authorities);
return userEntity;
}
Aggregations