Commit e4a57ce0 authored by zhangc's avatar zhangc

commit

parent 77c6b4d9
......@@ -49,11 +49,7 @@
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<!--lang3工具类-->
<dependency>
......
......@@ -124,7 +124,7 @@ public class RandomUtil {
String userNum = addZeroForNum(userId, 8);
builder.append(userNum);
}
coding = getCodeInfo(orgCode, coding, builder, month, day, hour, minute, second);
coding = getCodeInfo(userId, coding, builder, month, day, hour, minute, second);
}
return coding;
......
......@@ -26,6 +26,13 @@ public class AuthMallUserApiReq implements Serializable {
@NotNull(message = "apiKey唯一标识不能为空")
private String apiKey;
@ApiModelProperty(value = "组织类型: INT 内部, OUT 外部",required = true)
@NotNull(message = "组织类型不能为空")
private String orgType;
@ApiModelProperty(value = "用户id",required = false)
private String userId;
@ApiModelProperty(value = "组织id",required = true)
@NotNull(message = "组织id不能为空")
private Long orgId;
......
package com.jz.dm.models.resp;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.models.resp
* @PROJECT_NAME: jz-dm-parent
* @NAME: AuthMallUserResponse
* @DATE: 2020-12-30/19:35
* @DAY_NAME_SHORT: 周三
* @Description:
**/
@Data
@ApiModel
public class AuthMallUserResponse implements Serializable {
@ApiModelProperty(value ="授权码")
public String authCode;
@ApiModelProperty(value ="盐值")
public String salt;
}
......@@ -6,8 +6,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jz.common.constant.ResultMsg;
import com.jz.common.utils.Result;
import com.jz.dm.common.constant.Constants;
import com.jz.dm.common.enums.auth.AuthModeEnum;
import com.jz.dm.common.enums.auth.AuthTypeEnum;
import com.jz.dm.common.util.RandomUtil;
import com.jz.dm.mapper.ApiAuthMapper;
import com.jz.dm.mapper.ApiInterfaceMapper;
import com.jz.dm.mapper.ApiOrgMapper;
......@@ -16,6 +18,7 @@ import com.jz.dm.models.domian.ApiInterface;
import com.jz.dm.models.domian.ApiOrg;
import com.jz.dm.models.dto.AuthInfoDto;
import com.jz.dm.models.req.auth.*;
import com.jz.dm.models.resp.AuthMallUserResponse;
import com.jz.dm.service.AuthService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -123,6 +126,7 @@ public class AuthServiceImpl implements AuthService {
*/
@Override
public Result addMallUserApiAuth(AuthMallUserApiReq req) {
AuthMallUserResponse response = new AuthMallUserResponse();
ApiInterface apiInterface = getInterface(req.getApiKey());
if (null == apiInterface) {
return Result.of_error("api授权信息不存在!");
......@@ -133,7 +137,7 @@ public class AuthServiceImpl implements AuthService {
}
//授权验证
if (StringUtils.isNotBlank(req.getAuthType().name()) &&
!AuthTypeEnum.DATA_BANK_AUTH.name().equals(req.getAuthType())) {
!AuthTypeEnum.DATA_BANK_AUTH.name().equals(req.getAuthType())) {
return Result.of_error("授权类型错误!");
}
//认证类型
......@@ -143,21 +147,51 @@ public class AuthServiceImpl implements AuthService {
}
}
if (StringUtils.isNotBlank(req.getAuthMode().name()) &&
AuthModeEnum.PERMANENT_TIME_MODE.name().equals(req.getAuthMode())) {
AuthModeEnum.PERMANENT_TIME_MODE.name().equals(req.getAuthMode())) {
return Result.of_error("授权类型错误!");
}
String authCode = "";
ApiAuth apiAuth = new ApiAuth();
BeanUtils.copyProperties(req, apiAuth);
apiAuth.setApiInterfaceId(apiInterface.getId());
apiAuth.setAuthCode("");//授权码
apiAuth.setSalt("");//盐值
if (StringUtils.isNotBlank(req.getOrgType()) //内部组织
&& Constants.AUTH_INT.equalsIgnoreCase(req.getOrgType())) {
authCode = getAuthCode(apiOrg.getOrgCode(),"",Constants.AUTH_INT);
} else if (StringUtils.isNotBlank(req.getOrgType()) //外部组织
&& Constants.AUTH_OUT.equalsIgnoreCase(req.getOrgType())) {
authCode = getAuthCode("", req.getUserId(),Constants.AUTH_OUT);
}
apiAuth.setAuthCode(authCode);//授权码
String salt = RandomUtil.getStringRandom(8);
apiAuth.setSalt(salt);//盐值
apiAuth.setStatus("1");//授权状态
response.setAuthCode(authCode);
response.setSalt(salt);
if (apiAuthMapper.insert(apiAuth) > 0) {
return Result.of_success(ResultMsg.SUCCESS);
return Result.of_success(response);
}
return Result.of_success(ResultMsg.FAILURE);
}
/**
* 获取授权码
* @param type
* @param userId
* @param apiOrgCode
* @return
*/
private String getAuthCode(String apiOrgCode,String userId,String type) {
String authCode = "";
authCode = RandomUtil.generateTokenCode(type, apiOrgCode, userId);
QueryWrapper<ApiAuth> query = new QueryWrapper<>();
query.eq("auth_code", authCode);
ApiAuth auth = apiAuthMapper.selectOne(query);
if (null != auth) {
authCode = RandomUtil.generateTokenCode(type, apiOrgCode, userId);
}
return authCode;
}
/**
* 修改用户认证信息
*
......@@ -194,11 +228,12 @@ public class AuthServiceImpl implements AuthService {
}
return Result.of_success(ResultMsg.UPDATE_FAIL);
}
private ApiInterface getInterface(String apiKey){
private ApiInterface getInterface(String apiKey) {
QueryWrapper<ApiInterface> queryInface = new QueryWrapper<>();
queryInface.last("where is_deleted=0 and api_key ="+apiKey+"");
queryInface.last("where is_deleted=0 and api_key =" + apiKey + "");
ApiInterface apiInterface = apiInterfaceMapper.selectOne(queryInface);
if (null != apiInterface){
if (null != apiInterface) {
return apiInterface;
}
return null;
......
......@@ -19,6 +19,7 @@
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
......@@ -34,7 +35,12 @@
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
<!--httpclient包-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
......@@ -57,11 +63,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- swagger2接口文档 -->
<dependency>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment