|
|
|
@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.context.ApplicationEventPublisher; |
|
|
|
import org.springframework.security.authentication.DisabledException; |
|
|
|
@ -31,7 +30,6 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.common.data.User; |
|
|
|
import org.thingsboard.server.common.data.UserMobileInfo; |
|
|
|
import org.thingsboard.server.common.data.audit.ActionType; |
|
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
@ -40,6 +38,8 @@ import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantProfileId; |
|
|
|
import org.thingsboard.server.common.data.id.UserCredentialsId; |
|
|
|
import org.thingsboard.server.common.data.id.UserId; |
|
|
|
import org.thingsboard.server.common.data.mobile.MobileSessionInfo; |
|
|
|
import org.thingsboard.server.common.data.mobile.UserMobileInfo; |
|
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
|
import org.thingsboard.server.common.data.security.Authority; |
|
|
|
@ -56,6 +56,7 @@ import org.thingsboard.server.dao.exception.IncorrectParameterException; |
|
|
|
import org.thingsboard.server.dao.service.DataValidator; |
|
|
|
import org.thingsboard.server.dao.service.PaginatedRemover; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
@ -90,6 +91,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
|
|
|
private final UserCredentialsDao userCredentialsDao; |
|
|
|
private final UserAuthSettingsDao userAuthSettingsDao; |
|
|
|
private final UserSettingsService userSettingsService; |
|
|
|
private final UserSettingsDao userSettingsDao; |
|
|
|
private final DataValidator<User> userValidator; |
|
|
|
private final DataValidator<UserCredentials> userCredentialsValidator; |
|
|
|
private final ApplicationEventPublisher eventPublisher; |
|
|
|
@ -397,19 +399,39 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void saveMobileInfo(TenantId tenantId, UserId userId, UserMobileInfo mobileInfo) { |
|
|
|
if (StringUtils.isNotEmpty(mobileInfo.getFcmToken())) { |
|
|
|
// unassigning fcm token from other users, in case we didn't clean up it on log out or mobile app uninstall
|
|
|
|
userDao.unassignFcmToken(tenantId, mobileInfo.getFcmToken()); |
|
|
|
} |
|
|
|
public void saveMobileSession(TenantId tenantId, UserId userId, String mobileToken, MobileSessionInfo sessionInfo) { |
|
|
|
removeMobileSession(tenantId, mobileToken); // unassigning fcm token from other users, in case we didn't clean up it on log out or mobile app uninstall
|
|
|
|
|
|
|
|
UserMobileInfo mobileInfo = findMobileInfo(tenantId, userId).orElseGet(() -> { |
|
|
|
UserMobileInfo newMobileInfo = new UserMobileInfo(); |
|
|
|
newMobileInfo.setSessions(new HashMap<>()); |
|
|
|
return newMobileInfo; |
|
|
|
}); |
|
|
|
mobileInfo.getSessions().put(mobileToken, sessionInfo); |
|
|
|
userSettingsService.updateUserSettings(tenantId, userId, UserSettingsType.MOBILE, JacksonUtil.valueToTree(mobileInfo)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public UserMobileInfo findMobileInfo(TenantId tenantId, UserId userId) { |
|
|
|
public Map<String, MobileSessionInfo> findMobileSessions(TenantId tenantId, UserId userId) { |
|
|
|
return findMobileInfo(tenantId, userId).map(UserMobileInfo::getSessions).orElse(Collections.emptyMap()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public MobileSessionInfo findMobileSession(TenantId tenantId, UserId userId, String mobileToken) { |
|
|
|
return findMobileInfo(tenantId, userId).map(mobileInfo -> mobileInfo.getSessions().get(mobileToken)).orElse(null); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void removeMobileSession(TenantId tenantId, String mobileToken) { |
|
|
|
for (UserSettings userSettings : userSettingsDao.findByTypeAndPath(tenantId, UserSettingsType.MOBILE, "sessions", mobileToken)) { |
|
|
|
((ObjectNode) userSettings.getSettings().get("sessions")).remove(mobileToken); |
|
|
|
userSettingsService.saveUserSettings(tenantId, userSettings); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Optional<UserMobileInfo> findMobileInfo(TenantId tenantId, UserId userId) { |
|
|
|
return Optional.ofNullable(userSettingsService.findUserSettings(tenantId, userId, UserSettingsType.MOBILE)) |
|
|
|
.map(UserSettings::getSettings).map(settings -> JacksonUtil.treeToValue(settings, UserMobileInfo.class)) |
|
|
|
.orElse(null); |
|
|
|
.map(UserSettings::getSettings).map(settings -> JacksonUtil.treeToValue(settings, UserMobileInfo.class)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|