|
|
@@ -16,6 +16,7 @@ import org.springframework.security.core.Authentication; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
@@ -47,21 +48,24 @@ public class AuthorizationEventListener { |
|
|
|
Authentication authentication = event.getAuthentication(); |
|
|
|
UserInfoDetails userDetails = (UserInfoDetails) authentication.getPrincipal(); |
|
|
|
WebRequestDetails webDetails = (WebRequestDetails) authentication.getDetails(); |
|
|
|
OptLogDTO log = new OptLogDTO(); |
|
|
|
log.setActionMethod(webDetails.getServletPath()); |
|
|
|
log.setDescription(description); |
|
|
|
log.setStartTime(LocalDateTime.now()); |
|
|
|
log.setFinishTime(log.getStartTime()); |
|
|
|
log.setCreateOn(log.getStartTime()); |
|
|
|
log.setHttpMethod(webDetails.getMethod()); |
|
|
|
log.setUserName(userDetails.getUsername()); |
|
|
|
log.setCreateBy(userDetails.getUserId()); |
|
|
|
log.setRequestIp(webDetails.getRequestIp()); |
|
|
|
log.setRequestUri(webDetails.getRequestUri()); |
|
|
|
log.setRegionByIp(AddressUtil.getRegion(log.getRequestIp())); |
|
|
|
log.setUa(webDetails.getUserAgent()); |
|
|
|
log.setType(LogType.OPT.name()); |
|
|
|
return log; |
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
OptLogDTO optLog = new OptLogDTO(); |
|
|
|
optLog.setActionMethod(webDetails.getServletPath()); |
|
|
|
optLog.setDescription(description); |
|
|
|
optLog.setStartTime(webDetails.getRequestTime()); |
|
|
|
optLog.setFinishTime(now); |
|
|
|
optLog.setCreateOn(now); |
|
|
|
long consumingTime = ChronoUnit.MILLIS.between(optLog.getStartTime(), optLog.getFinishTime()); |
|
|
|
optLog.setConsumingTime(consumingTime); |
|
|
|
optLog.setHttpMethod(webDetails.getMethod()); |
|
|
|
optLog.setUserName(userDetails.getUsername()); |
|
|
|
optLog.setCreateBy(userDetails.getUserId()); |
|
|
|
optLog.setRequestIp(webDetails.getRequestIp()); |
|
|
|
optLog.setRequestUri(webDetails.getRequestUri()); |
|
|
|
optLog.setRegionByIp(AddressUtil.getRegion(optLog.getRequestIp())); |
|
|
|
optLog.setUa(webDetails.getUserAgent()); |
|
|
|
optLog.setType(LogType.OPT.name()); |
|
|
|
return optLog; |
|
|
|
} |
|
|
|
|
|
|
|
} |