加密openId

master
shijie 4 years ago
parent caeb3fbf64
commit 7caff277d3
  1. 2
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java
  2. 1
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/filter/MyAuthenticationFilter.java
  3. 3
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/handle/AdminAuthenticationProvider.java
  4. 3
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/handle/AdminAuthenticationSuccessHandler.java
  5. 3
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/handle/UrlFilterInvocationSecurityMetadataSource.java
  6. 9
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserServiceImpl.java
  7. 2
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/feign/HrmsAuthFeignService.java
  8. 6
      dq-govern-gateway/src/main/java/com/daqing/financial/gateway/config/ApiGlobalFilter.java

@ -8,6 +8,7 @@ import com.daqing.framework.domain.hrms.UserEntity;
import com.daqing.framework.domain.hrms.request.*; import com.daqing.framework.domain.hrms.request.*;
import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.model.response.ResponseResult;
import com.daqing.framework.util.JwtUtils; import com.daqing.framework.util.JwtUtils;
import com.daqing.framework.util.RedisUtil;
import com.daqing.framework.util.SendUtil; import com.daqing.framework.util.SendUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -129,6 +130,7 @@ public class UserLoginController implements UserLoginControllerApi {
long times = 86400; long times = 86400;
//生成jwt //生成jwt
String token = JwtUtils.createJWT(user.getId()+"","token", times); String token = JwtUtils.createJWT(user.getId()+"","token", times);
RedisUtil.setEx("dq:token:"+token,String.valueOf(user.getId()),times);
// state 当前用户的页面地址,需要拼接 http:// 这样才不会站内跳转 // state 当前用户的页面地址,需要拼接 http:// 这样才不会站内跳转
response.sendRedirect("http://www.huorantech.cn/dq/index.html#/Dashboard?token="+token); response.sendRedirect("http://www.huorantech.cn/dq/index.html#/Dashboard?token="+token);
//response.sendRedirect(state+"?token="+token+"&head_img="+user.getHeadImg()+"&name="+URLEncoder.encode(user.getName(),"UTF-8")); //response.sendRedirect(state+"?token="+token+"&head_img="+user.getHeadImg()+"&name="+URLEncoder.encode(user.getName(),"UTF-8"));

@ -42,6 +42,7 @@ public class MyAuthenticationFilter extends OncePerRequestFilter {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
System.out.println("请求头类型: " + request.getContentType()); System.out.println("请求头类型: " + request.getContentType());
String token = request.getHeader("token"); String token = request.getHeader("token");
log.info("访问鉴权token=============================");
if ((request.getContentType() == null && request.getContentLength() > 0) || (request.getContentType() != null && !request.getContentType().contains(Constants.REQUEST_HEADERS_CONTENT_TYPE))) { if ((request.getContentType() == null && request.getContentLength() > 0) || (request.getContentType() != null && !request.getContentType().contains(Constants.REQUEST_HEADERS_CONTENT_TYPE))) {
filterChain.doFilter(request, response); filterChain.doFilter(request, response);
return; return;

@ -7,6 +7,7 @@ import com.daqing.framework.domain.hrms.request.LoginRequest;
import com.daqing.framework.domain.hrms.response.LoginResponse; import com.daqing.framework.domain.hrms.response.LoginResponse;
import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.model.response.ResponseResult;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.AuthenticationProvider;
@ -24,6 +25,7 @@ import javax.annotation.Resource;
* @author : zhengqing * @author : zhengqing
* @date : 2019/10/12 14:49 * @date : 2019/10/12 14:49
*/ */
@Slf4j
@Component @Component
public class AdminAuthenticationProvider implements AuthenticationProvider { public class AdminAuthenticationProvider implements AuthenticationProvider {
@ -37,6 +39,7 @@ public class AdminAuthenticationProvider implements AuthenticationProvider {
@SneakyThrows @SneakyThrows
@Override @Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException { public Authentication authenticate(Authentication authentication) throws AuthenticationException {
log.info("来了authenticate~~~~");
MyAuthenticationToken authRequest=(MyAuthenticationToken)authentication; MyAuthenticationToken authRequest=(MyAuthenticationToken)authentication;
String tenDayEffective= MapUtils.getString(authRequest.getParam(),"tenDayEffective","1"); String tenDayEffective= MapUtils.getString(authRequest.getParam(),"tenDayEffective","1");
String type= MapUtils.getString(authRequest.getParam(),"type","1"); String type= MapUtils.getString(authRequest.getParam(),"type","1");

@ -3,6 +3,7 @@ package com.daqing.financial.hrauth.handle;
import com.daqing.financial.hrauth.model.ApiResult; import com.daqing.financial.hrauth.model.ApiResult;
import com.daqing.financial.hrauth.util.ResponseUtils; import com.daqing.financial.hrauth.util.ResponseUtils;
import com.daqing.framework.domain.hrms.UserEntity; import com.daqing.framework.domain.hrms.UserEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -19,12 +20,14 @@ import java.io.IOException;
* @author : zhengqing * @author : zhengqing
* @date : 2019/10/12 15:31 * @date : 2019/10/12 15:31
*/ */
@Slf4j
@Component @Component
public class AdminAuthenticationSuccessHandler implements AuthenticationSuccessHandler { public class AdminAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@Override @Override
public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse response, Authentication auth) throws IOException, ServletException { public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse response, Authentication auth) throws IOException, ServletException {
UserEntity user = new UserEntity(); UserEntity user = new UserEntity();
log.info("来了认证成功处理~~~~~~~~~~~~~~~~~~~~~~~~~~");
SecurityUser securityUser = ((SecurityUser) auth.getPrincipal()); SecurityUser securityUser = ((SecurityUser) auth.getPrincipal());
user.setAccount(securityUser.getCurrentUserInfo().getAccount()); user.setAccount(securityUser.getCurrentUserInfo().getAccount());
user.setToken(securityUser.getCurrentUserInfo().getToken()); user.setToken(securityUser.getCurrentUserInfo().getToken());

@ -8,6 +8,7 @@ import com.daqing.financial.hrauth.enums.Constants;
import com.daqing.framework.domain.hrms.PermissionEntity; import com.daqing.framework.domain.hrms.PermissionEntity;
import com.daqing.framework.domain.hrms.RoleEntity; import com.daqing.framework.domain.hrms.RoleEntity;
import com.daqing.framework.domain.hrms.RolePermissionEntity; import com.daqing.framework.domain.hrms.RolePermissionEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.ConfigAttribute; import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig; import org.springframework.security.access.SecurityConfig;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
@ -27,6 +28,7 @@ import java.util.List;
* @description : 执行完之后到 `UrlAccessDecisionManager` 中认证权限 * @description : 执行完之后到 `UrlAccessDecisionManager` 中认证权限
* @date : 2019/10/15 14:36 * @date : 2019/10/15 14:36
*/ */
@Slf4j
@Component @Component
public class UrlFilterInvocationSecurityMetadataSource implements FilterInvocationSecurityMetadataSource { public class UrlFilterInvocationSecurityMetadataSource implements FilterInvocationSecurityMetadataSource {
@ -46,6 +48,7 @@ public class UrlFilterInvocationSecurityMetadataSource implements FilterInvocati
*/ */
@Override @Override
public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException { public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
log.info("来了返回url所需要的用户权限信息~~~~~~~~~~~~~~~~~~~~");
// 获取当前请求url // 获取当前请求url
String beforeRequestUrl = ((FilterInvocation) object).getRequestUrl(); String beforeRequestUrl = ((FilterInvocation) object).getRequestUrl();
String requestUrl = null; String requestUrl = null;

@ -12,6 +12,7 @@ import com.daqing.framework.domain.hrms.UserEntity;
import com.daqing.framework.domain.hrms.request.LoginRequest; import com.daqing.framework.domain.hrms.request.LoginRequest;
import com.daqing.framework.domain.hrms.response.LoginResponse; import com.daqing.framework.domain.hrms.response.LoginResponse;
import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.model.response.ResponseResult;
import com.daqing.framework.util.Md5Util;
import com.daqing.framework.util.RedisUtil; import com.daqing.framework.util.RedisUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
@ -58,16 +59,18 @@ public class UserServiceImpl extends ServiceImpl<UserLoginDao, UserEntity> imple
String accessToken = (String)baseMap.get("access_token"); String accessToken = (String)baseMap.get("access_token");
String openId = (String) baseMap.get("openid"); String openId = (String) baseMap.get("openid");
//对code(回调过来的openid)加密
String md5OpenId = Md5Util.md5(openId);
log.info("accessToken========> "+accessToken+"openId========> "+openId+"code=======> "+code); log.info("accessToken========> "+accessToken+"openId========> "+openId+"code=======> "+code);
UserEntity dbUser = userMapper.findByOpenid(openId); UserEntity dbUser = userMapper.findByOpenid(md5OpenId);
if(dbUser!=null && dbUser.getPhoneAccount()!=null) { //dbUser不为空,存在直接让它登录 if(dbUser!=null && dbUser.getPhoneAccount()!=null) { //dbUser不为空,存在直接让它登录
log.info("来了微信扫码登录~~~~~~~~~~~~~~~~~~~~~~~~~~~"); log.info("来了微信扫码登录~~~~~~~~~~~~~~~~~~~~~~~~~~~");
LoginRequest loginRequest = new LoginRequest(); LoginRequest loginRequest = new LoginRequest();
loginRequest.setTenDayEffective(1); loginRequest.setTenDayEffective(1);
loginRequest.setType(2); loginRequest.setType(2);
loginRequest.setWechatId(openId); loginRequest.setWechatId(md5OpenId);
ResponseResult login = userLoginService.login(loginRequest); ResponseResult login = userLoginService.login(loginRequest);
LoginResponse data = (LoginResponse) login.getData(); LoginResponse data = (LoginResponse) login.getData();
@ -81,7 +84,7 @@ public class UserServiceImpl extends ServiceImpl<UserLoginDao, UserEntity> imple
if(dbUser == null){//openId不存在,返回绑定手机号页面,须另写绑定手机号接口 if(dbUser == null){//openId不存在,返回绑定手机号页面,须另写绑定手机号接口
log.info("dbUser为空,openId不存在,请先绑定手机号哦~~~"); log.info("dbUser为空,openId不存在,请先绑定手机号哦~~~");
try { try {
response.sendRedirect("http://www.huorantech.cn/dq/index.html#/bind-phone?matched="+openId);//跳转绑定手机号页面 response.sendRedirect("http://www.huorantech.cn/dq/index.html#/bind-phone?matched="+md5OpenId);//跳转绑定手机号页面
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.GetMapping;
* @auther River * @auther River
* @date 2020/10/12 17:58 * @date 2020/10/12 17:58
*/ */
@FeignClient("dq-financial-hrms-auth") @FeignClient(name = "dq-financial-hrms-auth",contextId = "example")
public interface HrmsAuthFeignService { public interface HrmsAuthFeignService {
// @GetMapping("/hrms/auth/userlogin/getWeChatConfig") // @GetMapping("/hrms/auth/userlogin/getWeChatConfig")

@ -2,6 +2,7 @@ package com.daqing.financial.gateway.config;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.daqing.framework.util.JwtUtils; import com.daqing.framework.util.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GatewayFilterChain;
@ -22,7 +23,7 @@ import reactor.core.publisher.Mono;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
@Slf4j
@Component @Component
@PropertySource(value = "classpath:jwt.properties") @PropertySource(value = "classpath:jwt.properties")
public class ApiGlobalFilter implements GlobalFilter, Ordered { public class ApiGlobalFilter implements GlobalFilter, Ordered {
@ -42,10 +43,13 @@ public class ApiGlobalFilter implements GlobalFilter, Ordered {
@Override @Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
String requestUrl = exchange.getRequest().getPath().toString(); String requestUrl = exchange.getRequest().getPath().toString();
log.info("requestUrl========================="+requestUrl);
boolean status = CollectionUtils.contains(ignoreUrl.iterator(), requestUrl); boolean status = CollectionUtils.contains(ignoreUrl.iterator(), requestUrl);
log.info("status========================"+status);
if (!status){ if (!status){
String token = exchange.getRequest().getHeaders().getFirst("token"); String token = exchange.getRequest().getHeaders().getFirst("token");
log.info("token1======================="+token);
ServerHttpResponse response = exchange.getResponse(); ServerHttpResponse response = exchange.getResponse();
//没有数据 //没有数据
if (StringUtils.isBlank(token)) { if (StringUtils.isBlank(token)) {

Loading…
Cancel
Save