use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class UserManagerImpl method deleteUser.
/**
* {@inheritDoc}
*/
@Override
public void deleteUser(String username) {
UserEntity userEntity = userEntityRepository.findOneByEmailAddress(username).orElseThrow(() -> new PrincipalNotFoundException(String.format("UserEntity with username'%s' is not found.", username)));
userEntityRepository.delete(userEntity);
}
use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class AuthorityServiceImpl method update.
@Override
public AuthorityEntity update(AuthorityUpdateDto authorityUpdateDto) {
AuthorityEntity retrievedAuthorityEntity = authorityEntityRepository.findById(authorityUpdateDto.getId()).orElseThrow(() -> new WebAuthnSampleEntityNotFoundException("Authority not found."));
List<UserEntity> userEntityList = userEntityRepository.findAllById(authorityUpdateDto.getUsers());
List<GroupEntity> groupEntityList = groupEntityRepository.findAllById(authorityUpdateDto.getGroups());
retrievedAuthorityEntity.setUsers(userEntityList);
retrievedAuthorityEntity.setGroups(groupEntityList);
return retrievedAuthorityEntity;
}
use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class UserServiceImpl method update.
/**
* {@inheritDoc}
*/
@Override
public UserEntity update(int id, Consumer<UserEntity> consumer) {
UserEntity userEntity = findOne(id);
consumer.accept(userEntity);
userManager.updateUser(userEntity);
return userEntity;
}
use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class ProfileControllerTest method show_test.
@Test
@WithMockWebAuthnUser(id = 1, firstName = "John", lastName = "Doe", emailAddress = "john.doe@example.com", authorities = { "ROLE_USER" }, authenticators = {})
public void show_test() throws Exception {
int userId = 1;
UserEntity userEntity = new UserEntity();
userEntity.setUserHandle(new byte[0]);
userEntity.setId(userId);
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.findOne(userId)).thenReturn(userEntity);
// When
mvc.perform(get("/api/profile")).andExpect(status().isOk()).andExpect(jsonPath("$.id", is(1))).andExpect(jsonPath("$.userHandle", is(""))).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)));
}
use of com.webauthn4j.springframework.security.webauthn.sample.domain.entity.UserEntity in project webauthn4j-spring-security by webauthn4j.
the class ProfileControllerTest method update_test.
@Test
@WithMockWebAuthnUser(id = 1, firstName = "John", lastName = "Doe", emailAddress = "john.doe@example.com", authorities = { "ROLE_USER" }, authenticators = {})
public void update_test() throws Exception {
int userId = 1;
byte[] userHandle = UUIDUtil.convertUUIDToBytes(UUID.randomUUID());
ProfileUpdateForm userUpdateForm = new ProfileUpdateForm();
userUpdateForm.setUserHandle(Base64UrlUtil.encodeToString(userHandle));
userUpdateForm.setFirstName("John");
userUpdateForm.setLastName("Smith");
userUpdateForm.setEmailAddress("john.smith@example.com");
userUpdateForm.setAuthenticators(Collections.emptyList());
userUpdateForm.setSingleFactorAuthenticationAllowed(true);
UserEntity userEntity = new UserEntity();
userEntity.setId(userId);
userEntity.setUserHandle(userHandle);
userEntity.setId(userId);
userEntity.setFirstName("John");
userEntity.setLastName("Smith");
userEntity.setEmailAddress("john.smith@example.com");
userEntity.setAuthenticators(Collections.emptyList());
userEntity.setAuthorities(Collections.singletonList(new AuthorityEntity(0, "SINGLE_FACTOR_AUTHN_ALLOWED")));
when(profileAppService.update(anyInt(), any())).thenReturn(userEntity);
// When
mvc.perform(put("/api/profile").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(userUpdateForm)).with(SecurityMockMvcRequestPostProcessors.csrf())).andExpect(status().isOk()).andExpect(jsonPath("$.id", is(1))).andExpect(jsonPath("$.userHandle", is(Base64UrlUtil.encodeToString(userHandle)))).andExpect(jsonPath("$.firstName", is("John"))).andExpect(jsonPath("$.lastName", is("Smith"))).andExpect(jsonPath("$.emailAddress", is("john.smith@example.com"))).andExpect(jsonPath("$.authenticators", is(empty()))).andExpect(jsonPath("$.singleFactorAuthenticationAllowed", is(true)));
verify(profileAppService).update(anyInt(), any());
}
Aggregations