From 51fface4018cccade89628073eb4b50f6f8fe8c5 Mon Sep 17 00:00:00 2001 From: "tcdlpds@gmail.com" Date: Wed, 27 Jan 2021 15:05:38 +0530 Subject: [PATCH] Append tenant domain when getting default access token --- .../service/impl/DeviceManagementServiceImpl.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 989c1df0e9..b2f2d1ab11 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -1463,12 +1463,18 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @GET @Path("/{clientId}/{clientSecret}/default-token") @Override - public Response getDefaultToken(@PathParam("clientId") String clientId, @PathParam("clientSecret") String clientSecret) { + public Response getDefaultToken( + @PathParam("clientId") String clientId, + @PathParam("clientSecret") String clientSecret) { JWTClientManagerService jwtClientManagerService = DeviceMgtAPIUtils.getJWTClientManagerService(); try { JWTClient jwtClient = jwtClientManagerService.getJWTClient(); - AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(clientId, clientSecret, - PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(), "default"); + String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (!"carbon.super".equals(tenantDomain)) { + username += "@" + tenantDomain; + } + AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(clientId, clientSecret, username, "default"); return Response.status(Response.Status.OK).entity(accessTokenInfo).build(); } catch (JWTClientException e) { String msg = "Error occurred while getting default access token by using given client Id and client secret.";