Commit aab6e9b1 authored by suntao's avatar suntao

登陆token 不变

parent 4e1fde2f
...@@ -22,8 +22,10 @@ import lombok.extern.slf4j.Slf4j; ...@@ -22,8 +22,10 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import java.util.Date; import java.util.Date;
...@@ -54,6 +56,9 @@ public class LoginServiceImpl implements LoginService { ...@@ -54,6 +56,9 @@ public class LoginServiceImpl implements LoginService {
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private StringRedisTemplate redisTemplate;
@Resource(name = "redisTemplate")
private ValueOperations<String, Principal> loginOperations;
/** /**
* 登入 * 登入
* *
...@@ -120,8 +125,11 @@ public class LoginServiceImpl implements LoginService { ...@@ -120,8 +125,11 @@ public class LoginServiceImpl implements LoginService {
long currentTimeMillis = System.currentTimeMillis(); long currentTimeMillis = System.currentTimeMillis();
principal.setLoginTimeMillis(currentTimeMillis); principal.setLoginTimeMillis(currentTimeMillis);
String bossToken = Application.getBossToken(request); String token = Application.getBossToken(request);
String token = StringUtils.isEmpty(bossToken) ? UUID.randomUUID().toString() : bossToken; if (principalService.getPrincipal() == null || StringUtils.isEmpty(token)) {
// 是否redis中存在token
token = UUID.randomUUID().toString();
}
principalService.pushPrincipal(token, principal); principalService.pushPrincipal(token, principal);
// session登陆时间,毫秒值 // session登陆时间,毫秒值
......
...@@ -2,8 +2,6 @@ package cn.quantgroup.cashloanflowboss.core.configuration; ...@@ -2,8 +2,6 @@ package cn.quantgroup.cashloanflowboss.core.configuration;
import cn.quantgroup.cashloanflowboss.api.login.model.Principal; import cn.quantgroup.cashloanflowboss.api.login.model.Principal;
import cn.quantgroup.cashloanflowboss.api.login.service.LoginService; import cn.quantgroup.cashloanflowboss.api.login.service.LoginService;
import cn.quantgroup.cashloanflowboss.api.login.service.LoginServiceImpl;
import cn.quantgroup.cashloanflowboss.api.login.service.PrincipalService;
import cn.quantgroup.cashloanflowboss.api.role.entity.Role; import cn.quantgroup.cashloanflowboss.api.role.entity.Role;
import cn.quantgroup.cashloanflowboss.component.security.Authority; import cn.quantgroup.cashloanflowboss.component.security.Authority;
import cn.quantgroup.cashloanflowboss.component.security.SecurityHandler; import cn.quantgroup.cashloanflowboss.component.security.SecurityHandler;
...@@ -11,17 +9,12 @@ import cn.quantgroup.cashloanflowboss.core.Application; ...@@ -11,17 +9,12 @@ import cn.quantgroup.cashloanflowboss.core.Application;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert; import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.base.Tuple; import cn.quantgroup.cashloanflowboss.core.base.Tuple;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import cn.quantgroup.cashloanflowboss.core.exception.ApplicationException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.ValueOperations;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -35,17 +28,9 @@ public class ApplicationSecurityHandler implements SecurityHandler { ...@@ -35,17 +28,9 @@ public class ApplicationSecurityHandler implements SecurityHandler {
@Autowired @Autowired
private LoginService loginService; private LoginService loginService;
// @Autowired
// private HttpServletRequest request;
@Autowired
private PrincipalService principalService;
@Override @Override
public Tuple<Boolean, ApplicationStatus> doAuthentication(MethodInvocation invocation, String authorityId, Authority[] authority) { public Tuple<Boolean, ApplicationStatus> doAuthentication(MethodInvocation invocation, String authorityId, Authority[] authority) {
// Principal principal = principalService.getPrincipal();
Principal principal = Application.getPrincipal(); Principal principal = Application.getPrincipal();
// 检查是否已登录 // 检查是否已登录
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment