@SuppressWarnings("unchecked") public void updateUser(final User updatedUser) { String serverEncryptPassword = EncryptUtils.clientPwd2ServerPwd(updatedUser.getPassword()); updatedUser.setPassword(serverEncryptPassword); User userInDb = getUser(updatedUser.getUserName()); final boolean existed = (userInDb != null); if (existed) { userDao.merge(updatedUser); // 更新用户的管理范围,权限树 if (!YuepObjectUtils.collectionEquals(userInDb.getMgmtScope(), updatedUser.getMgmtScope())) { mgmtScopeManager.setUserMgmtScope(updatedUser.getUserName(), updatedUser.getMgmtScope()); } if (!YuepObjectUtils.collectionEquals(userInDb.getRoles(), updatedUser.getRoles())) { userPermissionTree.userRolePermissionChanged(updatedUser); } } else { userDao.saveEntity(updatedUser); } // 发送消息 SmMessage msg = new SmMessage(); msg.setMessageBody(updatedUser); if (existed) { msg.setMessageType(SmMessage.TYPE_USER_UPDATE); Map changedInfo = userInDb.getValueCompareObjectMap(updatedUser); msg.setAdditions(changedInfo); } else { msg.setMessageType(SmMessage.TYPE_USER_ADD); } SmCoreContext.publishMessage(msg.getName(), msg); }
/** * 创建一个user * * @param user */ public void addUser(User user) { String serverEncryptPwd = EncryptUtils.clientPwd2ServerPwd(user.getPassword()); user.setPassword(serverEncryptPwd); userDao.saveEntity(user); // 发送消息 SmMessage msg = new SmMessage(); msg.setMessageType(SmMessage.TYPE_USER_ADD); msg.setMessageBody(user); SmCoreContext.publishMessage(msg.getName(), msg); }
public void deleteUser(final User user) { Set<Long> sessions = loginedUserSessions.get(user.getUserName()); if (CollectionUtils.isNotEmpty(sessions)) { throw new SmException(SmException.USER_IN_SESSION); } // 删除用户的个性化信息 userCustomProcessor.deleteUserCustom(user.getUserName()); userDao.deleteEntity(user); // 发送消息 SmMessage msg = new SmMessage(); msg.setMessageType(SmMessage.TYPE_USER_DELETE); msg.setMessageBody(user); SmCoreContext.publishMessage(msg.getName(), msg); }