|
@@ -6,23 +6,27 @@ import cn.hutool.http.useragent.UserAgent;
|
|
import cn.hutool.http.useragent.UserAgentUtil;
|
|
import cn.hutool.http.useragent.UserAgentUtil;
|
|
import com.zhongzheng.common.constant.Constants;
|
|
import com.zhongzheng.common.constant.Constants;
|
|
import com.zhongzheng.common.core.domain.model.LoginUser;
|
|
import com.zhongzheng.common.core.domain.model.LoginUser;
|
|
|
|
+import com.zhongzheng.common.exception.BaseException;
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
import com.zhongzheng.common.exception.user.UserPasswordNotMatchException;
|
|
import com.zhongzheng.common.exception.user.UserPasswordNotMatchException;
|
|
import com.zhongzheng.common.utils.MessageUtils;
|
|
import com.zhongzheng.common.utils.MessageUtils;
|
|
import com.zhongzheng.framework.manager.AsyncManager;
|
|
import com.zhongzheng.framework.manager.AsyncManager;
|
|
import com.zhongzheng.framework.manager.factory.AsyncFactory;
|
|
import com.zhongzheng.framework.manager.factory.AsyncFactory;
|
|
|
|
+import com.zhongzheng.modules.user.bo.UserLoginKeyAddBo;
|
|
import com.zhongzheng.modules.user.domain.User;
|
|
import com.zhongzheng.modules.user.domain.User;
|
|
import com.zhongzheng.modules.user.entity.ClientLoginUser;
|
|
import com.zhongzheng.modules.user.entity.ClientLoginUser;
|
|
import com.zhongzheng.common.core.redis.RedisCache;
|
|
import com.zhongzheng.common.core.redis.RedisCache;
|
|
import com.zhongzheng.common.utils.ServletUtils;
|
|
import com.zhongzheng.common.utils.ServletUtils;
|
|
import com.zhongzheng.common.utils.ip.AddressUtils;
|
|
import com.zhongzheng.common.utils.ip.AddressUtils;
|
|
import com.zhongzheng.common.utils.ip.IpUtils;
|
|
import com.zhongzheng.common.utils.ip.IpUtils;
|
|
|
|
+import com.zhongzheng.modules.user.service.IUserLoginKeyService;
|
|
import com.zhongzheng.modules.user.service.IUserService;
|
|
import com.zhongzheng.modules.user.service.IUserService;
|
|
import io.jsonwebtoken.Claims;
|
|
import io.jsonwebtoken.Claims;
|
|
import io.jsonwebtoken.Jwts;
|
|
import io.jsonwebtoken.Jwts;
|
|
import io.jsonwebtoken.SignatureAlgorithm;
|
|
import io.jsonwebtoken.SignatureAlgorithm;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.security.access.AccessDeniedException;
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
@@ -30,7 +34,10 @@ import org.springframework.security.core.Authentication;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.ServletException;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -67,6 +74,9 @@ public class WxTokenService
|
|
@Autowired
|
|
@Autowired
|
|
private IUserService iUserService;
|
|
private IUserService iUserService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IUserLoginKeyService iUserLoginKeyService;
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
private AuthenticationManager authenticationManager;
|
|
private AuthenticationManager authenticationManager;
|
|
|
|
|
|
@@ -75,8 +85,7 @@ public class WxTokenService
|
|
*
|
|
*
|
|
* @return 用户信息
|
|
* @return 用户信息
|
|
*/
|
|
*/
|
|
- public ClientLoginUser getLoginUser(HttpServletRequest request)
|
|
|
|
- {
|
|
|
|
|
|
+ public ClientLoginUser getLoginUser(HttpServletRequest request) {
|
|
//测试用户
|
|
//测试用户
|
|
String test_token = request.getHeader("X-Auth-Token");
|
|
String test_token = request.getHeader("X-Auth-Token");
|
|
if("test".equals(test_token)){
|
|
if("test".equals(test_token)){
|
|
@@ -89,6 +98,10 @@ public class WxTokenService
|
|
Claims claims = parseToken(token);
|
|
Claims claims = parseToken(token);
|
|
// 解析对应的权限以及用户信息
|
|
// 解析对应的权限以及用户信息
|
|
String uuid = (String) claims.get(Constants.WX_LOGIN_USER_KEY);
|
|
String uuid = (String) claims.get(Constants.WX_LOGIN_USER_KEY);
|
|
|
|
+ if(!iUserLoginKeyService.queryByUserKey(uuid)){
|
|
|
|
+ ClientLoginUser errorUser = new ClientLoginUser();
|
|
|
|
+ return errorUser;
|
|
|
|
+ }
|
|
String userKey = getTokenKey(uuid);
|
|
String userKey = getTokenKey(uuid);
|
|
ClientLoginUser user = redisCache.getCacheObject(userKey);
|
|
ClientLoginUser user = redisCache.getCacheObject(userKey);
|
|
return user;
|
|
return user;
|
|
@@ -142,7 +155,17 @@ public class WxTokenService
|
|
refreshToken(loginUser);
|
|
refreshToken(loginUser);
|
|
Map<String, Object> claims = new HashMap<>();
|
|
Map<String, Object> claims = new HashMap<>();
|
|
claims.put(Constants.WX_LOGIN_USER_KEY, token);
|
|
claims.put(Constants.WX_LOGIN_USER_KEY, token);
|
|
- return createToken(claims);
|
|
|
|
|
|
+ String secret = createToken(claims);
|
|
|
|
+ if(Validator.isNotEmpty(token)){
|
|
|
|
+ UserLoginKeyAddBo addBo = new UserLoginKeyAddBo();
|
|
|
|
+ addBo.setUserId(loginUser.getUser().getUserId());
|
|
|
|
+ addBo.setUserKey(token);
|
|
|
|
+ addBo.setIp(loginUser.getIpaddr());
|
|
|
|
+ addBo.setBrowser(loginUser.getBrowser());
|
|
|
|
+ addBo.setSecret(secret);
|
|
|
|
+ iUserLoginKeyService.insertByAddBo(addBo);
|
|
|
|
+ }
|
|
|
|
+ return secret;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|