diff --git a/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/controller/SpdmUserController.java b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/controller/SpdmUserController.java index ea7a214..67182d4 100644 --- a/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/controller/SpdmUserController.java +++ b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/controller/SpdmUserController.java @@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.honeycombis.honeycom.common.core.constant.SecurityConstants; import com.honeycombis.honeycom.common.core.util.R; 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.RemoteUserServiceFeign; 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.web.bind.annotation.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.nio.charset.StandardCharsets; +import java.util.*; import java.util.stream.Collectors; @@ -62,7 +61,7 @@ public class SpdmUserController { @Resource private RemoteTenantServiceFeign remoteTenantServiceFeign; @Resource - private ObjectMapper objectMapper; + private RemoteAuthServiceFeign remoteAuthServiceFeign; @Operation(summary = "条件查询用户列表") @PostMapping(value = "/listUser") @@ -161,9 +160,28 @@ public class SpdmUserController { @Operation(summary = "查询用户信息包括权限/角色") @PostMapping(value = "/queryUserFunctionAndRole") - public R queryUserFunctionAndRole(@RequestBody UserParamDto userParamDto) { + public ResponseR queryUserFunctionAndRole(@RequestBody UserParamDto userParamDto) { R 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 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); } } diff --git a/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/dto/TokenDTO.java b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/dto/TokenDTO.java new file mode 100644 index 0000000..cbf943a --- /dev/null +++ b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/dto/TokenDTO.java @@ -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; + + +} diff --git a/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/feign/RemoteAuthServiceFeign.java b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/feign/RemoteAuthServiceFeign.java new file mode 100644 index 0000000..db72528 --- /dev/null +++ b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/feign/RemoteAuthServiceFeign.java @@ -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 getClientUserToken(@RequestParam Long userId, @RequestParam Long tenantId, @RequestHeader("Authorization") String clientAuthHeader); + +}