use of org.summerb.users.api.dto.User in project summerb by skarpushin.
the class AuthTokenServiceImpl method isAuthTokenValid.
@Override
@Transactional(rollbackFor = Throwable.class)
public AuthToken isAuthTokenValid(String userUuid, String authTokenUuid, String tokenValue) throws UserNotFoundException {
Preconditions.checkArgument(userUuid != null);
Preconditions.checkArgument(authTokenUuid != null);
Preconditions.checkArgument(StringUtils.hasText(tokenValue), "TokenValue is mandatory");
try {
// First - check token itself
AuthToken authToken = getAuthTokenByUuid(authTokenUuid);
if (authToken.getExpiresAt() < getNow()) {
authTokenDao.deleteAuthToken(authTokenUuid);
return null;
}
if (!tokenValue.equals(authToken.getTokenValue())) {
return null;
}
// Check reference to user
User user = userService.getUserByUuid(userUuid);
if (!authToken.getUserUuid().equals(user.getUuid())) {
return null;
}
// Now we need to update time when token was checked
authToken.setTokenValue(UUID.randomUUID().toString());
authToken.setLastVerifiedAt(getNow());
authTokenDao.updateToken(authTokenUuid, authToken.getLastVerifiedAt(), authToken.getTokenValue());
return authToken;
} catch (AuthTokenNotFoundException nfe) {
return null;
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, UserNotFoundException.class);
String msg = String.format("Failed to check auth token '%s' validity for user '%s'", authTokenUuid, userUuid);
throw new UserServiceUnexpectedException(msg, t);
}
}
use of org.summerb.users.api.dto.User in project summerb by skarpushin.
the class UserServiceImplTest method testFindUsersByDisplayNamePartial_blackbox_shouldReturnExpectedResults.
@Test
public void testFindUsersByDisplayNamePartial_blackbox_shouldReturnExpectedResults() throws Exception {
UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
PagerParams pagerParams = new PagerParams(20, 40);
PaginatedList<User> resultFromDao = new PaginatedList<User>();
resultFromDao.setTotalResults(1);
resultFromDao.setPagerParams(pagerParams);
resultFromDao.setItems(new LinkedList<User>());
resultFromDao.getItems().add(UserFactory.createNewUserTemplate());
when(fixture.getUserDao().findUserByDisplayNamePartial("asd", pagerParams)).thenReturn(resultFromDao);
PaginatedList<User> results = fixture.findUsersByDisplayNamePartial("asd", pagerParams);
assertNotNull(results);
assertNotNull(results.getPagerParams());
assertEquals(pagerParams.getOffset(), results.getPagerParams().getOffset());
assertEquals(pagerParams.getMax(), results.getPagerParams().getMax());
assertEquals(1, results.getTotalResults());
}
use of org.summerb.users.api.dto.User in project summerb by skarpushin.
the class UserServiceImplTest method testCreateUser_whitebox_expectOurExceptionInsteadOfUnexpectedOne.
@Test(expected = UserServiceUnexpectedException.class)
public void testCreateUser_whitebox_expectOurExceptionInsteadOfUnexpectedOne() throws Exception {
UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
User user = UserFactory.createNewUserTemplate();
doThrow(new IllegalArgumentException("test exception")).when(fixture.getUserDao()).createUser(any(User.class));
fixture.createUser(user);
fail();
}
use of org.summerb.users.api.dto.User in project summerb by skarpushin.
the class UserServiceImplTest method testCreateUser_blackbox_expectValidationExceptionOnInvalidEmail1.
@Test(expected = FieldValidationException.class)
public void testCreateUser_blackbox_expectValidationExceptionOnInvalidEmail1() throws Exception {
UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
User user = UserFactory.createNewUserTemplate();
user.setEmail(null);
fixture.createUser(user);
fail();
}
use of org.summerb.users.api.dto.User in project summerb by skarpushin.
the class UserServiceImplTest method testCreateUser_blackbox_expectGuidWillBeCreatedForTheUser.
@Test
public void testCreateUser_blackbox_expectGuidWillBeCreatedForTheUser() throws Exception {
UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
User result = fixture.createUser(UserFactory.createNewUserTemplate());
// add additional test code here
assertNotNull(result);
assertNotNull(result.getUuid());
}
Aggregations