use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class GalleryRestControllerTest method init.
@Before
public void init() {
mockMvc = MockMvcBuilders.standaloneSetup(new GalleryRestController(galleryService)).setCustomArgumentResolvers(new AuthenticationPrincipalArgumentResolver(), new PageableHandlerMethodArgumentResolver()).apply(documentationConfiguration(restDocumentation)).build();
Authentication authentication = new UsernamePasswordAuthenticationToken(new UserEntity().setId(USER_ID).setUsername(USERNAME), "1234");
SecurityContextHolder.getContext().setAuthentication(authentication);
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class PostServiceTest method testSavePost.
@Test
public void testSavePost() {
when(postRepository.save(DUMMY_POST)).thenReturn(DUMMY_POST2);
PostEntity savedPost = postService.savePost(new UserEntity(), DUMMY_POST);
assertThat(savedPost).isEqualTo(DUMMY_POST2);
verify(postRepository).save(DUMMY_POST);
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class UserFollowerRestControllerTest method init.
@Before
public void init() {
when(userDetailsService.loadUserByUsername(USERNAME)).thenReturn(new UserEntity().setId(USER_ID).setUsername(USERNAME));
mockMvc = MockMvcBuilders.standaloneSetup(new UserFollowerRestController(userFollowerService)).setCustomArgumentResolvers(new UserArgumentResolver(userDetailsService), new AuthenticationPrincipalArgumentResolver(), new PageableHandlerMethodArgumentResolver()).apply(documentationConfiguration(restDocumentation)).build();
Authentication authentication = new UsernamePasswordAuthenticationToken(new UserEntity().setId(USER_ID).setUsername(USERNAME), "1234");
SecurityContextHolder.getContext().setAuthentication(authentication);
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class TokenStoreServiceImpl method findAndVerifyToken.
@Override
public TokenStoreRestData findAndVerifyToken(String token) {
try {
Jwt jwt = JwtHelper.decode(token);
TokenStoreRestData data = objectMapper.readValue(jwt.getClaims(), TokenStoreRestData.class);
UserEntity user = userRepository.findById(data.getUserId()).orElseThrow(() -> new UsernameNotFoundException(data.getUserId()));
SignerVerifier verifier = createSignerVerifier(user);
jwt.verifySignature(verifier);
return ImmutableTokenStoreRestData.builder().from(data).signedToken(jwt.getEncoded()).user(user).build();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class RegistrationServiceImpl method registerUser.
@Override
@Transactional
public UserEntity registerUser(RegistrationForm form) {
userRepository.findByUsernameOrEmailAndEnabled(form.getUsername(), form.getEmail(), true).findFirst().ifPresent(user -> {
throw new RegistrationException("Username or email already exists");
});
Stream<UserEntity> existingUsers = userRepository.findByUsernameOrEmailAndEnabled(form.getUsername(), form.getEmail(), false);
final UserEntity user = existingUsers.findFirst().orElse(new UserEntity()).setUsername(form.getUsername()).setEmail(form.getEmail()).setPassword(passwordEncoder.encode(form.getPassword())).setExpiredAt(null).setAccountNonLocked(true).setCredentialsNonExpired(true);
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
tokenStoreService.sendTokenNotification(TokenStoreType.USER_ACTIVATION, user);
}
});
return user.getId() == null ? userRepository.save(user) : user;
}
Aggregations