Commit e4a57ce0 authored by zhangc's avatar zhangc

commit

parent 77c6b4d9
...@@ -49,11 +49,7 @@ ...@@ -49,11 +49,7 @@
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<!--lang3工具类--> <!--lang3工具类-->
<dependency> <dependency>
......
...@@ -124,7 +124,7 @@ public class RandomUtil { ...@@ -124,7 +124,7 @@ public class RandomUtil {
String userNum = addZeroForNum(userId, 8); String userNum = addZeroForNum(userId, 8);
builder.append(userNum); 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; return coding;
......
...@@ -26,6 +26,13 @@ public class AuthMallUserApiReq implements Serializable { ...@@ -26,6 +26,13 @@ public class AuthMallUserApiReq implements Serializable {
@NotNull(message = "apiKey唯一标识不能为空") @NotNull(message = "apiKey唯一标识不能为空")
private String 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) @ApiModelProperty(value = "组织id",required = true)
@NotNull(message = "组织id不能为空") @NotNull(message = "组织id不能为空")
private Long orgId; 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; ...@@ -6,8 +6,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jz.common.constant.ResultMsg; import com.jz.common.constant.ResultMsg;
import com.jz.common.utils.Result; 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.AuthModeEnum;
import com.jz.dm.common.enums.auth.AuthTypeEnum; 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.ApiAuthMapper;
import com.jz.dm.mapper.ApiInterfaceMapper; import com.jz.dm.mapper.ApiInterfaceMapper;
import com.jz.dm.mapper.ApiOrgMapper; import com.jz.dm.mapper.ApiOrgMapper;
...@@ -16,6 +18,7 @@ import com.jz.dm.models.domian.ApiInterface; ...@@ -16,6 +18,7 @@ import com.jz.dm.models.domian.ApiInterface;
import com.jz.dm.models.domian.ApiOrg; import com.jz.dm.models.domian.ApiOrg;
import com.jz.dm.models.dto.AuthInfoDto; import com.jz.dm.models.dto.AuthInfoDto;
import com.jz.dm.models.req.auth.*; import com.jz.dm.models.req.auth.*;
import com.jz.dm.models.resp.AuthMallUserResponse;
import com.jz.dm.service.AuthService; import com.jz.dm.service.AuthService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -123,6 +126,7 @@ public class AuthServiceImpl implements AuthService { ...@@ -123,6 +126,7 @@ public class AuthServiceImpl implements AuthService {
*/ */
@Override @Override
public Result addMallUserApiAuth(AuthMallUserApiReq req) { public Result addMallUserApiAuth(AuthMallUserApiReq req) {
AuthMallUserResponse response = new AuthMallUserResponse();
ApiInterface apiInterface = getInterface(req.getApiKey()); ApiInterface apiInterface = getInterface(req.getApiKey());
if (null == apiInterface) { if (null == apiInterface) {
return Result.of_error("api授权信息不存在!"); return Result.of_error("api授权信息不存在!");
...@@ -146,18 +150,48 @@ public class AuthServiceImpl implements AuthService { ...@@ -146,18 +150,48 @@ public class AuthServiceImpl implements AuthService {
AuthModeEnum.PERMANENT_TIME_MODE.name().equals(req.getAuthMode())) { AuthModeEnum.PERMANENT_TIME_MODE.name().equals(req.getAuthMode())) {
return Result.of_error("授权类型错误!"); return Result.of_error("授权类型错误!");
} }
String authCode = "";
ApiAuth apiAuth = new ApiAuth(); ApiAuth apiAuth = new ApiAuth();
BeanUtils.copyProperties(req, apiAuth); BeanUtils.copyProperties(req, apiAuth);
apiAuth.setApiInterfaceId(apiInterface.getId()); apiAuth.setApiInterfaceId(apiInterface.getId());
apiAuth.setAuthCode("");//授权码 if (StringUtils.isNotBlank(req.getOrgType()) //内部组织
apiAuth.setSalt("");//盐值 && 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");//授权状态 apiAuth.setStatus("1");//授权状态
response.setAuthCode(authCode);
response.setSalt(salt);
if (apiAuthMapper.insert(apiAuth) > 0) { if (apiAuthMapper.insert(apiAuth) > 0) {
return Result.of_success(ResultMsg.SUCCESS); return Result.of_success(response);
} }
return Result.of_success(ResultMsg.FAILURE); 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 { ...@@ -194,11 +228,12 @@ public class AuthServiceImpl implements AuthService {
} }
return Result.of_success(ResultMsg.UPDATE_FAIL); return Result.of_success(ResultMsg.UPDATE_FAIL);
} }
private ApiInterface getInterface(String apiKey){
private ApiInterface getInterface(String apiKey) {
QueryWrapper<ApiInterface> queryInface = new QueryWrapper<>(); 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); ApiInterface apiInterface = apiInterfaceMapper.selectOne(queryInface);
if (null != apiInterface){ if (null != apiInterface) {
return apiInterface; return apiInterface;
} }
return null; return null;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
...@@ -34,7 +35,12 @@ ...@@ -34,7 +35,12 @@
<groupId>org.springframework.session</groupId> <groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId> <artifactId>spring-session-data-redis</artifactId>
</dependency> </dependency>
<!--httpclient包-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<!-- fastjson --> <!-- fastjson -->
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
...@@ -57,11 +63,11 @@ ...@@ -57,11 +63,11 @@
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
</dependency> </dependency>
<!-- lombok --> <!-- lombok -->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
</dependency> </dependency>
<!-- swagger2接口文档 --> <!-- swagger2接口文档 -->
<dependency> <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