mirror of
https://gitee.com/270580156/weiyu.git
synced 2025-12-30 02:42:25 +00:00
update
This commit is contained in:
@@ -99,7 +99,6 @@ public class QueueRestService extends BaseRestServiceWithExport<QueueEntity, Que
|
||||
|
||||
public Page<ThreadResponse> queryQueuing(ThreadRequest request) {
|
||||
UserEntity user = authService.getUser();
|
||||
|
||||
// 设置查询条件:状态为排队中
|
||||
request.setStatus(ThreadProcessStatusEnum.QUEUING.name());
|
||||
|
||||
|
||||
@@ -25,9 +25,14 @@ import com.bytedesk.core.constant.I18Consts;
|
||||
import com.bytedesk.core.rbac.organization.OrganizationEntity;
|
||||
import com.bytedesk.core.rbac.organization.event.OrganizationCreateEvent;
|
||||
import com.bytedesk.core.rbac.user.UserEntity;
|
||||
import com.bytedesk.core.socket.mqtt.event.MqttConnectedEvent;
|
||||
import com.bytedesk.core.topic.TopicCacheService;
|
||||
import com.bytedesk.core.topic.TopicUtils;
|
||||
import com.bytedesk.core.uid.UidUtils;
|
||||
import com.bytedesk.service.agent.AgentEntity;
|
||||
import com.bytedesk.service.agent.AgentRestService;
|
||||
import com.bytedesk.service.workgroup.event.WorkgroupCreateEvent;
|
||||
import com.bytedesk.service.workgroup.event.WorkgroupUpdateEvent;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -39,9 +44,9 @@ public class WorkgroupEventListener {
|
||||
|
||||
private final AgentRestService agentRestService;
|
||||
|
||||
private final WorkgroupRestService workgroupService;
|
||||
private final WorkgroupRestService workgroupRestService;
|
||||
|
||||
// private final WorktimeRestService worktimeService;
|
||||
private final TopicCacheService topicCacheService;
|
||||
|
||||
private final UidUtils uidUtils;
|
||||
|
||||
@@ -72,8 +77,45 @@ public class WorkgroupEventListener {
|
||||
.agentUids(agentUids)
|
||||
.orgUid(orgUid)
|
||||
.build();
|
||||
workgroupService.create(workgroupRequest);
|
||||
workgroupRestService.create(workgroupRequest);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void onWorkgroupCreateEvent(WorkgroupCreateEvent event) {
|
||||
WorkgroupEntity workgroup = (WorkgroupEntity) event.getSource();
|
||||
String workgroupUid = workgroup.getUid();
|
||||
String topic = TopicUtils.getQueueTopicFromUid(workgroupUid);
|
||||
log.info("workgroup - workgroup created: {}, topic: {}", workgroup.getNickname(), topic);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void onWorkgroupUpdateEvent(WorkgroupUpdateEvent event) {
|
||||
WorkgroupEntity workgroup = (WorkgroupEntity) event.getSource();
|
||||
String workgroupUid = workgroup.getUid();
|
||||
String topic = TopicUtils.getQueueTopicFromUid(workgroupUid);
|
||||
log.info("workgroup - workgroup updated: {}, topic: {}", workgroup.getNickname(), topic);
|
||||
// topicCacheService.updateTopic(topic);
|
||||
}
|
||||
|
||||
// @EventListener
|
||||
// public void onWorkgroupDeleteEvent(WorkgroupDeleteEvent event) {
|
||||
// WorkgroupEntity workgroup = (WorkgroupEntity) event.getSource();
|
||||
// String workgroupUid = workgroup.getUid();
|
||||
// String topic = TopicUtils.getQueueTopicFromUid(workgroupUid);
|
||||
// log.info("workgroup - workgroup deleted: {}, topic: {}", workgroup.getNickname(), topic);
|
||||
// // topicCacheService.removeTopic(topic);
|
||||
// }
|
||||
|
||||
@EventListener
|
||||
public void onMqttConnectedEvent(MqttConnectedEvent event) {
|
||||
String clientId = event.getClientId();
|
||||
// 用户clientId格式: uid/client/deviceUid
|
||||
final String userUid = clientId.split("/")[0];
|
||||
log.info("topic onMqttConnectedEvent uid {}, clientId {}", userUid, clientId);
|
||||
List<String> workgroupUids = workgroupRestService.findWorkgroupUidsByUserUid(userUid);
|
||||
for (String workgroupUid : workgroupUids) {
|
||||
String topic = TopicUtils.getQueueTopicFromUid(workgroupUid);
|
||||
topicCacheService.pushTopic(topic, userUid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ package com.bytedesk.service.workgroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
@@ -57,6 +58,27 @@ public class WorkgroupRestService extends BaseRestService<WorkgroupEntity, Workg
|
||||
|
||||
private final WorkgroupSettingsRestService workgroupSettingsRestService;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<String> findWorkgroupUidsByUserUid(String userUid) {
|
||||
if (!StringUtils.hasText(userUid)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
Optional<AgentEntity> agentOptional = agentRestService.findByUserUid(userUid);
|
||||
if (!agentOptional.isPresent()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<WorkgroupEntity> workgroups = workgroupRepository.findByAgentUid(agentOptional.get().getUid());
|
||||
List<String> workgroupUids = new ArrayList<>();
|
||||
for (WorkgroupEntity workgroup : workgroups) {
|
||||
if (workgroup != null && !workgroup.isDeleted() && StringUtils.hasText(workgroup.getUid())) {
|
||||
workgroupUids.add(workgroup.getUid());
|
||||
}
|
||||
}
|
||||
return workgroupUids;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public WorkgroupResponse create(WorkgroupRequest request) {
|
||||
// 判断uid是否已经存储,如果已经存在,则不创建新的workgroup
|
||||
@@ -173,7 +195,6 @@ public class WorkgroupRestService extends BaseRestService<WorkgroupEntity, Workg
|
||||
return convertToResponse(updatedWorkgroup);
|
||||
}
|
||||
|
||||
// updateAvatar
|
||||
@Transactional
|
||||
public WorkgroupResponse updateAvatar(WorkgroupRequest request) {
|
||||
WorkgroupEntity workgroup = findByUid(request.getUid()).orElseThrow(() -> new RuntimeException("workgroup not found with uid: " + request.getUid()));
|
||||
|
||||
@@ -13,47 +13,47 @@
|
||||
*/
|
||||
package com.bytedesk.ticket.identity;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
// import lombok.RequiredArgsConstructor;
|
||||
// import org.springframework.context.event.EventListener;
|
||||
// import org.springframework.stereotype.Component;
|
||||
// import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import com.bytedesk.service.agent.AgentEntity;
|
||||
import com.bytedesk.service.agent.event.AgentUpdateEvent;
|
||||
import com.bytedesk.service.workgroup.event.WorkgroupUpdateEvent;
|
||||
// import com.bytedesk.service.agent.AgentEntity;
|
||||
// import com.bytedesk.service.agent.event.AgentUpdateEvent;
|
||||
// import com.bytedesk.service.workgroup.event.WorkgroupUpdateEvent;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class TicketIdentityListener {
|
||||
// @Slf4j
|
||||
// @Component
|
||||
// @RequiredArgsConstructor
|
||||
// public class TicketIdentityListener {
|
||||
|
||||
private final TicketIdentityService identityService;
|
||||
// // private final TicketIdentityService identityService;
|
||||
|
||||
/**
|
||||
* 监听用户创建/更新事件
|
||||
*/
|
||||
@EventListener
|
||||
public void onAgentUpdated(AgentUpdateEvent event) {
|
||||
AgentEntity agent = event.getAgent();
|
||||
// 同步用户到Flowable
|
||||
identityService.syncUser(agent);
|
||||
}
|
||||
// /**
|
||||
// * 监听用户创建/更新事件
|
||||
// */
|
||||
// @EventListener
|
||||
// public void onAgentUpdated(AgentUpdateEvent event) {
|
||||
// AgentEntity agent = event.getAgent();
|
||||
// // 同步用户到Flowable
|
||||
// // identityService.syncUser(agent);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 监听工作组变更事件(最小载荷)
|
||||
*/
|
||||
@EventListener
|
||||
public void onWorkgroupUpdated(WorkgroupUpdateEvent event) {
|
||||
// 使用最小载荷字段进行同步,避免实体序列化问题
|
||||
identityService.syncWorkgroupByBasic(event.getWorkgroupUid(), event.getNickname());
|
||||
}
|
||||
// /**
|
||||
// * 监听工作组变更事件(最小载荷)
|
||||
// */
|
||||
// @EventListener
|
||||
// public void onWorkgroupUpdated(WorkgroupUpdateEvent event) {
|
||||
// // 使用最小载荷字段进行同步,避免实体序列化问题
|
||||
// // identityService.syncWorkgroupByBasic(event.getWorkgroupUid(), event.getNickname());
|
||||
// }
|
||||
|
||||
/**
|
||||
* 监听用户加入工作组事件
|
||||
*/
|
||||
// @EventListener
|
||||
// public void onAgentJoinWorkgroup(AgentJoinWorkgroupEvent event) {
|
||||
// // 同步用户和工作组关系
|
||||
// identityService.syncMembership(event.getAgentId(), event.getWorkgroupId());
|
||||
// }
|
||||
}
|
||||
// /**
|
||||
// * 监听用户加入工作组事件
|
||||
// */
|
||||
// // @EventListener
|
||||
// // public void onAgentJoinWorkgroup(AgentJoinWorkgroupEvent event) {
|
||||
// // // 同步用户和工作组关系
|
||||
// // identityService.syncMembership(event.getAgentId(), event.getWorkgroupId());
|
||||
// // }
|
||||
// }
|
||||
@@ -1,350 +1,350 @@
|
||||
package com.bytedesk.ticket.identity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
// import java.util.List;
|
||||
// import java.util.ArrayList;
|
||||
|
||||
import org.flowable.idm.api.Group;
|
||||
import org.flowable.idm.api.IdmIdentityService;
|
||||
import org.flowable.idm.api.User;
|
||||
import org.flowable.idm.api.Privilege;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
// import org.flowable.idm.api.Group;
|
||||
// import org.flowable.idm.api.IdmIdentityService;
|
||||
// import org.flowable.idm.api.User;
|
||||
// import org.flowable.idm.api.Privilege;
|
||||
// import org.springframework.security.core.Authentication;
|
||||
// import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
// import org.springframework.security.core.context.SecurityContextHolder;
|
||||
// import org.springframework.stereotype.Service;
|
||||
|
||||
import com.bytedesk.service.agent.AgentEntity;
|
||||
// import com.bytedesk.service.agent.AgentRestService;
|
||||
import com.bytedesk.service.workgroup.WorkgroupEntity;
|
||||
// import com.bytedesk.service.workgroup.WorkgroupRestService;
|
||||
// import com.bytedesk.service.agent.AgentEntity;
|
||||
// // import com.bytedesk.service.agent.AgentRestService;
|
||||
// import com.bytedesk.service.workgroup.WorkgroupEntity;
|
||||
// // import com.bytedesk.service.workgroup.WorkgroupRestService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
// import lombok.RequiredArgsConstructor;
|
||||
// import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 工单用户和组管理
|
||||
* 使用场景:
|
||||
*
|
||||
* 用户管理:
|
||||
* 同步业务系统用户到 Flowable
|
||||
* 管理用户信息和状态
|
||||
* 用户认证和授权
|
||||
*
|
||||
* 组管理:
|
||||
* 同步业务系统组织架构
|
||||
* 管理工作组和角色
|
||||
* 权限分配
|
||||
*
|
||||
* 关系管理:
|
||||
* 维护用户和组的关系
|
||||
* 支持多组织架构
|
||||
* 灵活的权限控制
|
||||
*
|
||||
* 这样就能将业务系统的用户和组织架构与 Flowable 的工作流权限体系完美对接。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TicketIdentityService {
|
||||
// /**
|
||||
// * 工单用户和组管理
|
||||
// * 使用场景:
|
||||
// *
|
||||
// * 用户管理:
|
||||
// * 同步业务系统用户到 Flowable
|
||||
// * 管理用户信息和状态
|
||||
// * 用户认证和授权
|
||||
// *
|
||||
// * 组管理:
|
||||
// * 同步业务系统组织架构
|
||||
// * 管理工作组和角色
|
||||
// * 权限分配
|
||||
// *
|
||||
// * 关系管理:
|
||||
// * 维护用户和组的关系
|
||||
// * 支持多组织架构
|
||||
// * 灵活的权限控制
|
||||
// *
|
||||
// * 这样就能将业务系统的用户和组织架构与 Flowable 的工作流权限体系完美对接。
|
||||
// */
|
||||
// @Slf4j
|
||||
// @Service
|
||||
// @RequiredArgsConstructor
|
||||
// public class TicketIdentityService {
|
||||
|
||||
// private final LDAPIdentityServiceImpl ldapIdentityService;
|
||||
private final IdmIdentityService identityService;
|
||||
// private final AgentRestService agentService;
|
||||
// private final WorkgroupRestService workgroupService;
|
||||
// // private final LDAPIdentityServiceImpl ldapIdentityService;
|
||||
// private final IdmIdentityService identityService;
|
||||
// // private final AgentRestService agentService;
|
||||
// // private final WorkgroupRestService workgroupService;
|
||||
|
||||
/**
|
||||
* 同步用户到Flowable
|
||||
*/
|
||||
public void syncUser(AgentEntity agent) {
|
||||
// 检查用户是否存在
|
||||
User flowableUser = identityService.createUserQuery()
|
||||
.userId(agent.getUid())
|
||||
.singleResult();
|
||||
// /**
|
||||
// * 同步用户到Flowable
|
||||
// */
|
||||
// public void syncUser(AgentEntity agent) {
|
||||
// // 检查用户是否存在
|
||||
// User flowableUser = identityService.createUserQuery()
|
||||
// .userId(agent.getUid())
|
||||
// .singleResult();
|
||||
|
||||
if (flowableUser == null) {
|
||||
// 创建新用户
|
||||
flowableUser = identityService.newUser(agent.getUid());
|
||||
}
|
||||
// if (flowableUser == null) {
|
||||
// // 创建新用户
|
||||
// flowableUser = identityService.newUser(agent.getUid());
|
||||
// }
|
||||
|
||||
// 更新用户信息
|
||||
flowableUser.setFirstName(agent.getNickname());
|
||||
flowableUser.setEmail(agent.getEmail());
|
||||
identityService.saveUser(flowableUser);
|
||||
// // 更新用户信息
|
||||
// flowableUser.setFirstName(agent.getNickname());
|
||||
// flowableUser.setEmail(agent.getEmail());
|
||||
// identityService.saveUser(flowableUser);
|
||||
|
||||
log.info("Synced user: {}", agent.getUid());
|
||||
}
|
||||
// log.info("Synced user: {}", agent.getUid());
|
||||
// }
|
||||
|
||||
/**
|
||||
* 同步工作组到Flowable
|
||||
*/
|
||||
public void syncWorkgroup(WorkgroupEntity workgroup) {
|
||||
// 检查组是否存在
|
||||
Group flowableGroup = identityService.createGroupQuery()
|
||||
.groupId(workgroup.getUid())
|
||||
.singleResult();
|
||||
// /**
|
||||
// * 同步工作组到Flowable
|
||||
// */
|
||||
// public void syncWorkgroup(WorkgroupEntity workgroup) {
|
||||
// // 检查组是否存在
|
||||
// Group flowableGroup = identityService.createGroupQuery()
|
||||
// .groupId(workgroup.getUid())
|
||||
// .singleResult();
|
||||
|
||||
if (flowableGroup == null) {
|
||||
// 创建新组
|
||||
flowableGroup = identityService.newGroup(workgroup.getUid());
|
||||
}
|
||||
// if (flowableGroup == null) {
|
||||
// // 创建新组
|
||||
// flowableGroup = identityService.newGroup(workgroup.getUid());
|
||||
// }
|
||||
|
||||
// 更新组信息
|
||||
flowableGroup.setName(workgroup.getNickname());
|
||||
flowableGroup.setType("assignment");
|
||||
identityService.saveGroup(flowableGroup);
|
||||
// // 更新组信息
|
||||
// flowableGroup.setName(workgroup.getNickname());
|
||||
// flowableGroup.setType("assignment");
|
||||
// identityService.saveGroup(flowableGroup);
|
||||
|
||||
log.info("Synced group: {}", workgroup.getUid());
|
||||
}
|
||||
// log.info("Synced group: {}", workgroup.getUid());
|
||||
// }
|
||||
|
||||
/**
|
||||
* 使用最小信息同步工作组(避免在事件中传输实体)
|
||||
*/
|
||||
public void syncWorkgroupByBasic(String workgroupUid, String nickname) {
|
||||
Group flowableGroup = identityService.createGroupQuery()
|
||||
.groupId(workgroupUid)
|
||||
.singleResult();
|
||||
// /**
|
||||
// * 使用最小信息同步工作组(避免在事件中传输实体)
|
||||
// */
|
||||
// public void syncWorkgroupByBasic(String workgroupUid, String nickname) {
|
||||
// Group flowableGroup = identityService.createGroupQuery()
|
||||
// .groupId(workgroupUid)
|
||||
// .singleResult();
|
||||
|
||||
if (flowableGroup == null) {
|
||||
flowableGroup = identityService.newGroup(workgroupUid);
|
||||
}
|
||||
// if (flowableGroup == null) {
|
||||
// flowableGroup = identityService.newGroup(workgroupUid);
|
||||
// }
|
||||
|
||||
flowableGroup.setName(nickname);
|
||||
flowableGroup.setType("assignment");
|
||||
identityService.saveGroup(flowableGroup);
|
||||
// flowableGroup.setName(nickname);
|
||||
// flowableGroup.setType("assignment");
|
||||
// identityService.saveGroup(flowableGroup);
|
||||
|
||||
log.info("Synced group (basic): {}", workgroupUid);
|
||||
}
|
||||
// log.info("Synced group (basic): {}", workgroupUid);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 同步用户和工作组的关系
|
||||
*/
|
||||
public void syncMembership(String userId, String groupId) {
|
||||
// 添加用户到组
|
||||
identityService.createMembership(userId, groupId);
|
||||
log.info("Synced membership: {} -> {}", userId, groupId);
|
||||
}
|
||||
// /**
|
||||
// * 同步用户和工作组的关系
|
||||
// */
|
||||
// public void syncMembership(String userId, String groupId) {
|
||||
// // 添加用户到组
|
||||
// identityService.createMembership(userId, groupId);
|
||||
// log.info("Synced membership: {} -> {}", userId, groupId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取用户
|
||||
*/
|
||||
public User getUser(String userId) {
|
||||
return identityService.createUserQuery()
|
||||
.userId(userId)
|
||||
.singleResult();
|
||||
}
|
||||
// /**
|
||||
// * 获取用户
|
||||
// */
|
||||
// public User getUser(String userId) {
|
||||
// return identityService.createUserQuery()
|
||||
// .userId(userId)
|
||||
// .singleResult();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取组
|
||||
*/
|
||||
public Group getGroup(String groupId) {
|
||||
return identityService.createGroupQuery()
|
||||
.groupId(groupId)
|
||||
.singleResult();
|
||||
}
|
||||
// /**
|
||||
// * 获取组
|
||||
// */
|
||||
// public Group getGroup(String groupId) {
|
||||
// return identityService.createGroupQuery()
|
||||
// .groupId(groupId)
|
||||
// .singleResult();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 查询用户所在的所有组
|
||||
*/
|
||||
public List<Group> getUserGroups(String userId) {
|
||||
return identityService.createGroupQuery()
|
||||
.groupMember(userId)
|
||||
.list();
|
||||
}
|
||||
// /**
|
||||
// * 查询用户所在的所有组
|
||||
// */
|
||||
// public List<Group> getUserGroups(String userId) {
|
||||
// return identityService.createGroupQuery()
|
||||
// .groupMember(userId)
|
||||
// .list();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 查询组内的所有用户
|
||||
*/
|
||||
public List<User> getGroupUsers(String groupId) {
|
||||
return identityService.createUserQuery()
|
||||
.memberOfGroup(groupId)
|
||||
.list();
|
||||
}
|
||||
// /**
|
||||
// * 查询组内的所有用户
|
||||
// */
|
||||
// public List<User> getGroupUsers(String groupId) {
|
||||
// return identityService.createUserQuery()
|
||||
// .memberOfGroup(groupId)
|
||||
// .list();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 检查用户是否在指定组中
|
||||
*/
|
||||
public Boolean isUserInGroup(String userId, String groupId) {
|
||||
return identityService.createGroupQuery()
|
||||
.groupId(groupId)
|
||||
.groupMember(userId)
|
||||
.count() > 0;
|
||||
}
|
||||
// /**
|
||||
// * 检查用户是否在指定组中
|
||||
// */
|
||||
// public Boolean isUserInGroup(String userId, String groupId) {
|
||||
// return identityService.createGroupQuery()
|
||||
// .groupId(groupId)
|
||||
// .groupMember(userId)
|
||||
// .count() > 0;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
public void deleteUser(String userId) {
|
||||
identityService.deleteUser(userId);
|
||||
log.info("Deleted user: {}", userId);
|
||||
}
|
||||
// /**
|
||||
// * 删除用户
|
||||
// */
|
||||
// public void deleteUser(String userId) {
|
||||
// identityService.deleteUser(userId);
|
||||
// log.info("Deleted user: {}", userId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除工作组
|
||||
*/
|
||||
public void deleteGroup(String groupId) {
|
||||
identityService.deleteGroup(groupId);
|
||||
log.info("Deleted group: {}", groupId);
|
||||
}
|
||||
// /**
|
||||
// * 删除工作组
|
||||
// */
|
||||
// public void deleteGroup(String groupId) {
|
||||
// identityService.deleteGroup(groupId);
|
||||
// log.info("Deleted group: {}", groupId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除用户和组的关系
|
||||
*/
|
||||
public void deleteMembership(String userId, String groupId) {
|
||||
identityService.deleteMembership(userId, groupId);
|
||||
log.info("Deleted membership: {} -> {}", userId, groupId);
|
||||
}
|
||||
// /**
|
||||
// * 删除用户和组的关系
|
||||
// */
|
||||
// public void deleteMembership(String userId, String groupId) {
|
||||
// identityService.deleteMembership(userId, groupId);
|
||||
// log.info("Deleted membership: {} -> {}", userId, groupId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 检查用户认证状态
|
||||
*/
|
||||
public Boolean checkAuthentication(String userId) {
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (auth == null || !auth.isAuthenticated()) {
|
||||
return false;
|
||||
}
|
||||
return auth.getName().equals(userId);
|
||||
}
|
||||
// /**
|
||||
// * 检查用户认证状态
|
||||
// */
|
||||
// public Boolean checkAuthentication(String userId) {
|
||||
// Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
// if (auth == null || !auth.isAuthenticated()) {
|
||||
// return false;
|
||||
// }
|
||||
// return auth.getName().equals(userId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 为用户添加权限
|
||||
*/
|
||||
public void addUserPrivilege(String userId, String privilegeName) {
|
||||
// 创建权限(如果不存在)
|
||||
Privilege privilege = identityService.createPrivilegeQuery()
|
||||
.privilegeName(privilegeName)
|
||||
.singleResult();
|
||||
// /**
|
||||
// * 为用户添加权限
|
||||
// */
|
||||
// public void addUserPrivilege(String userId, String privilegeName) {
|
||||
// // 创建权限(如果不存在)
|
||||
// Privilege privilege = identityService.createPrivilegeQuery()
|
||||
// .privilegeName(privilegeName)
|
||||
// .singleResult();
|
||||
|
||||
if (privilege == null) {
|
||||
privilege = identityService.createPrivilege(privilegeName);
|
||||
}
|
||||
// if (privilege == null) {
|
||||
// privilege = identityService.createPrivilege(privilegeName);
|
||||
// }
|
||||
|
||||
// 为用户添加权限
|
||||
identityService.addUserPrivilegeMapping(privilege.getId(), userId);
|
||||
log.info("Added privilege {} to user {}", privilegeName, userId);
|
||||
}
|
||||
// // 为用户添加权限
|
||||
// identityService.addUserPrivilegeMapping(privilege.getId(), userId);
|
||||
// log.info("Added privilege {} to user {}", privilegeName, userId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 为组添加权限
|
||||
*/
|
||||
public void addGroupPrivilege(String groupId, String privilegeName) {
|
||||
Privilege privilege = identityService.createPrivilegeQuery()
|
||||
.privilegeName(privilegeName)
|
||||
.singleResult();
|
||||
// /**
|
||||
// * 为组添加权限
|
||||
// */
|
||||
// public void addGroupPrivilege(String groupId, String privilegeName) {
|
||||
// Privilege privilege = identityService.createPrivilegeQuery()
|
||||
// .privilegeName(privilegeName)
|
||||
// .singleResult();
|
||||
|
||||
if (privilege == null) {
|
||||
privilege = identityService.createPrivilege(privilegeName);
|
||||
}
|
||||
// if (privilege == null) {
|
||||
// privilege = identityService.createPrivilege(privilegeName);
|
||||
// }
|
||||
|
||||
identityService.addGroupPrivilegeMapping(privilege.getId(), groupId);
|
||||
log.info("Added privilege {} to group {}", privilegeName, groupId);
|
||||
}
|
||||
// identityService.addGroupPrivilegeMapping(privilege.getId(), groupId);
|
||||
// log.info("Added privilege {} to group {}", privilegeName, groupId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取用户的所有权限
|
||||
*/
|
||||
public List<Privilege> getUserPrivileges(String userId) {
|
||||
return identityService.createPrivilegeQuery()
|
||||
.userId(userId)
|
||||
.list();
|
||||
}
|
||||
// /**
|
||||
// * 获取用户的所有权限
|
||||
// */
|
||||
// public List<Privilege> getUserPrivileges(String userId) {
|
||||
// return identityService.createPrivilegeQuery()
|
||||
// .userId(userId)
|
||||
// .list();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 检查用户是否有指定权限
|
||||
*/
|
||||
public Boolean hasPrivilege(String userId, String privilegeName) {
|
||||
return identityService.createPrivilegeQuery()
|
||||
.userId(userId)
|
||||
.privilegeName(privilegeName)
|
||||
.count() > 0;
|
||||
}
|
||||
// /**
|
||||
// * 检查用户是否有指定权限
|
||||
// */
|
||||
// public Boolean hasPrivilege(String userId, String privilegeName) {
|
||||
// return identityService.createPrivilegeQuery()
|
||||
// .userId(userId)
|
||||
// .privilegeName(privilegeName)
|
||||
// .count() > 0;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除用户权限
|
||||
*/
|
||||
public void removeUserPrivilege(String userId, String privilegeName) {
|
||||
Privilege privilege = identityService.createPrivilegeQuery()
|
||||
.privilegeName(privilegeName)
|
||||
.singleResult();
|
||||
// /**
|
||||
// * 删除用户权限
|
||||
// */
|
||||
// public void removeUserPrivilege(String userId, String privilegeName) {
|
||||
// Privilege privilege = identityService.createPrivilegeQuery()
|
||||
// .privilegeName(privilegeName)
|
||||
// .singleResult();
|
||||
|
||||
if (privilege != null) {
|
||||
identityService.deleteUserPrivilegeMapping(privilege.getId(), userId);
|
||||
log.info("Removed privilege {} from user {}", privilegeName, userId);
|
||||
}
|
||||
}
|
||||
// if (privilege != null) {
|
||||
// identityService.deleteUserPrivilegeMapping(privilege.getId(), userId);
|
||||
// log.info("Removed privilege {} from user {}", privilegeName, userId);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 删除组权限
|
||||
*/
|
||||
public void removeGroupPrivilege(String groupId, String privilegeName) {
|
||||
Privilege privilege = identityService.createPrivilegeQuery()
|
||||
.privilegeName(privilegeName)
|
||||
.singleResult();
|
||||
// /**
|
||||
// * 删除组权限
|
||||
// */
|
||||
// public void removeGroupPrivilege(String groupId, String privilegeName) {
|
||||
// Privilege privilege = identityService.createPrivilegeQuery()
|
||||
// .privilegeName(privilegeName)
|
||||
// .singleResult();
|
||||
|
||||
if (privilege != null) {
|
||||
identityService.deleteGroupPrivilegeMapping(privilege.getId(), groupId);
|
||||
log.info("Removed privilege {} from group {}", privilegeName, groupId);
|
||||
}
|
||||
}
|
||||
// if (privilege != null) {
|
||||
// identityService.deleteGroupPrivilegeMapping(privilege.getId(), groupId);
|
||||
// log.info("Removed privilege {} from group {}", privilegeName, groupId);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取用户的Spring Security权限
|
||||
*/
|
||||
public List<SimpleGrantedAuthority> getUserAuthorities(String userId) {
|
||||
List<SimpleGrantedAuthority> authorities = new ArrayList<>();
|
||||
// /**
|
||||
// * 获取用户的Spring Security权限
|
||||
// */
|
||||
// public List<SimpleGrantedAuthority> getUserAuthorities(String userId) {
|
||||
// List<SimpleGrantedAuthority> authorities = new ArrayList<>();
|
||||
|
||||
// 添加用户直接权限
|
||||
List<Privilege> userPrivileges = getUserPrivileges(userId);
|
||||
for (Privilege privilege : userPrivileges) {
|
||||
authorities.add(new SimpleGrantedAuthority(privilege.getName()));
|
||||
}
|
||||
// // 添加用户直接权限
|
||||
// List<Privilege> userPrivileges = getUserPrivileges(userId);
|
||||
// for (Privilege privilege : userPrivileges) {
|
||||
// authorities.add(new SimpleGrantedAuthority(privilege.getName()));
|
||||
// }
|
||||
|
||||
// 添加用户组权限
|
||||
List<Group> userGroups = getUserGroups(userId);
|
||||
for (Group group : userGroups) {
|
||||
authorities.add(new SimpleGrantedAuthority("GROUP_" + group.getId()));
|
||||
}
|
||||
// // 添加用户组权限
|
||||
// List<Group> userGroups = getUserGroups(userId);
|
||||
// for (Group group : userGroups) {
|
||||
// authorities.add(new SimpleGrantedAuthority("GROUP_" + group.getId()));
|
||||
// }
|
||||
|
||||
return authorities;
|
||||
}
|
||||
// return authorities;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 从LDAP同步用户
|
||||
*/
|
||||
public void syncUserFromLDAP(String userId) {
|
||||
// User ldapUser = ldapIdentityService.findUserById(userId);
|
||||
// if (ldapUser != null) {
|
||||
// User flowableUser = identityService.newUser(ldapUser.getId());
|
||||
// flowableUser.setFirstName(ldapUser.getFirstName());
|
||||
// flowableUser.setLastName(ldapUser.getLastName());
|
||||
// flowableUser.setEmail(ldapUser.getEmail());
|
||||
// identityService.saveUser(flowableUser);
|
||||
// /**
|
||||
// * 从LDAP同步用户
|
||||
// */
|
||||
// public void syncUserFromLDAP(String userId) {
|
||||
// // User ldapUser = ldapIdentityService.findUserById(userId);
|
||||
// // if (ldapUser != null) {
|
||||
// // User flowableUser = identityService.newUser(ldapUser.getId());
|
||||
// // flowableUser.setFirstName(ldapUser.getFirstName());
|
||||
// // flowableUser.setLastName(ldapUser.getLastName());
|
||||
// // flowableUser.setEmail(ldapUser.getEmail());
|
||||
// // identityService.saveUser(flowableUser);
|
||||
|
||||
// // 同步用户组
|
||||
// List<Group> ldapGroups = ldapIdentityService.findGroupsByUser(userId);
|
||||
// for (Group ldapGroup : ldapGroups) {
|
||||
// syncGroupFromLDAP(ldapGroup.getId());
|
||||
// identityService.createMembership(userId, ldapGroup.getId());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// // // 同步用户组
|
||||
// // List<Group> ldapGroups = ldapIdentityService.findGroupsByUser(userId);
|
||||
// // for (Group ldapGroup : ldapGroups) {
|
||||
// // syncGroupFromLDAP(ldapGroup.getId());
|
||||
// // identityService.createMembership(userId, ldapGroup.getId());
|
||||
// // }
|
||||
// // }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 从LDAP同步组
|
||||
*/
|
||||
public void syncGroupFromLDAP(String groupId) {
|
||||
// Group ldapGroup = ldapIdentityService.findGroupById(groupId);
|
||||
// if (ldapGroup != null) {
|
||||
// Group flowableGroup = identityService.newGroup(ldapGroup.getId());
|
||||
// flowableGroup.setName(ldapGroup.getName());
|
||||
// flowableGroup.setType("assignment");
|
||||
// identityService.saveGroup(flowableGroup);
|
||||
// }
|
||||
}
|
||||
// /**
|
||||
// * 从LDAP同步组
|
||||
// */
|
||||
// public void syncGroupFromLDAP(String groupId) {
|
||||
// // Group ldapGroup = ldapIdentityService.findGroupById(groupId);
|
||||
// // if (ldapGroup != null) {
|
||||
// // Group flowableGroup = identityService.newGroup(ldapGroup.getId());
|
||||
// // flowableGroup.setName(ldapGroup.getName());
|
||||
// // flowableGroup.setType("assignment");
|
||||
// // identityService.saveGroup(flowableGroup);
|
||||
// // }
|
||||
// }
|
||||
|
||||
/**
|
||||
* LDAP认证
|
||||
*/
|
||||
public Boolean authenticate(String userId, String password) {
|
||||
// return ldapIdentityService.checkPassword(userId, password);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * LDAP认证
|
||||
// */
|
||||
// public Boolean authenticate(String userId, String password) {
|
||||
// // return ldapIdentityService.checkPassword(userId, password);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
@@ -13,30 +13,30 @@
|
||||
*/
|
||||
package com.bytedesk.ticket.identity;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
// import org.springframework.beans.factory.InitializingBean;
|
||||
// import org.springframework.stereotype.Component;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
// import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class TicketPrivilegeInitializer implements InitializingBean {
|
||||
// @Component
|
||||
// @RequiredArgsConstructor
|
||||
// public class TicketPrivilegeInitializer implements InitializingBean {
|
||||
|
||||
// private final TicketIdentityService identityService;
|
||||
// // private final TicketIdentityService identityService;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
// 初始化系统权限
|
||||
initializePrivileges();
|
||||
}
|
||||
// @Override
|
||||
// public void afterPropertiesSet() {
|
||||
// // 初始化系统权限
|
||||
// initializePrivileges();
|
||||
// }
|
||||
|
||||
private void initializePrivileges() {
|
||||
// 为主管组添加权限
|
||||
// identityService.addGroupPrivilege("supervisors", "TICKET_MANAGE");
|
||||
// identityService.addGroupPrivilege("supervisors", "TICKET_ASSIGN");
|
||||
// private void initializePrivileges() {
|
||||
// // 为主管组添加权限
|
||||
// // identityService.addGroupPrivilege("supervisors", "TICKET_MANAGE");
|
||||
// // identityService.addGroupPrivilege("supervisors", "TICKET_ASSIGN");
|
||||
|
||||
// 为客服组添加权限
|
||||
// identityService.addGroupPrivilege("agents", "TICKET_CREATE");
|
||||
// identityService.addGroupPrivilege("agents", "TICKET_HANDLE");
|
||||
}
|
||||
}
|
||||
// // 为客服组添加权限
|
||||
// // identityService.addGroupPrivilege("agents", "TICKET_CREATE");
|
||||
// // identityService.addGroupPrivilege("agents", "TICKET_HANDLE");
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user