spdm用户获取token

This commit is contained in:
2025-12-08 11:19:28 +08:00
parent 176a1c346b
commit 5f43158965
3 changed files with 59 additions and 7 deletions

View File

@@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.honeycombis.honeycom.common.core.constant.SecurityConstants; import com.honeycombis.honeycom.common.core.constant.SecurityConstants;
import com.honeycombis.honeycom.common.core.util.R; import com.honeycombis.honeycom.common.core.util.R;
import com.honeycombis.honeycom.spdm.dto.*; import com.honeycombis.honeycom.spdm.dto.*;
import com.honeycombis.honeycom.spdm.feign.RemoteAuthServiceFeign;
import com.honeycombis.honeycom.spdm.feign.RemoteTenantServiceFeign; import com.honeycombis.honeycom.spdm.feign.RemoteTenantServiceFeign;
import com.honeycombis.honeycom.spdm.feign.RemoteUserServiceFeign; import com.honeycombis.honeycom.spdm.feign.RemoteUserServiceFeign;
import com.honeycombis.honeycom.spdm.util.PageResult; import com.honeycombis.honeycom.spdm.util.PageResult;
@@ -44,10 +45,8 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -62,7 +61,7 @@ public class SpdmUserController {
@Resource @Resource
private RemoteTenantServiceFeign remoteTenantServiceFeign; private RemoteTenantServiceFeign remoteTenantServiceFeign;
@Resource @Resource
private ObjectMapper objectMapper; private RemoteAuthServiceFeign remoteAuthServiceFeign;
@Operation(summary = "条件查询用户列表") @Operation(summary = "条件查询用户列表")
@PostMapping(value = "/listUser") @PostMapping(value = "/listUser")
@@ -161,9 +160,28 @@ public class SpdmUserController {
@Operation(summary = "查询用户信息包括权限/角色") @Operation(summary = "查询用户信息包括权限/角色")
@PostMapping(value = "/queryUserFunctionAndRole") @PostMapping(value = "/queryUserFunctionAndRole")
public R queryUserFunctionAndRole(@RequestBody UserParamDto userParamDto) { public ResponseR queryUserFunctionAndRole(@RequestBody UserParamDto userParamDto) {
R<SysUserInfoVO> sysUserInfoVOR = remoteUserServiceFeign.infoByAccount(userParamDto.getPhoneNo(), SecurityConstants.FROM_IN, userParamDto.getTenantId()); R<SysUserInfoVO> sysUserInfoVOR = remoteUserServiceFeign.infoByAccount(userParamDto.getPhoneNo(), SecurityConstants.FROM_IN, userParamDto.getTenantId());
return sysUserInfoVOR; return ResponseR.ok(sysUserInfoVOR.getData());
}
@Operation(summary = "根据用户userId获取token")
@PostMapping(value = "/getUserToken")
public ResponseR getUserToken(@RequestBody UserParamDto userParamDto) {
// 1. 准备用户名密码
String username = "transformer";
String password = "transformer";
// 2. 创建 Base64 编码的认证字符串
String auth = username + ":" + password;
byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8));
String authHeader = "Basic " + new String(encodedAuth);
R<TokenDTO> tokenDTOR = remoteAuthServiceFeign.getClientUserToken(userParamDto.getUserId(), Long.valueOf(userParamDto.getTenantId()), authHeader);
TokenDTO tokenDTO = tokenDTOR.getData();
tokenDTO.setCid_user_id(String.valueOf(userParamDto.getUserId()));
tokenDTO.setCid_tenant_id(userParamDto.getTenantId());
return ResponseR.ok(tokenDTO);
} }
} }

View File

@@ -0,0 +1,16 @@
package com.honeycombis.honeycom.spdm.dto;
import lombok.Data;
import java.io.Serializable;
@Data
public class TokenDTO implements Serializable {
private String access_token;
private String refresh_token;
private String cid_user_id;
private String cid_tenant_id;
}

View File

@@ -0,0 +1,18 @@
package com.honeycombis.honeycom.spdm.feign;
import com.honeycombis.honeycom.common.core.util.R;
import com.honeycombis.honeycom.common.feign.config.FeignConfig;
import com.honeycombis.honeycom.spdm.dto.TokenDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(contextId = "remoteAuthService", value = "honeycom-auth", configuration = FeignConfig.class)
public interface RemoteAuthServiceFeign {
@PostMapping("/clientAuth/token/getClientUserTempToken")
R<TokenDTO> getClientUserToken(@RequestParam Long userId, @RequestParam Long tenantId, @RequestHeader("Authorization") String clientAuthHeader);
}