use of com.baeldung.security.AppUserPrincipal in project tutorials by eugenp.
the class SpringDataWithSecurityTest method givenAppUser_whenLoginSuccessful_shouldReadMyPagedTweets.
@Test
public void givenAppUser_whenLoginSuccessful_shouldReadMyPagedTweets() {
AppUser appUser = userRepository.findByUsername("lionel@messi.com");
Authentication auth = new UsernamePasswordAuthenticationToken(new AppUserPrincipal(appUser), null, DummyContentUtil.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(auth);
Page<Tweet> page = null;
do {
page = tweetRepository.getMyTweetsAndTheOnesILiked(new PageRequest(page != null ? page.getNumber() + 1 : 0, 5));
for (Tweet twt : page.getContent()) {
isTrue((twt.getOwner() == appUser.getUsername()) || (twt.getLikes().contains(appUser.getUsername())), "I do not have any Tweets");
}
} while (page.hasNext());
}
use of com.baeldung.security.AppUserPrincipal in project tutorials by eugenp.
the class SpringDataWithSecurityTest method givenAppUser_whenLoginSuccessful_shouldUpdateLastLogin.
@Test
public void givenAppUser_whenLoginSuccessful_shouldUpdateLastLogin() {
AppUser appUser = userRepository.findByUsername("lionel@messi.com");
Authentication auth = new UsernamePasswordAuthenticationToken(new AppUserPrincipal(appUser), null, DummyContentUtil.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(auth);
userRepository.updateLastLogin(new Date());
}
Aggregations