use of org.summerb.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.
the class UserServiceImpl method deleteUserByUuid.
@Override
@Transactional(rollbackFor = Throwable.class)
public void deleteUserByUuid(String userUuid) throws UserNotFoundException {
Preconditions.checkArgument(userUuid != null, "User uuid required");
Preconditions.checkArgument(StringUtils.hasText(userUuid), "User uuid must be provided");
boolean isDeletedSucceessfully = false;
try {
User userToDelete = userDao.findUserByUuid(userUuid);
if (userToDelete != null) {
isDeletedSucceessfully = userDao.deleteUser(userUuid);
// NOTE: Assumed, that all related stuff will be deleted
// automatically using CASCADE DELETE in the database
eventBus.post(EntityChangedEvent.removedObject(userToDelete));
}
} catch (Throwable t) {
String msg = String.format("Failed to delete user '%s'", userUuid);
throw new UserServiceUnexpectedException(msg, t);
}
if (!isDeletedSucceessfully) {
throw new UserNotFoundException(userUuid);
}
}
use of org.summerb.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.
the class AuthTokenServiceImpl method validateAndGetUser.
private User validateAndGetUser(String userEmail, String passwordPlain) throws UserNotFoundException, FieldValidationException, InvalidPasswordException {
try {
User user = userService.getUserByEmail(userEmail);
boolean isPasswordValid = passwordService.isUserPasswordValid(user.getUuid(), passwordPlain);
if (!isPasswordValid) {
throw new InvalidPasswordException();
}
return user;
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, UserNotFoundException.class);
Throwables.throwIfInstanceOf(t, FieldValidationException.class);
Throwables.throwIfInstanceOf(t, InvalidPasswordException.class);
String msg = String.format("Failed to validate user '%s' and password '%s'", userEmail, passwordPlain);
throw new UserServiceUnexpectedException(msg, t);
}
}
use of org.summerb.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.
the class AuthTokenServiceImpl method updateToken.
@Override
@Transactional(rollbackFor = Throwable.class)
public void updateToken(String authTokenUuid, long lastVerifiedAt, String newTokenValue) throws AuthTokenNotFoundException, FieldValidationException {
Preconditions.checkArgument(authTokenUuid != null);
Preconditions.checkArgument(StringUtils.hasText(newTokenValue), "TokenValue is mandatory");
try {
// First - check token itself
AuthToken authToken = getAuthTokenByUuid(authTokenUuid);
if (newTokenValue.equals(authToken.getTokenValue())) {
throw new FieldValidationException(new ValidationError("validation.newValueExpected", "newTokenValue"));
}
// Now we need to update time when token was checked
authTokenDao.updateToken(authTokenUuid, lastVerifiedAt, newTokenValue);
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, FieldValidationException.class);
Throwables.throwIfInstanceOf(t, AuthTokenNotFoundException.class);
String msg = String.format("Failed to update token '%s'", authTokenUuid);
throw new UserServiceUnexpectedException(msg, t);
}
}
use of org.summerb.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.
the class PasswordServiceImpl method deleteRestorationToken.
@Override
@Transactional(rollbackFor = Throwable.class)
public void deleteRestorationToken(String userUuid) throws UserNotFoundException {
Preconditions.checkArgument(userUuid != null);
assertUserExists(userUuid);
try {
int updateResult = passwordDao.setRestorationToken(userUuid, null);
if (updateResult != 1) {
throw new RuntimeException("deleteRestorationToken returned unexpected result = " + updateResult);
}
} catch (Throwable t) {
String msg = String.format("Failed to delete restoration token for user '%s'", userUuid);
throw new UserServiceUnexpectedException(msg, t);
}
}
use of org.summerb.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.
the class PasswordServiceImpl method isUserPasswordValid.
@Override
public boolean isUserPasswordValid(String userUuid, String passwordPlain) throws UserNotFoundException {
Preconditions.checkArgument(userUuid != null);
Preconditions.checkArgument(passwordPlain != null);
assertUserExists(userUuid);
try {
Password password = passwordDao.findPasswordByUserUuid(userUuid);
if (password == null) {
return false;
}
if (!isPasswordMatch(passwordPlain, password.getPasswordHash())) {
return false;
}
} catch (Throwable t) {
String msg = String.format("Failed to validate user '%s' password", userUuid);
throw new UserServiceUnexpectedException(msg, t);
}
return true;
}
Aggregations