Browse Source

👣 完成锁屏功能

master
wangxiang 3 years ago
parent
commit
f02cfb7739
  1. 17
      kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccAuthenticationFailureEventHandler.java
  2. 14
      kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccAuthenticationSuccessEventHandler.java
  3. 23
      kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccLogoutSuccessEventHandler.java
  4. 14
      kicc-common/kicc-common-log/src/main/java/com/cloud/kicc/common/log/aspect/SysLogAspect.java
  5. 16
      kicc-common/kicc-common-log/src/main/java/com/cloud/kicc/common/log/util/SysLogUtils.java
  6. 1
      kicc-ui/src/store/modules/lock.ts
  7. 2
      kicc-ui/src/store/modules/user.ts

17
kicc-auth/src/main/java/com/cloud/kicc/auth/handler/kiccAuthenticationFailureEventHandler.java → kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccAuthenticationFailureEventHandler.java

@ -26,7 +26,7 @@ import java.util.Optional;
*/ */
@Slf4j @Slf4j
@Component @Component
public class kiccAuthenticationFailureEventHandler extends AbstractAuthenticationFailureEventHandler { public class KiccAuthenticationFailureEventHandler extends AbstractAuthenticationFailureEventHandler {
/** /**
* 处理登录失败方法 * 处理登录失败方法
@ -36,27 +36,16 @@ public class kiccAuthenticationFailureEventHandler extends AbstractAuthenticatio
*/ */
@Override @Override
public void handle(AuthenticationException authenticationException, Authentication authentication) { public void handle(AuthenticationException authenticationException, Authentication authentication) {
Long startTime = System.currentTimeMillis();
log.info("用户:{} 登录失败,异常:{}", authentication.getPrincipal(), authenticationException.getLocalizedMessage()); log.info("用户:{} 登录失败,异常:{}", authentication.getPrincipal(), authenticationException.getLocalizedMessage());
SecurityContextHolder.getContext().setAuthentication(authentication); SecurityContextHolder.getContext().setAuthentication(authentication);
KiccUser kiccUser = SecurityUtils.getUser(authentication);
OperLog operLog = SysLogUtils.getSysLog(); OperLog operLog = SysLogUtils.getSysLog();
operLog.setTitle("登录失败"); operLog.setTitle("登录失败");
operLog.setType(LogTypeEnum.ERROR.getType()); operLog.setType(LogTypeEnum.ERROR.getType());
operLog.setErrorMsg(authenticationException.getMessage()); operLog.setErrorMsg(authenticationException.getMessage());
operLog.setOperName(kiccUser.getUsername());
// 发送异步日志事件
Long startTime = System.currentTimeMillis();
Long endTime = System.currentTimeMillis(); Long endTime = System.currentTimeMillis();
operLog.setExecuteTime((endTime - startTime) + "毫秒"); operLog.setExecuteTime((endTime - startTime) + "毫秒");
// 发送异步日志事件
if (Optional.ofNullable(kiccUser).isPresent()) {
operLog.setCreateById(kiccUser.getId());
operLog.setCreateByName(kiccUser.getUsername());
operLog.setUpdateById(kiccUser.getId());
operLog.setUpdateByName(kiccUser.getUsername());
}
SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog)); SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog));
} }

14
kicc-auth/src/main/java/com/cloud/kicc/auth/handler/kiccAuthenticationSuccessEventHandler.java → kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccAuthenticationSuccessEventHandler.java

@ -24,7 +24,7 @@ import java.util.Optional;
*/ */
@Slf4j @Slf4j
@Component @Component
public class kiccAuthenticationSuccessEventHandler extends AbstractAuthenticationSuccessEventHandler { public class KiccAuthenticationSuccessEventHandler extends AbstractAuthenticationSuccessEventHandler {
/** /**
* 处理登录成功方法 * 处理登录成功方法
@ -34,22 +34,14 @@ public class kiccAuthenticationSuccessEventHandler extends AbstractAuthenticatio
*/ */
@Override @Override
public void handle(Authentication authentication) { public void handle(Authentication authentication) {
Long startTime = System.currentTimeMillis();
log.info("用户:{} 登录成功", authentication.getPrincipal()); log.info("用户:{} 登录成功", authentication.getPrincipal());
SecurityContextHolder.getContext().setAuthentication(authentication); SecurityContextHolder.getContext().setAuthentication(authentication);
OperLog operLog = SysLogUtils.getSysLog(); OperLog operLog = SysLogUtils.getSysLog();
operLog.setTitle("登录成功"); operLog.setTitle("登录成功");
// 发送异步日志事件
Long startTime = System.currentTimeMillis();
KiccUser kiccUser = SecurityUtils.getUser(authentication);
if (Optional.ofNullable(kiccUser).isPresent()) {
operLog.setCreateById(kiccUser.getId());
operLog.setCreateByName(kiccUser.getUsername());
operLog.setUpdateById(kiccUser.getId());
operLog.setUpdateByName(kiccUser.getUsername());
}
Long endTime = System.currentTimeMillis(); Long endTime = System.currentTimeMillis();
operLog.setExecuteTime((endTime - startTime) + "毫秒"); operLog.setExecuteTime((endTime - startTime) + "毫秒");
// 发送异步日志事件
SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog)); SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog));
} }

23
kicc-auth/src/main/java/com/cloud/kicc/auth/handler/kiccLogoutSuccessEventHandler.java → kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccLogoutSuccessEventHandler.java

@ -27,7 +27,7 @@ import java.util.Optional;
*/ */
@Slf4j @Slf4j
@Component @Component
public class kiccLogoutSuccessEventHandler extends AbstractLogoutSuccessEventHandler { public class KiccLogoutSuccessEventHandler extends AbstractLogoutSuccessEventHandler {
/** /**
* 处理退出成功方法 * 处理退出成功方法
@ -37,34 +37,21 @@ public class kiccLogoutSuccessEventHandler extends AbstractLogoutSuccessEventHan
*/ */
@Override @Override
public void handle(Authentication authentication) { public void handle(Authentication authentication) {
Long startTime = System.currentTimeMillis();
log.info("用户:{} 退出成功", authentication.getPrincipal()); log.info("用户:{} 退出成功", authentication.getPrincipal());
SecurityContextHolder.getContext().setAuthentication(authentication); SecurityContextHolder.getContext().setAuthentication(authentication);
KiccUser kiccUser = SecurityUtils.getUser(authentication);
OperLog operLog = SysLogUtils.getSysLog(); OperLog operLog = SysLogUtils.getSysLog();
operLog.setTitle("退出成功"); operLog.setTitle("退出成功");
// 发送异步日志事件
Long startTime = System.currentTimeMillis();
Long endTime = System.currentTimeMillis();
operLog.setExecuteTime((endTime - startTime) + "毫秒");
// 设置对应的token // 设置对应的token
WebUtil.getRequest().ifPresent(request -> operLog.setOperParam(request.getHeader(HttpHeaders.AUTHORIZATION))); WebUtil.getRequest().ifPresent(request -> operLog.setOperParam(request.getHeader(HttpHeaders.AUTHORIZATION)));
// 这边设置ServiceId // 这边设置ServiceId
if (authentication instanceof OAuth2Authentication) { if (authentication instanceof OAuth2Authentication) {
OAuth2Authentication auth2Authentication = (OAuth2Authentication) authentication; OAuth2Authentication auth2Authentication = (OAuth2Authentication) authentication;
operLog.setServiceId(auth2Authentication.getOAuth2Request().getClientId()); operLog.setServiceId(auth2Authentication.getOAuth2Request().getClientId());
} }
Long endTime = System.currentTimeMillis();
if (Optional.ofNullable(kiccUser).isPresent()) { operLog.setExecuteTime((endTime - startTime) + "毫秒");
operLog.setCreateById(kiccUser.getId()); // 发送异步日志事件
operLog.setCreateByName(kiccUser.getUsername());
operLog.setUpdateById(kiccUser.getId());
operLog.setUpdateByName(kiccUser.getUsername());
}
SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog)); SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog));
} }

14
kicc-common/kicc-common-log/src/main/java/com/cloud/kicc/common/log/aspect/SysLogAspect.java

@ -27,31 +27,25 @@ public class SysLogAspect {
@Around("@annotation(sysLog)") @Around("@annotation(sysLog)")
@SneakyThrows @SneakyThrows
public Object around(ProceedingJoinPoint point, SysLog sysLog) { public Object around(ProceedingJoinPoint point, SysLog sysLog) {
Long startTime = System.currentTimeMillis();
String strClassName = point.getTarget().getClass().getName(); String strClassName = point.getTarget().getClass().getName();
String strMethodName = point.getSignature().getName(); String strMethodName = point.getSignature().getName();
log.debug("[类名]:{},[方法]:{}", strClassName, strMethodName); log.debug("[类名]:{},[方法]:{}", strClassName, strMethodName);
OperLog operLog = SysLogUtils.getSysLog(); OperLog operLog = SysLogUtils.getSysLog();
operLog.setTitle(sysLog.value()); operLog.setTitle(sysLog.value());
// 发送异步日志事件
Long startTime = System.currentTimeMillis();
Object obj; Object obj;
try { try {
obj = point.proceed(); obj = point.proceed();
} } catch (Exception e) {
catch (Exception e) {
operLog.setType(LogTypeEnum.ERROR.getType()); operLog.setType(LogTypeEnum.ERROR.getType());
operLog.setErrorMsg(e.getMessage()); operLog.setErrorMsg(e.getMessage());
throw e; throw e;
} } finally {
finally {
Long endTime = System.currentTimeMillis(); Long endTime = System.currentTimeMillis();
operLog.setExecuteTime((endTime - startTime) + "毫秒"); operLog.setExecuteTime((endTime - startTime) + "毫秒");
// 发送异步日志事件
SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog)); SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog));
} }
return obj; return obj;
} }

16
kicc-common/kicc-common-log/src/main/java/com/cloud/kicc/common/log/util/SysLogUtils.java

@ -1,5 +1,6 @@
package com.cloud.kicc.common.log.util; package com.cloud.kicc.common.log.util;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.URLUtil; import cn.hutool.core.util.URLUtil;
import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
@ -35,9 +36,7 @@ public class SysLogUtils {
HttpServletRequest request = ((ServletRequestAttributes) Objects HttpServletRequest request = ((ServletRequestAttributes) Objects
.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); .requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
OperLog sysLog = new OperLog(); OperLog sysLog = new OperLog();
sysLog.setOperIp(ServletUtil.getClientIP(request)); sysLog.setOperIp(ServletUtil.getClientIP(request));
sysLog.setType(LogTypeEnum.NORMAL.getType()); sysLog.setType(LogTypeEnum.NORMAL.getType());
sysLog.setOperAddr(ServletUtil.getClientIP(request)); sysLog.setOperAddr(ServletUtil.getClientIP(request));
sysLog.setOperUrl(URLUtil.getPath(request.getRequestURI())); sysLog.setOperUrl(URLUtil.getPath(request.getRequestURI()));
@ -47,12 +46,13 @@ public class SysLogUtils {
sysLog.setClientId(getClientId(request)); sysLog.setClientId(getClientId(request));
sysLog.setServiceId(getClientId(request)); sysLog.setServiceId(getClientId(request));
sysLog.setOperTime(LocalDateTime.now()); sysLog.setOperTime(LocalDateTime.now());
Objects.requireNonNull(getUser()); if (ObjectUtil.isNotEmpty(getUser())) {
sysLog.setOperName(getUser().getUsername()); sysLog.setOperName(getUser().getUsername());
sysLog.setCreateById(getUser().getId()); sysLog.setCreateById(getUser().getId());
sysLog.setCreateByName(getUser().getUsername()); sysLog.setCreateByName(getUser().getUsername());
sysLog.setUpdateById(getUser().getId()); sysLog.setUpdateById(getUser().getId());
sysLog.setUpdateByName(getUser().getUsername()); sysLog.setUpdateByName(getUser().getUsername());
}
return sysLog; return sysLog;
} }

1
kicc-ui/src/store/modules/lock.ts

@ -56,6 +56,7 @@ export const useLockStore = defineStore({
goHome: false, goHome: false,
unLock: true unLock: true
}); });
debugger
if (res) this.resetLockInfo(); if (res) this.resetLockInfo();
return res; return res;
} catch (error) { } catch (error) {

2
kicc-ui/src/store/modules/user.ts

@ -102,7 +102,7 @@ export const useUserStore = defineStore({
try { try {
const { goHome = true, unLock = false, ...loginParams } = params; const { goHome = true, unLock = false, ...loginParams } = params;
const data = await loginApi(loginParams, unLock && { const data = await loginApi(loginParams, unLock && {
// 使用微服务提供的专属客户端不需要写验证码进行登录 // 使用微服务提供的锁屏专属客户端不需要写验证码进行登录
clientId: 'kicc_lock', clientId: 'kicc_lock',
clientSecret: 'kicc_lock' clientSecret: 'kicc_lock'
}); });

Loading…
Cancel
Save