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

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; @@ -24,7 +24,7 @@ import java.util.Optional;
*/
@Slf4j
@Component
public class kiccAuthenticationSuccessEventHandler extends AbstractAuthenticationSuccessEventHandler {
public class KiccAuthenticationSuccessEventHandler extends AbstractAuthenticationSuccessEventHandler {
/**
* 处理登录成功方法
@ -34,22 +34,14 @@ public class kiccAuthenticationSuccessEventHandler extends AbstractAuthenticatio @@ -34,22 +34,14 @@ public class kiccAuthenticationSuccessEventHandler extends AbstractAuthenticatio
*/
@Override
public void handle(Authentication authentication) {
Long startTime = System.currentTimeMillis();
log.info("用户:{} 登录成功", authentication.getPrincipal());
SecurityContextHolder.getContext().setAuthentication(authentication);
OperLog operLog = SysLogUtils.getSysLog();
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();
operLog.setExecuteTime((endTime - startTime) + "毫秒");
// 发送异步日志事件
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; @@ -27,7 +27,7 @@ import java.util.Optional;
*/
@Slf4j
@Component
public class kiccLogoutSuccessEventHandler extends AbstractLogoutSuccessEventHandler {
public class KiccLogoutSuccessEventHandler extends AbstractLogoutSuccessEventHandler {
/**
* 处理退出成功方法
@ -37,34 +37,21 @@ public class kiccLogoutSuccessEventHandler extends AbstractLogoutSuccessEventHan @@ -37,34 +37,21 @@ public class kiccLogoutSuccessEventHandler extends AbstractLogoutSuccessEventHan
*/
@Override
public void handle(Authentication authentication) {
Long startTime = System.currentTimeMillis();
log.info("用户:{} 退出成功", authentication.getPrincipal());
SecurityContextHolder.getContext().setAuthentication(authentication);
KiccUser kiccUser = SecurityUtils.getUser(authentication);
OperLog operLog = SysLogUtils.getSysLog();
operLog.setTitle("退出成功");
// 发送异步日志事件
Long startTime = System.currentTimeMillis();
Long endTime = System.currentTimeMillis();
operLog.setExecuteTime((endTime - startTime) + "毫秒");
// 设置对应的token
WebUtil.getRequest().ifPresent(request -> operLog.setOperParam(request.getHeader(HttpHeaders.AUTHORIZATION)));
// 这边设置ServiceId
if (authentication instanceof OAuth2Authentication) {
OAuth2Authentication auth2Authentication = (OAuth2Authentication) authentication;
operLog.setServiceId(auth2Authentication.getOAuth2Request().getClientId());
}
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();
operLog.setExecuteTime((endTime - startTime) + "毫秒");
// 发送异步日志事件
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 { @@ -27,31 +27,25 @@ public class SysLogAspect {
@Around("@annotation(sysLog)")
@SneakyThrows
public Object around(ProceedingJoinPoint point, SysLog sysLog) {
Long startTime = System.currentTimeMillis();
String strClassName = point.getTarget().getClass().getName();
String strMethodName = point.getSignature().getName();
log.debug("[类名]:{},[方法]:{}", strClassName, strMethodName);
OperLog operLog = SysLogUtils.getSysLog();
operLog.setTitle(sysLog.value());
// 发送异步日志事件
Long startTime = System.currentTimeMillis();
Object obj;
try {
obj = point.proceed();
}
catch (Exception e) {
} catch (Exception e) {
operLog.setType(LogTypeEnum.ERROR.getType());
operLog.setErrorMsg(e.getMessage());
throw e;
}
finally {
} finally {
Long endTime = System.currentTimeMillis();
operLog.setExecuteTime((endTime - startTime) + "毫秒");
// 发送异步日志事件
SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog));
}
return obj;
}

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

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

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

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

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

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

Loading…
Cancel
Save