use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class UserController method getActivationLink.
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/user/{userId}/activationLink", method = RequestMethod.GET, produces = "text/plain")
@ResponseBody
public String getActivationLink(@PathVariable(USER_ID) String strUserId, HttpServletRequest request) throws ThingsboardException {
checkParameter(USER_ID, strUserId);
try {
UserId userId = new UserId(toUUID(strUserId));
SecurityUser authUser = getCurrentUser();
if (authUser.getAuthority() == Authority.CUSTOMER_USER && !authUser.getId().equals(userId)) {
throw new ThingsboardException(YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION, ThingsboardErrorCode.PERMISSION_DENIED);
}
User user = checkUserId(userId);
UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getId());
if (!userCredentials.isEnabled()) {
String baseUrl = constructBaseUrl(request);
String activateUrl = String.format(ACTIVATE_URL_PATTERN, baseUrl, userCredentials.getActivateToken());
return activateUrl;
} else {
throw new ThingsboardException("User is already active!", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
}
} catch (Exception e) {
throw handleException(e);
}
}
use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class UserServiceImpl method deleteUser.
@Override
public void deleteUser(UserId userId) {
log.trace("Executing deleteUser [{}]", userId);
validateId(userId, INCORRECT_USER_ID + userId);
UserCredentials userCredentials = userCredentialsDao.findByUserId(userId.getId());
userCredentialsDao.removeById(userCredentials.getUuidId());
deleteEntityRelations(userId);
userDao.removeById(userId.getId());
}
use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class UserServiceImpl method saveUser.
@Override
public User saveUser(User user) {
log.trace("Executing saveUser [{}]", user);
userValidator.validate(user);
User savedUser = userDao.save(user);
if (user.getId() == null) {
UserCredentials userCredentials = new UserCredentials();
userCredentials.setEnabled(false);
userCredentials.setActivateToken(RandomStringUtils.randomAlphanumeric(DEFAULT_TOKEN_LENGTH));
userCredentials.setUserId(new UserId(savedUser.getUuidId()));
userCredentialsDao.save(userCredentials);
}
return savedUser;
}
use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class BaseUserServiceTest method testFindUserCredentials.
@Test
public void testFindUserCredentials() {
User user = userService.findUserByEmail("sysadmin@thingsboard.org");
Assert.assertNotNull(user);
UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getId());
Assert.assertNotNull(userCredentials);
}
use of org.thingsboard.server.common.data.security.UserCredentials in project thingsboard by thingsboard.
the class BaseUserServiceTest method testDeleteUser.
@Test
public void testDeleteUser() {
User tenantAdminUser = userService.findUserByEmail("tenant@thingsboard.org");
User user = new User();
user.setAuthority(Authority.TENANT_ADMIN);
user.setTenantId(tenantAdminUser.getTenantId());
user.setEmail("tenant2@thingsboard.org");
User savedUser = userService.saveUser(user);
Assert.assertNotNull(savedUser);
Assert.assertNotNull(savedUser.getId());
User foundUser = userService.findUserById(savedUser.getId());
Assert.assertNotNull(foundUser);
UserCredentials userCredentials = userService.findUserCredentialsByUserId(foundUser.getId());
Assert.assertNotNull(userCredentials);
userService.deleteUser(foundUser.getId());
userCredentials = userService.findUserCredentialsByUserId(foundUser.getId());
foundUser = userService.findUserById(foundUser.getId());
Assert.assertNull(foundUser);
Assert.assertNull(userCredentials);
}
Aggregations