mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 12:39:05 +08:00
🐛 oauth 封装,直接获取用户名为空问题修复
This commit is contained in:
1 parent
910739c090
commit
e0d9cce2fd
6 files changed
+9
-35
No files matched your search
-26
@@ -62,37 +62,11 @@ public class SecurityUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用名
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getUsername() {
|
||||
Object principal = getAuthentication().getPrincipal();
|
||||
if (principal instanceof String) {
|
||||
return principal.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String getClientId() {
|
||||
Authentication authentication = getAuthentication();
|
||||
if (authentication instanceof OAuth2Authentication) {
|
||||
OAuth2Authentication auth2Authentication = (OAuth2Authentication) authentication;
|
||||
return auth2Authentication.getOAuth2Request().getClientId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户
|
||||
*/
|
||||
public PigxUser getUser() {
|
||||
Authentication authentication = getAuthentication();
|
||||
if (authentication == null) {
|
||||
return null;
|
||||
}
|
||||
return getUser(authentication);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ import java.util.Objects;
|
||||
/**
|
||||
* @author lengleng
|
||||
* <p>
|
||||
* fallBack 代理处理
|
||||
* fallback 代理处理
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ public class LeaveBillController {
|
||||
*/
|
||||
@PostMapping
|
||||
public R save(@RequestBody LeaveBill leaveBill) {
|
||||
leaveBill.setUsername(SecurityUtils.getUsername());
|
||||
leaveBill.setUsername(SecurityUtils.getUser().getUsername());
|
||||
leaveBill.setState(TaskStatusEnum.UNSUBMIT.getStatus());
|
||||
return new R<>(leaveBillService.save(leaveBill));
|
||||
}
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ public class TaskController {
|
||||
|
||||
@GetMapping("/todo")
|
||||
public R todo(@RequestParam Map<String, Object> params) {
|
||||
return new R<>(actTaskService.getTaskByName(params, SecurityUtils.getUsername()));
|
||||
return new R<>(actTaskService.getTaskByName(params, SecurityUtils.getUser().getUsername()));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
|
||||
+5
-5
@@ -51,13 +51,13 @@ public class LeaveProcessTaskListener implements TaskListener {
|
||||
SimpMessagingTemplate simpMessagingTemplate = SpringContextHolder.getBean(SimpMessagingTemplate.class);
|
||||
RemoteUserService userService = SpringContextHolder.getBean(RemoteUserService.class);
|
||||
|
||||
R<List<SysUser>> result = userService.ancestorUsers(SecurityUtils.getUsername());
|
||||
R<List<SysUser>> result = userService.ancestorUsers(SecurityUtils.getUser().getUsername());
|
||||
List<String> remindUserList = new ArrayList<>();
|
||||
|
||||
if (CollUtil.isEmpty(result.getData())) {
|
||||
log.info("用户 {} 不存在上级,任务单由当前用户审批", SecurityUtils.getUsername());
|
||||
delegateTask.addCandidateUser(SecurityUtils.getUsername());
|
||||
remindUserList.add(SecurityUtils.getUsername());
|
||||
log.info("用户 {} 不存在上级,任务单由当前用户审批", SecurityUtils.getUser().getUsername());
|
||||
delegateTask.addCandidateUser(SecurityUtils.getUser().getUsername());
|
||||
remindUserList.add(SecurityUtils.getUser().getUsername());
|
||||
} else {
|
||||
List<String> userList = result.getData().stream().map(SysUser::getUsername).collect(Collectors.toList());
|
||||
log.info("当前任务 {},由 {}处理", delegateTask.getId(), userList);
|
||||
@@ -66,7 +66,7 @@ public class LeaveProcessTaskListener implements TaskListener {
|
||||
}
|
||||
|
||||
remindUserList.forEach(user -> {
|
||||
String target = String.format("%s-%s", SecurityUtils.getUsername(), TenantContextHolder.getTenantId());
|
||||
String target = String.format("%s-%s", SecurityUtils.getUser().getUsername(), TenantContextHolder.getTenantId());
|
||||
simpMessagingTemplate.convertAndSendToUser(target, "/remind", delegateTask.getName());
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ public class ActTaskServiceImpl implements ActTaskService {
|
||||
.singleResult();
|
||||
|
||||
String processInstanceId = task.getProcessInstanceId();
|
||||
Authentication.setAuthenticatedUserId(SecurityUtils.getUsername());
|
||||
Authentication.setAuthenticatedUserId(SecurityUtils.getUser().getUsername());
|
||||
taskService.addComment(taskId, processInstanceId, message);
|
||||
|
||||
Map<String, Object> variables = new HashMap<>(1);
|
||||
|
||||
Reference in new issue
Block a user