登录
This commit is contained in:
@@ -22,13 +22,9 @@
|
||||
<orderEntry type="library" name="Maven: xerces:xercesImpl:2.11.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
|
||||
<orderEntry type="module" module-name="coolstore-partner-dao" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:3.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.2.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.2.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.2.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.2.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
|
||||
@@ -39,9 +35,32 @@
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.2.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.10.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.10.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.10.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.10.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.10.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.2.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.33" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:9.0.33" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.33" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-validation:2.2.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: jakarta.validation:jakarta.validation-api:2.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.0.18.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.4.1.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.5.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="module" module-name="coolstore-partner-dao" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:3.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.4.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.18" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:3.6.1" level="project" />
|
||||
@@ -64,7 +83,6 @@
|
||||
<orderEntry type="library" name="Maven: com.github.xiaoymin:knife4j-core:2.0.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.javassist:javassist:3.25.0-GA" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.swagger:swagger-models:1.5.22" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.10.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.5.22" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger2:2.9.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-spi:2.9.2" level="project" />
|
||||
@@ -74,11 +92,12 @@
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-common:2.9.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-spring-web:2.9.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:guava:20.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.5.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-metadata:1.2.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mapstruct:mapstruct:1.2.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-bean-validators:2.9.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.xiaoymin:knife4j-spring-ui:2.0.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-core:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.8.3" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -29,6 +29,10 @@
|
||||
<groupId>com.coolstore</groupId>
|
||||
<artifactId>coolstore-partner-model</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.cool.store.service.config.redis;
|
||||
package com.cool.store.config.redis;
|
||||
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.cool.store.config.rest;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author dong_gui on 2020/5/20.
|
||||
*/
|
||||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.cool.store.service.context;
|
||||
package com.cool.store.context;
|
||||
|
||||
import com.cool.store.entity.SysRoleDO;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@@ -36,4 +37,6 @@ public class CurrentUser {
|
||||
private String roleAuth;
|
||||
|
||||
private String mainCorpId;
|
||||
|
||||
private SysRoleDO sysRoleDO;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.cool.store.service.context;
|
||||
package com.cool.store.context;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.cool.store.service.context;
|
||||
package com.cool.store.context;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.cool.store.http;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.utils.RestTemplateUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: ISVHttpRequest
|
||||
* @Description:
|
||||
* @date 2023-05-23 16:03
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ISVHttpRequest {
|
||||
|
||||
@Value("${isv.domain:null}")
|
||||
private String isvDomain;
|
||||
|
||||
@Value("${get.user.id.by.code:null}")
|
||||
private String getUserIdByCode;
|
||||
|
||||
|
||||
public JSONObject getUserIdByCode(String paramStr){
|
||||
String url = isvDomain + getUserIdByCode + paramStr;
|
||||
ResponseEntity<JSONObject> responseEntity = null;
|
||||
try {
|
||||
responseEntity = RestTemplateUtil.loadGet(url, JSONObject.class);
|
||||
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
}
|
||||
if(Objects.isNull(responseEntity)){
|
||||
return null;
|
||||
}
|
||||
return responseEntity.getBody();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
|
||||
public interface LoginService {
|
||||
|
||||
|
||||
|
||||
Object feiShuLogin(String userId, String corpId, Boolean needRefreshToken , String appType, String avatar);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.cool.store.service.EnterpriseConfigService;
|
||||
import com.cool.store.dao.EnterpriseConfigDAO;
|
||||
import com.cool.store.entity.EnterpriseConfigDO;
|
||||
import com.cool.store.service.EnterpriseConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.context.CurrentUser;
|
||||
import com.cool.store.context.DataSourceContext;
|
||||
import com.cool.store.dao.*;
|
||||
import com.cool.store.dto.login.RefreshUser;
|
||||
import com.cool.store.entity.EnterpriseConfigDO;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.entity.SysRoleDO;
|
||||
import com.cool.store.enums.AppTypeEnum;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.enums.UserStatusEnum;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import com.cool.store.model.entity.EnterpriseDO;
|
||||
import com.cool.store.service.LoginService;
|
||||
import com.cool.store.utils.DataSourceHelper;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import com.github.xiaoymin.knife4j.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.crypto.RandomNumberGenerator;
|
||||
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: LoginServiceImpl
|
||||
* @Description:
|
||||
* @date 2023-05-23 9:57
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class LoginServiceImpl implements LoginService {
|
||||
|
||||
@Resource
|
||||
private EnterpriseConfigDAO enterpriseConfigDAO;
|
||||
@Resource
|
||||
private EnterpriseDAO enterpriseDAO;
|
||||
@Resource
|
||||
private EnterpriseUserDAO enterpriseUserDAO;
|
||||
@Resource
|
||||
private SysRoleDAO sysRoleDAO;
|
||||
@Resource
|
||||
private LoginRecordDAO loginRecordDAO;
|
||||
@Resource
|
||||
private RedisUtilPool redisUtilPool;
|
||||
|
||||
@Override
|
||||
public Object feiShuLogin(String userId, String corpId, Boolean needRefreshToken, String appType, String avatar) {
|
||||
log.info("isvLogin, corpId={}, userId={}, appType={}", corpId, userId, appType);
|
||||
DataSourceContext.clearDataSourceType();
|
||||
if (StringUtils.isEmpty(userId)) {
|
||||
throw new ServiceException(ErrorCodeEnum.USER_NOT_EXIST);
|
||||
}
|
||||
if (StringUtils.isEmpty(corpId)) {
|
||||
throw new ServiceException(ErrorCodeEnum.ENTERPRISE_NOT_EXIST);
|
||||
}
|
||||
EnterpriseConfigDO enterpriseConfig = enterpriseConfigDAO.getConfigByCorpIdAndAppType(corpId, appType);
|
||||
if (enterpriseConfig == null) {
|
||||
throw new ServiceException(ErrorCodeEnum.ENTERPRISE_INIT);
|
||||
}
|
||||
EnterpriseDO enterprise = enterpriseDAO.getEnterpriseById(enterpriseConfig.getEnterpriseId());
|
||||
if (enterprise == null || enterprise.getStatus() == CommonConstants.ZERO) {
|
||||
throw new ServiceException(ErrorCodeEnum.ENTERPRISE_INIT);
|
||||
}
|
||||
CurrentUser currentUser = new CurrentUser();
|
||||
RefreshUser refreshUser = new RefreshUser();
|
||||
String dbName = enterpriseConfig.getDbName();
|
||||
// 切到企业库
|
||||
DataSourceContext.setDataSourceType(dbName);
|
||||
// 查企业用户
|
||||
EnterpriseUserDO enterpriseUser = enterpriseUserDAO.getUserInfoById(enterprise.getId(), userId);
|
||||
if(enterpriseUser == null){
|
||||
throw new ServiceException(ErrorCodeEnum.NOT_AUTH);
|
||||
}
|
||||
//冻结登录 超登用户过滤
|
||||
if (enterprise.getStatus() == CommonConstants.HUNDRED && !StringUtils.equals(enterpriseUser.getUserId(), "a100000001")) {
|
||||
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR.getCode(), "企业被冻结");
|
||||
}
|
||||
SysRoleDO sysRole = sysRoleDAO.getHighestPrioritySysRoleDoByUserId(enterprise.getId(), userId);
|
||||
if(Objects.isNull(sysRole)){
|
||||
log.info("当前用户没角色:{}", userId);
|
||||
throw new ServiceException(ErrorCodeEnum.NOT_AUTH);
|
||||
}
|
||||
if(UserStatusEnum.FREEZE.getCode().equals(enterpriseUser.getUserStatus())){
|
||||
throw new ServiceException(ErrorCodeEnum.USER_FREEZE);
|
||||
}
|
||||
if(UserStatusEnum.WAIT_AUDIT.getCode().equals(enterpriseUser.getUserStatus())){
|
||||
throw new ServiceException(ErrorCodeEnum.USER_WAIT_AUDIT);
|
||||
}
|
||||
//用户是否已有头像
|
||||
Boolean hasAvatar = StringUtils.isNotEmpty(enterpriseUser.getAvatar()) && !enterpriseUser.getAvatar().contains(CommonConstants.DEFAULT_AVATAR);
|
||||
String finalAvatar = hasAvatar ? enterpriseUser.getAvatar() : avatar;
|
||||
enterpriseUser.setAvatar(finalAvatar);
|
||||
enterpriseUser.setFaceUrl(finalAvatar);
|
||||
currentUser.setUserId(enterpriseUser.getUserId());
|
||||
currentUser.setDbName(enterpriseConfig.getDbName());
|
||||
currentUser.setIsAdmin(enterpriseUser.getIsAdmin());
|
||||
currentUser.setMainCorpId(enterpriseConfig.getMainCorpId());
|
||||
//设置当前登录人使用的企业相关信息
|
||||
currentUser.setRoleAuth(sysRole.getRoleAuth());
|
||||
currentUser.setSysRoleDO(sysRole);
|
||||
currentUser.setEnterpriseId(enterprise.getId());
|
||||
//生成令牌
|
||||
RandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator();
|
||||
String token = randomNumberGenerator.nextBytes().toHex();
|
||||
String refreshToken = randomNumberGenerator.nextBytes().toHex();
|
||||
currentUser.setName(enterpriseUser.getName());
|
||||
currentUser.setDingCorpId(enterpriseConfig.getDingCorpId());
|
||||
currentUser.setAccessToken(token);
|
||||
currentUser.setAppType(appType);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("action_token", token);
|
||||
jsonObject.put("user", currentUser);
|
||||
redisUtilPool.setString(CommonConstants.ACCESS_TOKEN_KEY + ":" + token, JSON.toJSONString(currentUser), CommonConstants.ACTION_TOKEN_EXPIRE);
|
||||
jsonObject.put("expire", CommonConstants.ACTION_TOKEN_EXPIRE);
|
||||
redisUtilPool.setString(currentUser.getUserId(), token);
|
||||
redisUtilPool.setString(CommonConstants.REFRESH_TOKEN_KEY+":"+refreshToken,JSON.toJSONString(refreshUser), CommonConstants.REFRESH_TOKEN_EXPIRE);
|
||||
jsonObject.put("refresh_token",refreshToken);
|
||||
loginRecordDAO.addLoginRecord(currentUser.getEnterpriseId(),currentUser.getUserId());
|
||||
log.info("[" + enterpriseUser.getName() + "; action_token:"+ token + "; userId:" + currentUser.getUserId() +"]登入系统成功");
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.cool.store.service.utils;
|
||||
package com.cool.store.utils;
|
||||
|
||||
import com.cool.store.service.context.DataSourceContext;
|
||||
import com.cool.store.service.context.UserContext;
|
||||
import com.cool.store.context.DataSourceContext;
|
||||
import com.cool.store.context.UserContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
Reference in New Issue
Block a user