use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class RegistrationServiceImpl method changePassword.
@Override
@Transactional
public void changePassword(String activationToken, String password) {
try {
TokenStoreRestData token = tokenStoreService.findAndVerifyToken(activationToken);
if (token.isExpired()) {
throw new RegistrationException("Key is Expired");
}
UserEntity user = (UserEntity) token.getUser();
user.setPassword(passwordEncoder.encode(password));
} catch (InvalidSignatureException e) {
throw new RegistrationException("Invalid Token");
}
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class UserAccessTokenAuthenticationConverter method convertUserAuthentication.
@Override
public Map<String, ?> convertUserAuthentication(Authentication authentication) {
LinkedHashMap<String, Object> response = new LinkedHashMap<>(super.convertUserAuthentication(authentication));
if (authentication.getPrincipal() instanceof UserEntity) {
UserEntity user = (UserEntity) authentication.getPrincipal();
response.put(EMAIL, user.getEmail());
response.put(USER_ID, user.getId());
}
return response;
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class ProfileRestControllerTest method testFindUserByUsername.
@Test
@WithMockUser("user123")
public void testFindUserByUsername() throws Exception {
final UserEntity user = new UserEntity().setId("user123").setEmail("user@server");
when(profileService.findProfileByUsername("user123")).thenReturn(user);
MockHttpServletRequestBuilder request = get("/api/profile").contentType(MediaType.APPLICATION_JSON);
MockHttpServletResponse response = mockMvc.perform(request).andDo(document("user-profile-view")).andReturn().getResponse();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(ProfileRestData.builder().fromUserEntity(user).build()));
verify(profileService).findProfileByUsername("user123");
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class ProfileRestControllerTest method testUpdateProfile.
@Test
@WithMockUser("user123")
public void testUpdateProfile() throws Exception {
final UserEntity user = new UserEntity().setId("user125").setUsername("user").setEmail("user@server");
when(profileService.updateProfile(eq("user123"), any())).thenReturn(user);
MockHttpServletRequestBuilder request = put("/api/profile").content("{\"username\": \"user1234\"}").contentType(MediaType.APPLICATION_JSON);
MockHttpServletResponse response = mockMvc.perform(request).andDo(document("user-profile-update")).andReturn().getResponse();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(ProfileRestData.builder().fromUserEntity(user).build()));
verify(profileService).updateProfile(eq("user123"), any());
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class ProfileRestControllerTest method testFindProfileActiveSessions.
@Test
@WithMockUser("user123")
public void testFindProfileActiveSessions() throws Exception {
final UserEntity user = new UserEntity().setUsername("user123");
when(sessionRegistry.getAllPrincipals()).thenReturn(Collections.singletonList(user));
final SessionInformation sessionInformation = new SessionInformation("1", "1", new Date());
when(sessionRegistry.getAllSessions(user, true)).thenReturn(Collections.singletonList(sessionInformation));
MockHttpServletRequestBuilder request = get("/api/profile/sessions").contentType(MediaType.APPLICATION_JSON);
MockHttpServletResponse response = mockMvc.perform(request).andDo(document("user-profile-sessions-list")).andReturn().getResponse();
assertThat(response.getStatus()).isEqualTo(200);
List<SessionInformation> expectedValue = Collections.singletonList(new SessionInformation("user123", "1", sessionInformation.getLastRequest()));
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(expectedValue));
verify(sessionRegistry).getAllPrincipals();
verify(sessionRegistry).getAllSessions(user, true);
}
Aggregations