mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 12:52:07 +08:00
新增imes-token获取组织id接口
This commit is contained in:
@@ -22,10 +22,11 @@ logging:
|
|||||||
chenfeng:
|
chenfeng:
|
||||||
gateway:
|
gateway:
|
||||||
ignore-token-urls:
|
ignore-token-urls:
|
||||||
|
- /admin-api/system/auth/app-token/organ-id
|
||||||
- /admin-api/executor/plate/wechat/miniprogram/cadview/info/*
|
- /admin-api/executor/plate/wechat/miniprogram/cadview/info/*
|
||||||
- /admin-api/executor/plate/wechat/miniprogram/cadview/order/info/*
|
- /admin-api/executor/plate/wechat/miniprogram/cadview/order/info/*
|
||||||
- /admin-api/executor/plate/wechat/miniprogram/cadview/order/details/*
|
- /admin-api/executor/plate/wechat/miniprogram/cadview/order/details/*
|
||||||
accessLogEnable: false
|
accessLogEnable: false
|
||||||
access-log-ignore-urls:
|
access-log-ignore-urls:
|
||||||
- /report/template
|
- /report/template
|
||||||
- /system/captcha/get
|
- /system/captcha/get
|
||||||
|
|||||||
+21
-2
@@ -14,9 +14,12 @@ import com.cf.imes.framework.security.config.SecurityProperties;
|
|||||||
import com.cf.imes.framework.security.core.LoginUser;
|
import com.cf.imes.framework.security.core.LoginUser;
|
||||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||||
import com.cf.imes.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
|
import com.cf.imes.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
|
||||||
|
import com.cf.imes.module.system.controller.admin.auth.vo.AuthAppTokenReqVO;
|
||||||
import com.cf.imes.module.system.controller.admin.auth.vo.AuthLoginReqVO;
|
import com.cf.imes.module.system.controller.admin.auth.vo.AuthLoginReqVO;
|
||||||
|
import com.cf.imes.module.system.controller.admin.auth.vo.AuthLoginRespVO;
|
||||||
import com.cf.imes.module.system.controller.admin.auth.vo.AuthLoginSmsCheckReqVO;
|
import com.cf.imes.module.system.controller.admin.auth.vo.AuthLoginSmsCheckReqVO;
|
||||||
import com.cf.imes.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO;
|
import com.cf.imes.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO;
|
||||||
|
import com.cf.imes.module.system.controller.admin.auth.vo.AuthSmsSendReqVO;
|
||||||
import com.cf.imes.module.system.convert.auth.AuthConvert;
|
import com.cf.imes.module.system.convert.auth.AuthConvert;
|
||||||
import com.cf.imes.module.system.dal.dataobject.organ.OrganizationDO;
|
import com.cf.imes.module.system.dal.dataobject.organ.OrganizationDO;
|
||||||
import com.cf.imes.module.system.dal.dataobject.permission.MenuDO;
|
import com.cf.imes.module.system.dal.dataobject.permission.MenuDO;
|
||||||
@@ -29,9 +32,8 @@ import com.cf.imes.module.system.service.permission.MenuService;
|
|||||||
import com.cf.imes.module.system.service.permission.PermissionService;
|
import com.cf.imes.module.system.service.permission.PermissionService;
|
||||||
import com.cf.imes.module.system.service.permission.RoleService;
|
import com.cf.imes.module.system.service.permission.RoleService;
|
||||||
import com.cf.imes.module.system.service.sms.SmsCodeService;
|
import com.cf.imes.module.system.service.sms.SmsCodeService;
|
||||||
|
import com.cf.imes.module.system.service.tokenconfig.TokenConfigService;
|
||||||
import com.cf.imes.module.system.service.user.AdminUserService;
|
import com.cf.imes.module.system.service.user.AdminUserService;
|
||||||
import com.cf.imes.module.system.controller.admin.auth.vo.AuthLoginRespVO;
|
|
||||||
import com.cf.imes.module.system.controller.admin.auth.vo.AuthSmsSendReqVO;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@@ -86,6 +88,9 @@ public class AuthController {
|
|||||||
@Resource
|
@Resource
|
||||||
private IPQueryService ipQueryService;
|
private IPQueryService ipQueryService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TokenConfigService tokenConfigService;
|
||||||
|
|
||||||
@PostMapping("/manage/login")
|
@PostMapping("/manage/login")
|
||||||
@PermitAll
|
@PermitAll
|
||||||
@Operation(summary = "使用账号密码登录")
|
@Operation(summary = "使用账号密码登录")
|
||||||
@@ -120,6 +125,20 @@ public class AuthController {
|
|||||||
return success(authService.loginSmsCheck(reqVO));
|
return success(authService.loginSmsCheck(reqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据应用 Token 获取所属组织编号,供外部应用在未登录场景下识别组织。
|
||||||
|
*
|
||||||
|
* @param reqVO 应用 Token 请求参数
|
||||||
|
* @return 组织编号
|
||||||
|
*/
|
||||||
|
@PostMapping("/app-token/organ-id")
|
||||||
|
@PermitAll
|
||||||
|
@Operation(summary = "根据应用 Token 获取组织编号")
|
||||||
|
@OperateLog(enable = false)
|
||||||
|
public CommonResult<Long> getOrganIdByAppToken(@Valid @RequestBody AuthAppTokenReqVO reqVO) {
|
||||||
|
return success(tokenConfigService.getOrganIdByAppToken(reqVO.getAppToken()));
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/logout")
|
@PostMapping("/logout")
|
||||||
@PermitAll
|
@PermitAll
|
||||||
@Operation(summary = "登出系统")
|
@Operation(summary = "登出系统")
|
||||||
|
|||||||
+2
-1
@@ -47,7 +47,8 @@ public interface TokenConfigMapper extends BaseMapperX<TokenConfigDO> {
|
|||||||
|
|
||||||
default TokenConfigDO selectByToken(String token) {
|
default TokenConfigDO selectByToken(String token) {
|
||||||
return selectOne(new LambdaQueryWrapperX<TokenConfigDO>()
|
return selectOne(new LambdaQueryWrapperX<TokenConfigDO>()
|
||||||
.eq(TokenConfigDO::getAppToken,token));
|
.eq(TokenConfigDO::getAppToken, token)
|
||||||
|
.eq(TokenConfigDO::getDeleted, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteTokenConfig(@Param("id") Long id);
|
void deleteTokenConfig(@Param("id") Long id);
|
||||||
|
|||||||
+8
@@ -57,6 +57,14 @@ public interface TokenConfigService {
|
|||||||
*/
|
*/
|
||||||
Long checkTokenConfig(String token);
|
Long checkTokenConfig(String token);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据数据库中存储的应用 Token 获取所属组织编号。
|
||||||
|
*
|
||||||
|
* @param appToken 应用 Token
|
||||||
|
* @return 组织编号
|
||||||
|
*/
|
||||||
|
Long getOrganIdByAppToken(String appToken);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 复制token
|
* 复制token
|
||||||
*
|
*
|
||||||
|
|||||||
+8
-3
@@ -207,8 +207,13 @@ public class TokenConfigServiceImpl implements TokenConfigService{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long checkTokenConfig(String token) {
|
public Long checkTokenConfig(String token) {
|
||||||
|
return getOrganIdByAppToken(token.substring(FIELD_IMES.length()));
|
||||||
|
}
|
||||||
|
|
||||||
TokenConfigDO tokenConfigDO = tokenConfigMapper.selectByToken(token.substring(5));
|
@Override
|
||||||
|
public Long getOrganIdByAppToken(String appToken) {
|
||||||
|
// 应用 Token 必须存在且处于有效期内,避免失效配置继续访问外部接口。
|
||||||
|
TokenConfigDO tokenConfigDO = tokenConfigMapper.selectByToken(appToken);
|
||||||
|
|
||||||
if(tokenConfigDO == null){
|
if(tokenConfigDO == null){
|
||||||
throw new ServiceException(TOKEN_CONFIG_NOT_EXISTS);
|
throw new ServiceException(TOKEN_CONFIG_NOT_EXISTS);
|
||||||
@@ -219,7 +224,7 @@ public class TokenConfigServiceImpl implements TokenConfigService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
Long organId = tokenConfigDO.getOrganId();
|
Long organId = tokenConfigDO.getOrganId();
|
||||||
|
// 同步校验组织状态和有效期,保证返回的组织编号当前可用。
|
||||||
OrganizationDO organizationDO = organMapper.selectById(organId);
|
OrganizationDO organizationDO = organMapper.selectById(organId);
|
||||||
|
|
||||||
if (organizationDO == null) {
|
if (organizationDO == null) {
|
||||||
@@ -326,4 +331,4 @@ public class TokenConfigServiceImpl implements TokenConfigService{
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ chenfeng:
|
|||||||
- /admin-api/system/user/reset-password
|
- /admin-api/system/user/reset-password
|
||||||
- /admin-api/system/auth/login/check
|
- /admin-api/system/auth/login/check
|
||||||
- /admin-api/system/auth/login/sms/check
|
- /admin-api/system/auth/login/sms/check
|
||||||
|
- /admin-api/system/auth/app-token/organ-id
|
||||||
- /admin-api/system/token/check
|
- /admin-api/system/token/check
|
||||||
- /rpc-api/**
|
- /rpc-api/**
|
||||||
- /admin-api/system/pay/**
|
- /admin-api/system/pay/**
|
||||||
@@ -360,4 +361,4 @@ aj:
|
|||||||
|
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
configuration:
|
configuration:
|
||||||
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
|
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||||
|
|||||||
@@ -202,6 +202,7 @@ chenfeng:
|
|||||||
- /admin-api/system/user/reset-password
|
- /admin-api/system/user/reset-password
|
||||||
- /admin-api/system/auth/login/check
|
- /admin-api/system/auth/login/check
|
||||||
- /admin-api/system/auth/login/sms/check
|
- /admin-api/system/auth/login/sms/check
|
||||||
|
- /admin-api/system/auth/app-token/organ-id
|
||||||
- /admin-api/system/token/check
|
- /admin-api/system/token/check
|
||||||
- /rpc-api/**
|
- /rpc-api/**
|
||||||
- /admin-api/system/pay/**
|
- /admin-api/system/pay/**
|
||||||
|
|||||||
@@ -108,4 +108,6 @@ assembly.config.import.orderIds.size=訂單號清單長度不能超過100
|
|||||||
assembly.config.save.id.notNull=裝備設定編號不能為空
|
assembly.config.save.id.notNull=裝備設定編號不能為空
|
||||||
assembly.config.save.structure.config.notNull=裝備設定結構配寘不能為空
|
assembly.config.save.structure.config.notNull=裝備設定結構配寘不能為空
|
||||||
|
|
||||||
common.status.invalid=狀態不合法
|
common.status.invalid=狀態不合法
|
||||||
|
auth.appToken.notBlank=應用 Token 不能為空
|
||||||
|
auth.appToken.size=應用 Token 長度不能超過 255 個字元
|
||||||
|
|||||||
@@ -108,4 +108,6 @@ assembly.config.import.orderIds.size=The length of the production order number l
|
|||||||
assembly.config.save.id.notNull=Assembly setting number cannot be empty
|
assembly.config.save.id.notNull=Assembly setting number cannot be empty
|
||||||
assembly.config.save.structure.config.notNull=Assembly setting structure configuration cannot be empty
|
assembly.config.save.structure.config.notNull=Assembly setting structure configuration cannot be empty
|
||||||
|
|
||||||
common.status.invalid=The status is illegal
|
common.status.invalid=The status is illegal
|
||||||
|
auth.appToken.notBlank=Application Token cannot be blank
|
||||||
|
auth.appToken.size=Application Token cannot exceed 255 characters
|
||||||
|
|||||||
@@ -108,4 +108,6 @@ assembly.config.import.orderIds.size=订单号列表长度不能超过100
|
|||||||
assembly.config.save.id.notNull=装备设置编号不能为空
|
assembly.config.save.id.notNull=装备设置编号不能为空
|
||||||
assembly.config.save.structure.config.notNull=装备设置结构配置不能为空
|
assembly.config.save.structure.config.notNull=装备设置结构配置不能为空
|
||||||
|
|
||||||
common.status.invalid=状态不合法
|
common.status.invalid=状态不合法
|
||||||
|
auth.appToken.notBlank=应用 Token 不能为空
|
||||||
|
auth.appToken.size=应用 Token 长度不能超过 255 个字符
|
||||||
|
|||||||
+17
@@ -28,6 +28,7 @@ import com.cf.imes.module.system.service.permission.MenuService;
|
|||||||
import com.cf.imes.module.system.service.permission.PermissionService;
|
import com.cf.imes.module.system.service.permission.PermissionService;
|
||||||
import com.cf.imes.module.system.service.permission.RoleService;
|
import com.cf.imes.module.system.service.permission.RoleService;
|
||||||
import com.cf.imes.module.system.service.sms.SmsCodeService;
|
import com.cf.imes.module.system.service.sms.SmsCodeService;
|
||||||
|
import com.cf.imes.module.system.service.tokenconfig.TokenConfigService;
|
||||||
import com.cf.imes.module.system.service.user.AdminUserService;
|
import com.cf.imes.module.system.service.user.AdminUserService;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
@@ -115,6 +116,9 @@ class AuthControllerTest extends BaseWebUnitTest {
|
|||||||
@MockitoBean
|
@MockitoBean
|
||||||
private ApiErrorLogApi apiErrorLogApi;
|
private ApiErrorLogApi apiErrorLogApi;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private TokenConfigService tokenConfigService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
@@ -202,6 +206,19 @@ class AuthControllerTest extends BaseWebUnitTest {
|
|||||||
verify(authService, times(1)).loginSmsCheck(smsCheckReq);
|
verify(authService, times(1)).loginSmsCheck(smsCheckReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetOrganIdByAppToken() throws Exception {
|
||||||
|
when(tokenConfigService.getOrganIdByAppToken("test-app-token")).thenReturn(100L);
|
||||||
|
|
||||||
|
mockMvc.perform(post("/admin-api/system/auth/app-token/organ-id")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content("{\"appToken\":\"test-app-token\"}"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data").value(100L));
|
||||||
|
|
||||||
|
verify(tokenConfigService, times(1)).getOrganIdByAppToken("test-app-token");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testLogout_withToken() throws Exception {
|
void testLogout_withToken() throws Exception {
|
||||||
// mock token header/parameter
|
// mock token header/parameter
|
||||||
|
|||||||
Reference in New Issue
Block a user