use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.
the class LocaleResolverUserBasedImpl method resolveLocale.
@Override
public Locale resolveLocale(HttpServletRequest request) {
try {
boolean isRegisteredUser = securityContextResolver.hasRole(SecurityConstants.ROLE_USER);
if (isRegisteredUser) {
User user = securityContextResolver.getUser();
Locale userLocale = StringUtils.parseLocaleString(user.getLocale());
return userLocale;
}
} catch (Throwable t) {
log.warn("Failed to resolve locale based on user data", t);
}
return super.resolveLocale(request);
}
use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.
the class LocaleResolverUserBasedImpl method updateUserProfileWithNewLocale.
private void updateUserProfileWithNewLocale(String newLocale) throws UserNotFoundException, FieldValidationException {
User user = securityContextResolver.getUser();
if (user.getLocale().equalsIgnoreCase(newLocale)) {
return;
}
user.setLocale(newLocale);
userService.updateUser(user);
}
use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.
the class PersistentTokenRepositoryDefaultImpl method removeUserTokens.
@Override
public void removeUserTokens(String username) {
try {
User user = userService.getUserByEmail(username);
List<AuthToken> authTokens = authTokenService.findUserAuthTokens(user.getUuid());
for (AuthToken authToken : authTokens) {
authTokenService.deleteAuthToken(authToken.getUuid());
}
} catch (Throwable e) {
throw new RuntimeException("Failed to delete user auth tokens", e);
}
}
use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.
the class AuthTokenServiceImpl method authenticate.
@Override
@Transactional(rollbackFor = Throwable.class)
public AuthToken authenticate(String userEmail, String passwordPlain, String clientIp) throws UserNotFoundException, FieldValidationException, InvalidPasswordException {
Preconditions.checkArgument(userEmail != null);
Preconditions.checkArgument(passwordPlain != null);
Preconditions.checkArgument(clientIp != null);
try {
User user = validateAndGetUser(userEmail, passwordPlain);
return createAuthToken(user.getEmail(), clientIp, UUID.randomUUID().toString(), UUID.randomUUID().toString());
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, UserNotFoundException.class);
Throwables.throwIfInstanceOf(t, FieldValidationException.class);
Throwables.throwIfInstanceOf(t, InvalidPasswordException.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.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);
}
}
Aggregations