use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class UserServiceImpl method requestPasswordReset.
@Override
public UserCredentials requestPasswordReset(String email) {
log.trace("Executing requestPasswordReset email [{}]", email);
validateString(email, "Incorrect email " + email);
User user = userDao.findByEmail(email);
if (user == null) {
throw new IncorrectParameterException(String.format("Unable to find user by email [%s]", email));
}
UserCredentials userCredentials = userCredentialsDao.findByUserId(user.getUuidId());
if (!userCredentials.isEnabled()) {
throw new IncorrectParameterException("Unable to reset password for inactive user");
}
userCredentials.setResetToken(RandomStringUtils.randomAlphanumeric(DEFAULT_TOKEN_LENGTH));
return saveUserCredentials(userCredentials);
}
use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class UserServiceImpl method activateUserCredentials.
@Override
public UserCredentials activateUserCredentials(String activateToken, String password) {
log.trace("Executing activateUserCredentials activateToken [{}], password [{}]", activateToken, password);
validateString(activateToken, "Incorrect activateToken " + activateToken);
validateString(password, "Incorrect password " + password);
UserCredentials userCredentials = userCredentialsDao.findByActivateToken(activateToken);
if (userCredentials == null) {
throw new IncorrectParameterException(String.format("Unable to find user credentials by activateToken [%s]", activateToken));
}
if (userCredentials.isEnabled()) {
throw new IncorrectParameterException("User credentials already activated");
}
userCredentials.setEnabled(true);
userCredentials.setActivateToken(null);
userCredentials.setPassword(password);
return saveUserCredentials(userCredentials);
}
use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class UserCredentialsEntity method toData.
@Override
public UserCredentials toData() {
UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(id));
userCredentials.setCreatedTime(UUIDs.unixTimestamp(id));
if (userId != null) {
userCredentials.setUserId(new UserId(userId));
}
userCredentials.setEnabled(enabled);
userCredentials.setPassword(password);
userCredentials.setActivateToken(activateToken);
userCredentials.setResetToken(resetToken);
return userCredentials;
}
use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class UserCredentialsEntity method toData.
@Override
public UserCredentials toData() {
UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(getId()));
userCredentials.setCreatedTime(UUIDs.unixTimestamp(getId()));
if (userId != null) {
userCredentials.setUserId(new UserId(toUUID(userId)));
}
userCredentials.setEnabled(enabled);
userCredentials.setPassword(password);
userCredentials.setActivateToken(activateToken);
userCredentials.setResetToken(resetToken);
return userCredentials;
}
use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class RefreshTokenAuthenticationProvider method authenticateByUserId.
private SecurityUser authenticateByUserId(UserId userId) {
User user = userService.findUserById(userId);
if (user == null) {
throw new UsernameNotFoundException("User not found by refresh token");
}
UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getId());
if (userCredentials == null) {
throw new UsernameNotFoundException("User credentials not found");
}
if (!userCredentials.isEnabled()) {
throw new DisabledException("User is not active");
}
if (user.getAuthority() == null)
throw new InsufficientAuthenticationException("User has no authority assigned");
UserPrincipal userPrincipal = new UserPrincipal(UserPrincipal.Type.USER_NAME, user.getEmail());
SecurityUser securityUser = new SecurityUser(user, userCredentials.isEnabled(), userPrincipal);
return securityUser;
}
Aggregations