Merge branch 'leng_dev' into k8s
This commit is contained in:
commit
8e1ccd76d9
25 files changed
+335
-177
No files matched your search
@@ -23,6 +23,8 @@ package com.pig4cloud.pigx.auth;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.cloud.client.SpringCloudApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
@@ -36,4 +38,9 @@ public class PigxAuthApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(PigxAuthApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ package com.pig4cloud.pigx.auth.config;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.pig4cloud.pigx.common.security.mobile.MobileLoginSuccessHandler;
|
||||
import com.pig4cloud.pigx.common.security.mobile.MobileSecurityConfigurer;
|
||||
import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -31,7 +32,6 @@ import org.springframework.core.annotation.Order;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.oauth2.provider.ClientDetailsService;
|
||||
@@ -52,7 +52,7 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
|
||||
@Autowired
|
||||
private ClientDetailsService clientDetailsService;
|
||||
@Autowired
|
||||
private UserDetailsService pigxUserDetailsServiceImpl;
|
||||
private PigxUserDetailsService userDetailsService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private AuthorizationServerTokenServices defaultAuthorizationServerTokenServices;
|
||||
@@ -88,7 +88,7 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
|
||||
@Bean
|
||||
public MobileSecurityConfigurer mobileSecurityConfigurer() {
|
||||
return new MobileSecurityConfigurer(mobileLoginSuccessHandler()
|
||||
, pigxUserDetailsServiceImpl);
|
||||
, userDetailsService);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+59
-3
@@ -21,21 +21,25 @@ package com.pig4cloud.pigx.auth.service;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysUser;
|
||||
import com.pig4cloud.pigx.admin.api.feign.RemoteUserService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.EnumLoginType;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.security.social.WxSocialConfig;
|
||||
import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -50,13 +54,65 @@ import java.util.Set;
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class PigxUserDetailsServiceImpl implements UserDetailsService {
|
||||
public class PigxUserDetailsServiceImpl implements PigxUserDetailsService {
|
||||
private static final String WX_AUTHORIZATION_CODE_URL = "https://api.weixin.qq.com/sns/oauth2/access_token" +
|
||||
"?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
|
||||
private static final String REGEX = "@";
|
||||
private final RestTemplate restTemplate;
|
||||
private final RemoteUserService remoteUserService;
|
||||
private final WxSocialConfig wxSocialConfig;
|
||||
|
||||
/**
|
||||
* 用户密码登录
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return
|
||||
* @throws UsernameNotFoundException
|
||||
*/
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
R<UserInfo> result = remoteUserService.info(username, SecurityConstants.FROM_IN);
|
||||
return getUserDetails(result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据社交登录code 登录
|
||||
*
|
||||
* @param inStr TYPE@CODE
|
||||
* @return UserDetails
|
||||
* @throws UsernameNotFoundException
|
||||
*/
|
||||
@Override
|
||||
public UserDetails loadUserBySocial(String inStr) throws UsernameNotFoundException {
|
||||
String[] codeStr = inStr.split(REGEX);
|
||||
String type = codeStr[0];
|
||||
String code = codeStr[1];
|
||||
|
||||
R<UserInfo> userInfo = null;
|
||||
if (EnumLoginType.WECHAT.getType().equals(type)) {
|
||||
String url = String.format(WX_AUTHORIZATION_CODE_URL
|
||||
, wxSocialConfig.getAppid(), wxSocialConfig.getSecret(), code);
|
||||
String result = restTemplate.getForObject(url, String.class);
|
||||
log.debug("微信响应报文:{}", result);
|
||||
|
||||
Object obj = JSONUtil.parseObj(result).get("openid");
|
||||
if (obj != null) {
|
||||
userInfo = remoteUserService.social(EnumLoginType.WECHAT.getType(), obj.toString());
|
||||
} else {
|
||||
throw new UsernameNotFoundException("获取用户openid失败");
|
||||
}
|
||||
}
|
||||
return getUserDetails(userInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建userdetails
|
||||
*
|
||||
* @param result 用户信息
|
||||
* @return
|
||||
*/
|
||||
private UserDetails getUserDetails(R<UserInfo> result) {
|
||||
if (result == null || result.getData() == null) {
|
||||
throw new UsernameNotFoundException("用户不存在");
|
||||
}
|
||||
@@ -75,7 +131,7 @@ public class PigxUserDetailsServiceImpl implements UserDetailsService {
|
||||
SysUser user = info.getSysUser();
|
||||
boolean enabled = StrUtil.equals(user.getDelFlag(), CommonConstant.STATUS_NORMAL);
|
||||
// 构造security用户
|
||||
return new User(username, SecurityConstants.BCRYPT + user.getPassword(), enabled,
|
||||
return new User(info.getSysUser().getUsername(), SecurityConstants.BCRYPT + user.getPassword(), enabled,
|
||||
true, true, true, authorities);
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,6 @@
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>${servlet-api.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--jacksonJSR310规范-->
|
||||
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.common.core.constant;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/1/15
|
||||
* MQ 消息队列
|
||||
*/
|
||||
public interface MqQueueConstant {
|
||||
/**
|
||||
* log rabbit队列名称
|
||||
*/
|
||||
String LOG_QUEUE = "log";
|
||||
|
||||
/**
|
||||
* 发送短信验证码队列
|
||||
*/
|
||||
String MOBILE_CODE_QUEUE = "mobile_code_queue";
|
||||
|
||||
/**
|
||||
* 短信服务状态队列
|
||||
*/
|
||||
String MOBILE_SERVICE_STATUS_CHANGE = "mobile_service_status_change";
|
||||
|
||||
/**
|
||||
* 钉钉服务状态队列
|
||||
*/
|
||||
String DINGTALK_SERVICE_STATUS_CHANGE = "dingtalk_service_status_change";
|
||||
|
||||
/**
|
||||
* zipkin 队列
|
||||
*/
|
||||
String ZIPKIN_NAME_QUEUE = "zipkin";
|
||||
|
||||
/**
|
||||
* 路由配置状态队列
|
||||
*/
|
||||
String ROUTE_CONFIG_CHANGE = "route_config_change";
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.common.core.constant.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/8/15
|
||||
* 社交登录类型
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum EnumLoginType {
|
||||
/**
|
||||
* 账号密码登录
|
||||
*/
|
||||
PWD("PWD", "账号密码登录"),
|
||||
|
||||
/**
|
||||
* QQ登录
|
||||
*/
|
||||
QQ("QQ", "QQ登录"),
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
*/
|
||||
WECHAT("WX", "微信登录");
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private final String type;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private final String description;
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.common.core.constant.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/1/16
|
||||
* 短信通道枚举
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum EnumSmsChannel {
|
||||
/**
|
||||
* 阿里大鱼短信通道
|
||||
*/
|
||||
ALIYUN("ALIYUN_SMS", "阿里大鱼");
|
||||
/**
|
||||
* 通道名称
|
||||
*/
|
||||
private final String name;
|
||||
/**
|
||||
* 通道描述
|
||||
*/
|
||||
private final String description;
|
||||
}
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.common.core.constant.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author LiXunHuan
|
||||
* @date 2018/1/16
|
||||
* 短信通道模板
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum EnumSmsChannelTemplate {
|
||||
/**
|
||||
* 登录验证
|
||||
*/
|
||||
LOGIN_NAME_LOGIN("loginCodeChannel", "登录验证"),
|
||||
/**
|
||||
* 服务异常提醒
|
||||
*/
|
||||
SERVICE_STATUS_CHANGE("serviceStatusChange", "Pig4Cloud");
|
||||
|
||||
/**
|
||||
* 模板名称
|
||||
*/
|
||||
private final String template;
|
||||
/**
|
||||
* 模板签名
|
||||
*/
|
||||
private final String signName;
|
||||
}
|
||||
+9
-4
@@ -17,28 +17,33 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.mobile;
|
||||
|
||||
import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/8/5
|
||||
* 手机号登录校验逻辑
|
||||
* 手机登录校验逻辑
|
||||
* 验证码登录、社交登录
|
||||
*/
|
||||
public class MobileAuthenticationProvider implements AuthenticationProvider {
|
||||
@Getter
|
||||
@Setter
|
||||
private UserDetailsService userDetailsService;
|
||||
private PigxUserDetailsService userDetailsService;
|
||||
|
||||
@Override
|
||||
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
||||
MobileAuthenticationToken mobileAuthenticationToken = (MobileAuthenticationToken) authentication;
|
||||
UserDetails userDetails = userDetailsService.loadUserByUsername("admin");
|
||||
|
||||
String principal = mobileAuthenticationToken.getPrincipal().toString();
|
||||
UserDetails userDetails = userDetailsService.loadUserBySocial(principal);
|
||||
|
||||
|
||||
MobileAuthenticationToken authenticationToken = new MobileAuthenticationToken(userDetails, userDetails.getAuthorities());
|
||||
authenticationToken.setDetails(mobileAuthenticationToken.getDetails());
|
||||
return authenticationToken;
|
||||
|
||||
+2
-2
@@ -17,11 +17,11 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.mobile;
|
||||
|
||||
import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.web.DefaultSecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
@@ -36,7 +36,7 @@ import org.springframework.stereotype.Component;
|
||||
@AllArgsConstructor
|
||||
public class MobileSecurityConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
|
||||
private AuthenticationSuccessHandler mobileLoginSuccessHandler;
|
||||
private UserDetailsService userDetailsService;
|
||||
private PigxUserDetailsService userDetailsService;
|
||||
|
||||
@Override
|
||||
public void configure(HttpSecurity http) {
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.common.security.social;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/8/16
|
||||
* qq登录配置信息
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "social.qq")
|
||||
public class QqSocialConfig {
|
||||
private String appid;
|
||||
private String secret;
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.common.security.social;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/8/16
|
||||
* 微信登录配置
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "social.wx")
|
||||
public class WxSocialConfig {
|
||||
private String appid;
|
||||
private String secret;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/package com.pig4cloud.pigx.common.security.util;
|
||||
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/8/15
|
||||
*/
|
||||
public interface PigxUserDetailsService extends UserDetailsService {
|
||||
|
||||
/**
|
||||
* 根据社交登录code 登录
|
||||
*
|
||||
* @param code TYPE@CODE
|
||||
* @return UserDetails
|
||||
* @throws UsernameNotFoundException
|
||||
*/
|
||||
UserDetails loadUserBySocial(String code) throws UsernameNotFoundException;
|
||||
}
|
||||
@@ -2,4 +2,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.pig4cloud.pigx.common.security.component.PermissionService,\
|
||||
com.pig4cloud.pigx.common.security.component.PigAccessDeniedHandler,\
|
||||
com.pig4cloud.pigx.common.security.component.ResourceAuthExceptionEntryPoint,\
|
||||
com.pig4cloud.pigx.common.security.feign.PigxFeignClientConfiguration
|
||||
com.pig4cloud.pigx.common.security.feign.PigxFeignClientConfiguration,\
|
||||
com.pig4cloud.pigx.common.security.social.QqSocialConfig,\
|
||||
com.pig4cloud.pigx.common.security.social.WxSocialConfig
|
||||
@@ -45,7 +45,6 @@
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>${servlet-api.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--swagger 依赖-->
|
||||
|
||||
+10
@@ -87,4 +87,14 @@ public class SysUser implements Serializable {
|
||||
*/
|
||||
private Integer deptId;
|
||||
|
||||
/**
|
||||
* 微信openid
|
||||
*/
|
||||
private String wxOpenid;
|
||||
|
||||
/**
|
||||
* QQ openid
|
||||
*/
|
||||
private String qqOpenid;
|
||||
|
||||
}
|
||||
+11
@@ -44,4 +44,15 @@ public interface RemoteUserService {
|
||||
@GetMapping("/user/info/{username}")
|
||||
R<UserInfo> info(@PathVariable("username") String username
|
||||
, @RequestHeader("from") String from);
|
||||
|
||||
/**
|
||||
* 通过社交账号查询用户、角色信息
|
||||
*
|
||||
* @param type 社交账号类型 (QQ/WX)
|
||||
* @param openid 账号
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/user/social/{type}/{openid}")
|
||||
R<UserInfo> social(@PathVariable("type") String type
|
||||
, @PathVariable("openid") String openid);
|
||||
}
|
||||
+14
@@ -44,4 +44,18 @@ public class RemoteUserServiceFallbackImpl implements RemoteUserService {
|
||||
log.error("feign 查询用户信息失败:{}", username);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过社交账号查询用户、角色信息
|
||||
*
|
||||
* @param type 社交账号类型 (QQ/WX)
|
||||
* @param openid 账号
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public R<UserInfo> social(String type, String openid) {
|
||||
log.error("feign 查询用户信息失败:{}", openid);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,6 +50,17 @@ public class UserVO implements Serializable {
|
||||
* 随机盐
|
||||
*/
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
* 微信openid
|
||||
*/
|
||||
private String wxOpenid;
|
||||
|
||||
/**
|
||||
* QQ openid
|
||||
*/
|
||||
private String qqOpenid;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
+5
-1
@@ -44,7 +44,11 @@ public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/actuator/**", "/user/info/*", "/log/**", "/v2/api-docs").permitAll()
|
||||
.antMatchers("/actuator/**"
|
||||
, "/user/info/*"
|
||||
, "/user/social/**"
|
||||
, "/log/**"
|
||||
, "/v2/api-docs").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and().csrf().disable();
|
||||
}
|
||||
|
||||
+15
-2
@@ -21,7 +21,6 @@ package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysUser;
|
||||
@@ -30,6 +29,8 @@ import com.pig4cloud.pigx.admin.api.vo.UserVO;
|
||||
import com.pig4cloud.pigx.admin.service.SysUserService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.EnumLoginType;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
@@ -75,7 +76,19 @@ public class UserController {
|
||||
username = SecurityUtils.getUser();
|
||||
}
|
||||
|
||||
return new R<>(userService.findUserInfo(username));
|
||||
return new R<>(userService.findUserInfo(EnumLoginType.PWD.getType(), username));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过社交账号查询用户、角色信息
|
||||
*
|
||||
* @param type 社交账号类型 (QQ/WX)
|
||||
* @param openid 账号
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/social/{type}/{openid}")
|
||||
public R<UserInfo> social(@PathVariable String type, @PathVariable String openid) {
|
||||
return new R<>(userService.findUserInfo(type, openid));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -21,11 +21,11 @@ package com.pig4cloud.pigx.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysUser;
|
||||
import com.pig4cloud.pigx.admin.api.vo.UserVO;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
|
||||
/**
|
||||
@@ -36,10 +36,11 @@ public interface SysUserService extends IService<SysUser> {
|
||||
/**
|
||||
* 查询用户信息
|
||||
*
|
||||
* @param type 类型
|
||||
* @param username 用户名
|
||||
* @return userInfo
|
||||
*/
|
||||
UserInfo findUserInfo(String username);
|
||||
UserInfo findUserInfo(String type, String username);
|
||||
|
||||
/**
|
||||
* 分页查询用户信息(含有角色信息)
|
||||
|
||||
+11
-4
@@ -25,7 +25,6 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRole;
|
||||
@@ -38,6 +37,8 @@ import com.pig4cloud.pigx.admin.service.SysMenuService;
|
||||
import com.pig4cloud.pigx.admin.service.SysRoleService;
|
||||
import com.pig4cloud.pigx.admin.service.SysUserRoleService;
|
||||
import com.pig4cloud.pigx.admin.service.SysUserService;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.EnumLoginType;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@@ -79,10 +80,16 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(value = "user_details", key = "#username")
|
||||
public UserInfo findUserInfo(String username) {
|
||||
@Cacheable(value = "user_details", key = "#type +':'+ #username")
|
||||
public UserInfo findUserInfo(String type, String username) {
|
||||
SysUser condition = new SysUser();
|
||||
condition.setUsername(username);
|
||||
if (EnumLoginType.PWD.getType().equals(type)) {
|
||||
condition.setUsername(username);
|
||||
} else if (EnumLoginType.WECHAT.getType().equals(type)) {
|
||||
condition.setWxOpenid(username);
|
||||
} else {
|
||||
condition.setQqOpenid(username);
|
||||
}
|
||||
SysUser sysUser = this.selectOne(new EntityWrapper<>(condition));
|
||||
if (sysUser == null) {
|
||||
return null;
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
<result column="avatar" property="avatar"/>
|
||||
<result column="salt" property="salt"/>
|
||||
<result column="dept_id" property="deptId"/>
|
||||
<result column="wx_openid" property="wxOpenid"/>
|
||||
<result column="qq_openid" property="qqOpenid"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="del_flag" property="delFlag"/>
|
||||
@@ -42,6 +44,8 @@
|
||||
<result column="salt" property="salt"/>
|
||||
<result column="phone" property="phone"/>
|
||||
<result column="avatar" property="avatar"/>
|
||||
<result column="wx_openid" property="wxOpenid"/>
|
||||
<result column="qq_openid" property="qqOpenid"/>
|
||||
<result column="ucreate_time" property="createTime"/>
|
||||
<result column="uupdate_time" property="updateTime"/>
|
||||
<result column="udel_flag" property="delFlag"/>
|
||||
@@ -65,6 +69,8 @@
|
||||
`user`.salt,
|
||||
`user`.phone,
|
||||
`user`.avatar,
|
||||
`user`.wx_openid,
|
||||
`user`.qq_openid,
|
||||
`user`.dept_id,
|
||||
`user`.create_time AS ucreate_time,
|
||||
`user`.update_time AS uupdate_time,
|
||||
@@ -95,6 +101,8 @@
|
||||
`user`.salt,
|
||||
`user`.phone,
|
||||
`user`.avatar,
|
||||
`user`.wx_openid,
|
||||
`user`.qq_openid,
|
||||
`user`.create_time AS ucreate_time,
|
||||
`user`.update_time AS uupdate_time,
|
||||
`user`.del_flag AS udel_flag,
|
||||
@@ -123,6 +131,8 @@
|
||||
`user`.salt,
|
||||
`user`.phone,
|
||||
`user`.avatar,
|
||||
`user`.wx_openid,
|
||||
`user`.qq_openid,
|
||||
`user`.create_time AS ucreate_time,
|
||||
`user`.update_time AS uupdate_time,
|
||||
`user`.del_flag AS udel_flag,
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<monitor.version>2.0.1</monitor.version>
|
||||
<hutool.version>4.1.4</hutool.version>
|
||||
<hutool.version>4.1.7</hutool.version>
|
||||
<mbp.boot.version>2.3</mbp.boot.version>
|
||||
<kaptcha.version>0.0.9</kaptcha.version>
|
||||
<swagger.version>2.9.2</swagger.version>
|
||||
@@ -89,6 +89,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--测试依赖-->
|
||||
<dependency>
|
||||
|
||||
Reference in new issue
Block a user