- 后端:User 模块,接入统一的 OAuth2 服务
This commit is contained in:
@@ -17,7 +17,7 @@ import java.util.Map;
|
||||
public interface AdminService {
|
||||
|
||||
/**
|
||||
* 用户认证。认证成功后,返回认证信息
|
||||
* 管理员认证。认证成功后,返回认证信息
|
||||
*
|
||||
* 实际上,就是用户名 + 密码登陆
|
||||
*
|
||||
|
||||
@@ -20,6 +20,8 @@ public interface OAuth2Service {
|
||||
|
||||
// TODO @see 刷新 token
|
||||
|
||||
void removeToken(Integer userId); // TODO 需要优化
|
||||
|
||||
/**
|
||||
* 通过 accessToken 获得身份信息
|
||||
*
|
||||
|
||||
@@ -5,10 +5,12 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel("OAUTH2 认证 BO")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class OAuth2AuthenticationBO {
|
||||
public class OAuth2AuthenticationBO implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", required = true, example = "1")
|
||||
private Integer userId;
|
||||
|
||||
@@ -8,11 +8,12 @@ import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel("OAuth2 创建 Token DTO")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class OAuth2CreateTokenDTO {
|
||||
public class OAuth2CreateTokenDTO implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", required = true, example = "1")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
|
||||
@@ -9,11 +9,12 @@ import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel("OAuth2 身份验证 DTO")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class OAuth2GetTokenDTO {
|
||||
public class OAuth2GetTokenDTO implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "accessToken", required = true, example = "001e8f49b20e47f7b3a2de774497cd50")
|
||||
@NotEmpty(message = "accessToken 不能为空")
|
||||
|
||||
@@ -64,6 +64,7 @@ public class OAuth2ServiceImpl implements OAuth2Service {
|
||||
*
|
||||
* @param adminId 管理员编号
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeToken(Integer adminId) {
|
||||
// 设置 access token 失效
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package cn.iocoder.mall.admin.service;
|
||||
|
||||
import cn.iocoder.common.framework.exception.ServiceException;
|
||||
import cn.iocoder.mall.admin.api.SmsPlatform;
|
||||
import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum;
|
||||
import cn.iocoder.mall.admin.api.constant.SmsApplyStatusEnum;
|
||||
import cn.iocoder.mall.admin.api.exception.SmsFailException;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@@ -104,7 +104,7 @@ public class SmsYunPianPlatform implements SmsPlatform {
|
||||
String result = post(URL_SIGN_ADD, params);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
if (!(jsonObject.getInteger("code") == SUCCESS_CODE)) {
|
||||
throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getCode(),
|
||||
throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getCode(),
|
||||
AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getMessage());
|
||||
}
|
||||
|
||||
@@ -124,13 +124,13 @@ public class SmsYunPianPlatform implements SmsPlatform {
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
|
||||
if (!(jsonObject.getInteger("code") == SUCCESS_CODE)) {
|
||||
throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getCode(),
|
||||
throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getCode(),
|
||||
AdminErrorCodeEnum.SMS_SIGN_ADD_FAIL.getMessage());
|
||||
}
|
||||
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("sign");
|
||||
if (jsonArray.size() <= 0) {
|
||||
throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(),
|
||||
throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(),
|
||||
AdminErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ public class SmsYunPianPlatform implements SmsPlatform {
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
|
||||
if (!(jsonObject.getInteger("code") == SUCCESS_CODE)) {
|
||||
throw new SmsFailException(AdminErrorCodeEnum.SMS_SIGN_UPDATE_FAIL.getCode(),
|
||||
throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_UPDATE_FAIL.getCode(),
|
||||
AdminErrorCodeEnum.SMS_SIGN_UPDATE_FAIL.getMessage());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user