use of org.openremote.manager.security.UserConfiguration in project openremote by openremote.
the class AssetStorageService method getUserConfiguration.
protected UserConfiguration getUserConfiguration(EntityManager em, String userId) {
UserConfiguration userConfiguration = em.find(UserConfiguration.class, userId);
if (userConfiguration == null) {
userConfiguration = new UserConfiguration(userId);
userConfiguration = mergeUserConfiguration(em, userConfiguration);
}
return userConfiguration;
}
use of org.openremote.manager.security.UserConfiguration in project openremote by openremote.
the class AssetStorageService method storeUserAsset.
protected void storeUserAsset(EntityManager entityManager, UserAsset userAsset) {
// The user must be configured as restricted
UserConfiguration userConfiguration = getUserConfiguration(entityManager, userAsset.getId().getUserId());
userConfiguration.setRestricted(true);
mergeUserConfiguration(entityManager, userConfiguration);
userAsset.setCreatedOn(new Date(timerService.getCurrentTimeMillis()));
entityManager.merge(userAsset);
}
use of org.openremote.manager.security.UserConfiguration in project openremote by openremote.
the class AssetStorageService method deleteUserAsset.
/**
* Also marks the user as unrestricted if no assets are linked to the user, manages {@link UserConfiguration#isRestricted()}.
*/
public void deleteUserAsset(String realmId, String userId, String assetId) {
persistenceService.doTransaction(entityManager -> {
UserAsset userAsset = entityManager.find(UserAsset.class, new UserAsset.Id(realmId, userId, assetId));
if (userAsset != null)
entityManager.remove(userAsset);
// If there are no more assets linked to this user
long count = entityManager.createQuery("select count(ua) from UserAsset ua where ua.id.userId = :userId", Long.class).setParameter("userId", userId).getSingleResult();
if (count == 0) {
// The user must be configured as not restricted
UserConfiguration userConfiguration = getUserConfiguration(entityManager, userAsset.getId().getUserId());
userConfiguration.setRestricted(false);
mergeUserConfiguration(entityManager, userConfiguration);
}
});
}
Aggregations