Skip to content

Commit

Permalink
Merge branch 'jdk17' into jdk17-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lltx committed Dec 4, 2024
2 parents ae6fda3 + 092ae11 commit 27ac5fd
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package com.pig4cloud.pig.auth.support.handler;

import cn.hutool.core.util.StrUtil;
import com.pig4cloud.pig.admin.api.entity.SysLog;
import com.pig4cloud.pig.common.core.constant.CommonConstants;
import com.pig4cloud.pig.common.core.util.SpringContextHolder;
import com.pig4cloud.pig.common.core.util.WebUtils;
import com.pig4cloud.pig.common.log.event.SysLogEvent;
Expand Down Expand Up @@ -57,19 +59,25 @@ public void handle(Authentication authentication) {
log.info("用户:{} 退出成功", authentication.getPrincipal());
SysLog logVo = SysLogUtils.getSysLog();
logVo.setTitle("退出成功");
// 发送异步日志事件
Long startTime = System.currentTimeMillis();
Long endTime = System.currentTimeMillis();
logVo.setTime(endTime - startTime);

// 设置对应的token
WebUtils.getRequest().ifPresent(request -> logVo.setParams(request.getHeader(HttpHeaders.AUTHORIZATION)));
WebUtils.getRequest().ifPresent(request -> {
logVo.setParams(request.getHeader(HttpHeaders.AUTHORIZATION));
// 计算请求耗时
String startTimeStr = request.getHeader(CommonConstants.REQUEST_START_TIME);
if (StrUtil.isNotBlank(startTimeStr)) {
Long startTime = Long.parseLong(startTimeStr);
Long endTime = System.currentTimeMillis();
logVo.setTime(endTime - startTime);
}
});

// 这边设置ServiceId
if (authentication instanceof PreAuthenticatedAuthenticationToken) {
logVo.setServiceId(authentication.getCredentials().toString());
}
logVo.setCreateBy(authentication.getName());
// 发送异步日志事件
SpringContextHolder.publishEvent(new SysLogEvent(logVo));
}

Expand Down

0 comments on commit 27ac5fd

Please sign in to comment.