diff --git a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoServiceImpl.java b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoServiceImpl.java index 73c14c0bc..2c5e608b2 100644 --- a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoServiceImpl.java +++ b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.api/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoServiceImpl.java @@ -221,13 +221,21 @@ public class ArduinoServiceImpl implements ArduinoService { String applicationUsername = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm() .getRealmConfiguration().getAdminUserName() + "@" + PrivilegedCarbonContext .getThreadLocalCarbonContext().getTenantDomain(); - ; if (apiApplicationKey == null) { + String adminUsername = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminUserName(); + String tenantAdminDomainName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); String[] tags = {ArduinoConstants.DEVICE_TYPE}; - apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( - ArduinoConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true, - ArduinoConstants.APIM_APPLICATION_TOKEN_VALIDITY_PERIOD); + try{ + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantAdminDomainName); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(adminUsername); + apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( + ArduinoConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true, + ArduinoConstants.APIM_APPLICATION_TOKEN_VALIDITY_PERIOD); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } } JWTClient jwtClient = APIUtil.getJWTClientManagerService().getJWTClient(); String scopes = " device_" + deviceId + " perm:arduino:enroll"; diff --git a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiServiceImpl.java b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiServiceImpl.java index 3e9c00ba1..5ebd98005 100644 --- a/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiServiceImpl.java +++ b/components/device-types/raspberrypi-plugin/org.wso2.carbon.device.mgt.iot.raspberrypi.api/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/impl/RaspberryPiServiceImpl.java @@ -203,14 +203,23 @@ public class RaspberryPiServiceImpl implements RaspberryPiService { throw new DeviceManagementException(msg); } if (apiApplicationKey == null) { + String adminUsername = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminUserName(); + String tenantAdminDomainName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String applicationUsername = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm() .getRealmConfiguration().getAdminUserName() + "@" + PrivilegedCarbonContext .getThreadLocalCarbonContext().getTenantDomain(); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); String[] tags = {RaspberrypiConstants.DEVICE_TYPE}; - apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( - RaspberrypiConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true, - RaspberrypiConstants.APIM_APPLICATION_TOKEN_VALIDITY_PERIOD); + try{ + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantAdminDomainName); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(adminUsername); + apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( + RaspberrypiConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true, + RaspberrypiConstants.APIM_APPLICATION_TOKEN_VALIDITY_PERIOD); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } } JWTClient jwtClient = APIUtil.getJWTClientManagerService().getJWTClient(); String scopes = " device_" + deviceId; diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java index 0e540978b..367cd248b 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java @@ -233,15 +233,27 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService { throw new DeviceManagementException(msg); } if (apiApplicationKey == null) { + String adminUsername = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm() + .getRealmConfiguration().getAdminUserName(); + String tenantAdminDomainName = PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getTenantDomain(); String applicationUsername = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration() .getAdminUserName() + "@" + PrivilegedCarbonContext.getThreadLocalCarbonContext() .getTenantDomain(); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); String[] tags = {VirtualFireAlarmConstants.DEVICE_TYPE}; - apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( - VirtualFireAlarmConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true, - VirtualFireAlarmConstants.APIM_APPLICATION_TOKEN_VALIDITY_PERIOD); + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantAdminDomainName); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(adminUsername); + + apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( + VirtualFireAlarmConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true, + VirtualFireAlarmConstants.APIM_APPLICATION_TOKEN_VALIDITY_PERIOD); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } } JWTClient jwtClient = APIUtil.getJWTClientManagerService().getJWTClient(); String scopes = " device_" + deviceId; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/android-web-agent/app/pages/mdm.page.enrollments.android.download-agent/public/asset/android-agent.apk b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/android-web-agent/app/pages/mdm.page.enrollments.android.download-agent/public/asset/android-agent.apk index b133e2fda..71860aca8 100644 Binary files a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/android-web-agent/app/pages/mdm.page.enrollments.android.download-agent/public/asset/android-agent.apk and b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/android-web-agent/app/pages/mdm.page.enrollments.android.download-agent/public/asset/android-agent.apk differ