登陆代码迁移jianquan接口鉴权
This commit is contained in:
23
pom.xml
23
pom.xml
@ -13,8 +13,31 @@
|
||||
<artifactId>sys_manager_ebtp_project</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<name>sys_manager_ebtp_project</name>
|
||||
<properties>
|
||||
<spring.cloud.version>Hoxton.SR7</spring.cloud.version>
|
||||
<com.alibaba.cloud.version>2.2.3.RELEASE</com.alibaba.cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
<version>2.2.3.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring.cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>${com.alibaba.cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.chinaunicom.mall.ebtp</groupId>
|
||||
<artifactId>uboot-core</artifactId>
|
||||
|
@ -32,7 +32,7 @@ public class CaptchaGenerator {
|
||||
@Value("${login.captcha.privateKey}")
|
||||
private String privateKey;
|
||||
|
||||
public BuffeedImageVo generateCaptcha() {
|
||||
public BuffeedImageVo generateCaptcha() throws IOException {
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g = image.createGraphics();
|
||||
|
||||
@ -69,15 +69,22 @@ public class CaptchaGenerator {
|
||||
BuffeedImageVo vo = new BuffeedImageVo();
|
||||
|
||||
vo.setCode(sb.toString());
|
||||
vo.setImage(image);
|
||||
// vo.setImage(image);
|
||||
// 在 generateCaptcha() 或其他方法中添加如下代码
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(image, "png", baos); // 将 image 写入 ByteArrayOutputStream
|
||||
byte[] imageBytes = baos.toByteArray();
|
||||
String base64Image = Base64.getEncoder().encodeToString(imageBytes);
|
||||
vo.setBase64Image(base64Image);
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取图形验证码
|
||||
* @return
|
||||
*/
|
||||
public BuffeedImageVo getCaptcha(){
|
||||
public BuffeedImageVo getCaptcha() throws IOException {
|
||||
BuffeedImageVo vo = this.generateCaptcha();
|
||||
String creteTime = LocalDateTimeUtil.format(LocalDateTime.now().plusMinutes(timeLimit), "yyyy-MM-dd HH:mm:ss");
|
||||
String code = encoded(vo.getCode()+"_"+creteTime);
|
||||
@ -92,7 +99,7 @@ public class CaptchaGenerator {
|
||||
public Boolean checkCaptcha(String value, String captch){
|
||||
|
||||
try{
|
||||
String cap = this.encoded(captch);
|
||||
String cap = this.decrypt(captch);
|
||||
String[] caps = cap.split("_");
|
||||
String time = caps[1];
|
||||
LocalDateTime ltime = LocalDateTimeUtil.parse(time,"yyyy-MM-dd HH:mm:ss");
|
||||
|
@ -18,6 +18,7 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@ -37,7 +38,11 @@ public class LoginController {
|
||||
@ApiOperation("获取图形验证码")
|
||||
@GetMapping("/getCaptcha")
|
||||
public BaseResponse getCaptcha(){
|
||||
return BaseResponse.success(captchaGenerator.getCaptcha());
|
||||
try {
|
||||
return BaseResponse.success(captchaGenerator.getCaptcha());
|
||||
} catch (IOException e) {
|
||||
return BaseResponse.fail(CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 账号 密码 图形验证码
|
||||
@ -49,7 +54,7 @@ public class LoginController {
|
||||
public BaseResponse idcardLogin(HttpServletResponse response,@RequestBody LoginUserVo vo) {
|
||||
if(captchaGenerator.checkCaptcha(vo.getIdentifying(),vo.getEncryptValue())){
|
||||
BaseSelf self = iBaseUserService.idcardLogin(vo.getAccount(), vo.getPassword());
|
||||
this.iBaseUserService.setCookie(response,"mall3_token",self.getToken());
|
||||
this.iBaseUserService.setCookie(response,"mall3_token"+self.getUser().getUserId(),self.getToken());
|
||||
return BaseResponse.success(self);
|
||||
}else{
|
||||
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("验证码无效",true);
|
||||
|
@ -9,4 +9,5 @@ public class BuffeedImageVo {
|
||||
|
||||
private String code;
|
||||
private BufferedImage image;
|
||||
private String base64Image;
|
||||
}
|
||||
|
@ -219,6 +219,11 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
|
||||
securityEntity.setStaffId(baseUser.getEmployeeNumber());
|
||||
securityEntity.setUsername(baseUser.getName());
|
||||
securityEntity.setStaffName(baseUser.getName());
|
||||
securityEntity.setOu(baseUser.getOrgId());//部门id
|
||||
securityEntity.setOuName(baseUser.getOrgName());
|
||||
securityEntity.setOrgId("1");//公司Id
|
||||
securityEntity.setOrgName("中远");
|
||||
securityEntity.setUserSource("0");//账号类型中远
|
||||
List<AuthorityEntity> authorityList =this.baseUserMapper.selectRoleByUserId(baseUser.getUserId());;
|
||||
securityEntity.setAuthorityList(authorityList);
|
||||
return securityEntity;
|
||||
|
@ -1,8 +1,13 @@
|
||||
package com.chinaunicom.mall.ebtp.userinfo.controller;
|
||||
|
||||
import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.entity.CheckTokenVo;
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import com.chinaunicom.mall.ebtp.common.exception.common.CommonExceptionEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Slf4j
|
||||
@ -29,15 +34,15 @@ public class CheckTokenController {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
// @GetMapping("/getCheckTokenVo")
|
||||
// public BaseResponse<CheckTokenVo> getCheckTokenVo(@RequestParam(value="ps",required = false) String ps){
|
||||
// CommonExceptionEnum.LOGIN_CHECK_TOKEN_EXPIRATION.assertStringNotNullByKey("网络异常",ps);
|
||||
// CheckTokenVo vo = new CheckTokenVo();
|
||||
// vo.setTimeLimit(timeLimit);
|
||||
// vo.setOnof(onof);
|
||||
// vo.setCheckprivateKey(checkprivateKey);
|
||||
// vo.setCheckpublicKey(checkpublicKey);
|
||||
// return BaseResponse.success(vo);
|
||||
// }
|
||||
@GetMapping("/getCheckTokenVo")
|
||||
public BaseResponse<CheckTokenVo> getCheckTokenVo(@RequestParam(value="ps",required = false) String ps){
|
||||
CommonExceptionEnum.LOGIN_CHECK_TOKEN_EXPIRATION.assertStringNotNullByKey("网络异常",ps);
|
||||
CheckTokenVo vo = new CheckTokenVo();
|
||||
vo.setTimeLimit(timeLimit);
|
||||
vo.setOnof(onof);
|
||||
vo.setCheckprivateKey(checkprivateKey);
|
||||
vo.setCheckpublicKey(checkpublicKey);
|
||||
return BaseResponse.success(vo);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,11 +2,15 @@ package com.chinaunicom.mall.ebtp.userinfo.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityEntity;
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||
import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService;
|
||||
import com.chinaunicom.mall.ebtp.common.exception.common.CommonExceptionEnum;
|
||||
import com.chinaunicom.mall.ebtp.faceCompare.feign.SupplierbaseFeignClient;
|
||||
import com.chinaunicom.mall.ebtp.login.common.Constants;
|
||||
import com.chinaunicom.mall.ebtp.login.entity.BaseUserToken;
|
||||
import com.chinaunicom.mall.ebtp.login.service.BaseUserTokenService;
|
||||
import com.chinaunicom.mall.ebtp.userinfo.entity.*;
|
||||
import com.chinaunicom.mall.ebtp.userinfo.service.EbtpUserInfoService;
|
||||
import com.chinaunicom.mall.ebtp.userinfo.utils.BaseCertService;
|
||||
@ -27,7 +31,9 @@ import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -59,6 +65,9 @@ public class UserInfoController {
|
||||
|
||||
private static Map<String,SecurityEntity> securityEntityMap;
|
||||
|
||||
@Autowired
|
||||
private BaseUserTokenService baseUserTokenService;
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
@ -229,12 +238,33 @@ public class UserInfoController {
|
||||
log.info("path:"+path);
|
||||
String str = HttpUtils.checkTokenHttpGet(path);
|
||||
|
||||
securityEntity = JSON.parseObject(str,SecurityEntity.class);
|
||||
securityEntity = JSON.parseObject(str,SecurityEntity.class);
|
||||
|
||||
//Object o = unifastOAuthBdClient.get(token);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return securityEntity;
|
||||
}
|
||||
@PostMapping("oauth/check_token")
|
||||
public SecurityEntity getPost(@RequestParam("token") String token){
|
||||
SecurityEntity securityEntity = new SecurityEntity();
|
||||
try {
|
||||
// String path = checkTokenPath+"?token="+token;
|
||||
// log.info("path:"+path);
|
||||
// String str = HttpUtils.checkTokenHttpGet(path);
|
||||
List<BaseUserToken> tokenList = baseUserTokenService.list((new LambdaQueryWrapper<BaseUserToken>().eq(BaseUserToken::getToken,token)
|
||||
.gt(BaseUserToken::getValidTime, LocalDateTime.now()).eq(BaseUserToken::getState, Constants.USER_TOKEN_STATUS_E).orderByDesc(BaseUserToken::getValidTime)));
|
||||
if ((tokenList!=null)&&tokenList.size()>0){
|
||||
BaseUserToken tokenObj = tokenList.get(0);
|
||||
securityEntity = JSON.parseObject(tokenObj.getUserObject(),SecurityEntity.class);
|
||||
}
|
||||
//Object o = unifastOAuthBdClient.get(token);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return securityEntity;
|
||||
}
|
||||
// SecurityEntity getPost(@RequestParam("token") String token);
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ import com.chinaunicom.mall.ebtp.userinfo.service.EbtpUserInfoService;
|
||||
import com.chinaunicom.mall.ebtp.userinfo.service.UnicomOAuthClient;
|
||||
import com.chinaunicom.mall.ebtp.userinfo.utils.HttpsUtils;
|
||||
import com.chinaunicom.mall.ebtp.userinfo.utils.UserinfoConstants;
|
||||
import com.coscoshipping.ebtp.project.role.dao.SysRoleMapper;
|
||||
import com.coscoshipping.ebtp.project.role.entity.SysRole;
|
||||
import com.coscoshipping.ebtp.project.user.entity.SysUser;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -43,6 +45,8 @@ public class EbtpUserInfoServiceImpl implements EbtpUserInfoService {
|
||||
@Autowired
|
||||
private BaseRoleMapper baseRoleMapper;
|
||||
|
||||
@Autowired
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
@Autowired
|
||||
@Qualifier("userinfoRedisTemplate")
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
@ -77,7 +81,7 @@ public class EbtpUserInfoServiceImpl implements EbtpUserInfoService {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
List<SysUser> users = baseUserMapper.selectList(Wrappers.lambdaQuery(SysUser.class));
|
||||
map.put(USERS, JsonUtils.objectToJson(users));
|
||||
List<BaseRole> roles = baseRoleMapper.selectList(Wrappers.emptyWrapper());
|
||||
List<SysRole> roles = sysRoleMapper.selectList(Wrappers.emptyWrapper());
|
||||
map.put(ROLES, JsonUtils.objectToJson(roles));
|
||||
redisTemplate.opsForValue().set(REDIS_USER_KEY_EXTEND, JsonUtils.objectToJson(map), 24, TimeUnit.HOURS);
|
||||
return true;
|
||||
|
@ -16,9 +16,9 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
DataSourceAutoConfiguration.class,
|
||||
DruidDataSourceAutoConfigure.class
|
||||
})
|
||||
@EnableFeignClients(basePackages = {"com.coscoshipping.ebtp.*", "com.chinaunicom.mall.ebtp.*"})
|
||||
@MapperScan({"com.coscoshipping.ebtp.project.**.dao", "com.chinaunicom.mall.ebtp.**.dao"})
|
||||
@ComponentScan(basePackages = {"com.coscoshipping.ebtp.*", "com.chinaunicom.mall.ebtp.*"})
|
||||
@EnableFeignClients(basePackages = {"com.coscoshipping.ebtp.*","com.chinaunicom.mall.ebtp.cloud.*","com.chinaunicom.mall.ebtp.*"})
|
||||
@MapperScan({"com.coscoshipping.ebtp.project.**.dao","com.chinaunicom.mall.ebtp.**.dao"})
|
||||
@ComponentScan(basePackages = {"com.coscoshipping.ebtp.*","com.chinaunicom.mall.ebtp.cloud.*","com.chinaunicom.mall.ebtp.*"})
|
||||
public class SysManagerEbtpProjectApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -5,6 +5,12 @@ server:
|
||||
|
||||
spring:
|
||||
cloud:
|
||||
feign:
|
||||
client:
|
||||
config:
|
||||
connectTimeout: 55000
|
||||
readTimeout: 35000
|
||||
writeTimeout: 35000
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:18848
|
||||
@ -86,6 +92,7 @@ spring:
|
||||
userinfo: 4
|
||||
|
||||
|
||||
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
# 是否开启自动驼峰命名规则映射:从数据库列名到Java属性驼峰命名的类似映射
|
||||
@ -116,10 +123,10 @@ hystrix:
|
||||
forceClosed: true
|
||||
|
||||
ribbon:
|
||||
ReadTimeout: 20000 #请求处理的超时时间
|
||||
ConnectTimeout: 20000 #请求连接超时时间
|
||||
MaxAutoRetries: 0 #对当前实例的重试次数
|
||||
MaxAutoRetriesNextServer: 1 #切换实例的重试次数 1
|
||||
ReadTimeout: 200000 #请求处理的超时时间
|
||||
ConnectTimeout: 200000 #请求连接超时时间
|
||||
MaxAutoRetries: 1 #对当前实例的重试次数
|
||||
MaxAutoRetriesNextServer: 2 #切换实例的重试次数 1
|
||||
|
||||
mconfig:
|
||||
swagger-ui-open: true
|
||||
@ -257,3 +264,8 @@ login:
|
||||
privateKey: MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAK8sGQAshhH/H1G/lOJdAZYBdPOto38d7zSv2BCi9JDmhM/yqWUv345zUt1OKM8VGx10daDfu6a8WWLCGa6RTU1P6jaWgZwqnIwcWRz9Q82NAu935gVHidiGA/yX52ZE061BZrA63l1uSxEpOCEyMD4UpPb6K0yxrBKzX4hz7OgjAgMBAAECgYAT/jx8QJisxSmV8v/TNjpQHKp0hYT7pTcAFHHctDylrSnLci7TVbt2TsNObvVJbWdC3V/vlJmeVjD9jJnRytO/pgc+p8I3Q3pfF7ACiBAz1+4VZM40vFz0RfQKJ/kZB3DiGohprOw60kRR0eMtHuaA07luhBCbne6700Paf+OOAQJBAP9THm3KEcnChnRBC6yPdNHLN/XplgGaIJU2Wo0biI8Oz2bM3eJGPSwrVCqObOwVPNYJIfEQRhlWlB9kpBS0ECECQQCvorUUJwJhV+Fx6bhUK5aa1/rDTODPmS1MycvLtjOp7ig1sGcb4g9Vl8uRPzsvQZ6Z+sNTD4mFFnYFneCvPL/DAkAMZo4QyQKqKO98z/fwLpt+4P7by7eEZmb0uEoXlmHAiPibxpF0PvMTpRsWYgp6QOHOh20Fl0PAUUsqZyns833hAkBEzV9UIqfrDCsTnbQIvP6FcAAay53xlRbK0u5Twe9hLRtxVMY/hQHuzMUBBB0iOPlxZmtnuVls2kynjJ4853ZTAkEAu+lLTmM7DBV9jDEc9sNM7UNa0MvAUb6r9DsTKHGLLRqB7ljQ1R2RiLRknFaegUPEVsvdMszH2rdy3CaIWkC5OQ==
|
||||
publicKey: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCvLBkALIYR/x9Rv5TiXQGWAXTzraN/He80r9gQovSQ5oTP8qllL9+Oc1LdTijPFRsddHWg37umvFliwhmukU1NT+o2loGcKpyMHFkc/UPNjQLvd+YFR4nYhgP8l+dmRNOtQWawOt5dbksRKTghMjA+FKT2+itMsawSs1+Ic+zoIwIDAQAB
|
||||
time_limit: 2 #Minutes
|
||||
|
||||
user:
|
||||
auth:
|
||||
resource:
|
||||
serviceId: sys-manager-ebtp-project
|
||||
|
Reference in New Issue
Block a user