|
@@ -2,8 +2,19 @@ package com.ozs.framework.security.handle;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.Serializable;
|
|
import java.io.Serializable;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.Date;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+
|
|
|
|
+import com.ozs.common.constant.Constants;
|
|
|
|
+import com.ozs.common.core.domain.model.LoginUser;
|
|
|
|
+import com.ozs.common.core.redis.RedisCache;
|
|
|
|
+import com.ozs.framework.web.service.TokenService;
|
|
|
|
+import com.ozs.system.domain.SysLoginInfo;
|
|
|
|
+import com.ozs.system.service.ISysLoginInfoService;
|
|
|
|
+import io.jsonwebtoken.Claims;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.security.core.AuthenticationException;
|
|
import org.springframework.security.core.AuthenticationException;
|
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -22,13 +33,38 @@ import com.ozs.common.utils.StringUtils;
|
|
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, Serializable
|
|
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, Serializable
|
|
{
|
|
{
|
|
private static final long serialVersionUID = -8970718410437077606L;
|
|
private static final long serialVersionUID = -8970718410437077606L;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TokenService tokenService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisCache redisCache;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysLoginInfoService iSysLoginInfoService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
|
|
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
|
|
throws IOException
|
|
throws IOException
|
|
{
|
|
{
|
|
int code = HttpStatus.UNAUTHORIZED;
|
|
int code = HttpStatus.UNAUTHORIZED;
|
|
- String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
|
|
|
|
- ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
|
|
|
|
|
|
+ String token = tokenService.getToken(request);
|
|
|
|
+ if (StringUtils.isNotEmpty(token)) {
|
|
|
|
+ try {
|
|
|
|
+ Claims claims =tokenService.parseToken(token);
|
|
|
|
+ String app = "";
|
|
|
|
+ // 解析对应的权限以及用户信息
|
|
|
|
+ String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
|
|
|
|
+ if (StringUtils.isEmpty(uuid)) {
|
|
|
|
+ uuid = (String) claims.get(Constants.LOGIN_USER_KEY_APP);
|
|
|
|
+ app = "APP";
|
|
|
|
+ }
|
|
|
|
+ String userKey = tokenService.getTokenKey(uuid);
|
|
|
|
+ LoginUser user = redisCache.getCacheObject(userKey);
|
|
|
|
+ SysLoginInfo loginTime = iSysLoginInfoService.getLoginTime(user.getUsername());
|
|
|
|
+ SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ String format1 = dateFormat1.format(loginTime.getLoginTime());
|
|
|
|
+ String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源"+format1, request.getRequestURI());
|
|
|
|
+ ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
|
|
|
|
+ }catch (Exception exception){
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|