use of org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.
the class AuthTokenServiceImpl method createAuthToken.
@Override
@Transactional(rollbackFor = Throwable.class)
public AuthToken createAuthToken(String userEmail, String clientIp, String tokenUuid, String tokenValueUuid) throws UserNotFoundException, FieldValidationException {
Preconditions.checkArgument(userEmail != null);
Preconditions.checkArgument(clientIp != null);
Preconditions.checkArgument(StringUtils.hasText(tokenUuid));
Preconditions.checkArgument(StringUtils.hasText(tokenValueUuid));
try {
User user = userService.getUserByEmail(userEmail);
AuthToken authToken = buildNewAuthToken(user, clientIp, tokenUuid, tokenValueUuid);
authTokenDao.createAuthToken(authToken);
return authToken;
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, UserNotFoundException.class);
Throwables.throwIfInstanceOf(t, FieldValidationException.class);
String msg = String.format("Failed to create auth otken for user '%s'", userEmail);
throw new UserServiceUnexpectedException(msg, t);
}
}
use of org.summerb.microservices.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.microservices.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.
the class PasswordServiceImpl method getNewRestorationTokenForUser.
@Override
@Transactional(rollbackFor = Throwable.class)
public String getNewRestorationTokenForUser(String userUuid) throws UserNotFoundException {
Preconditions.checkArgument(userUuid != null);
assertUserExists(userUuid);
try {
String restorationToken = UUID.randomUUID().toString();
int updateResult = passwordDao.setRestorationToken(userUuid, restorationToken);
if (updateResult != 1) {
throw new RuntimeException("createRestorationToken returned unexpected result = " + updateResult);
}
return restorationToken;
} catch (Throwable t) {
String msg = String.format("Failed to create restoration token for user '%s'", userUuid);
throw new UserServiceUnexpectedException(msg, t);
}
}
use of org.summerb.microservices.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;
}
use of org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException in project summerb by skarpushin.
the class PermissionServiceImpl method revokePermission.
@Override
@Transactional(rollbackFor = Throwable.class)
public void revokePermission(String optionalDomainName, String userUuid, String optionalSubjectId, String permissionKey) {
Preconditions.checkArgument(StringUtils.hasText(permissionKey));
Preconditions.checkArgument(StringUtils.hasText(userUuid));
String domainName = getOptionalParamValue(optionalDomainName);
String subjectId = getOptionalParamValue(optionalSubjectId);
try {
permissionDao.revokePermission(domainName, userUuid, subjectId, permissionKey);
} catch (Throwable t) {
String msg = String.format("Failed to revoke permission '%s' from user '%s' for subject '%s' in domain '%s'", permissionKey, userUuid, subjectId, domainName);
throw new UserServiceUnexpectedException(msg, t);
}
}
Aggregations