From 84ad02156bae70a09f4f41a5550105d227d8d298 Mon Sep 17 00:00:00 2001 From: amalhub Date: Wed, 30 Aug 2017 12:20:51 +0530 Subject: [PATCH] Resolves: https://github.com/wso2/product-iots/issues/1339, https://github.com/wso2/product-iots/issues/1300 --- .../integration/client/IntegrationClientServiceImpl.java | 9 +++++++++ .../integration/client/OAuthRequestInterceptor.java | 5 ++--- .../device-mgt/org.wso2.carbon.device.mgt.api/pom.xml | 5 +++++ .../jaxrs/util/CredentialManagementResponseBuilder.java | 6 ++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/IntegrationClientServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/IntegrationClientServiceImpl.java index 7878bcfffd..94c6f7e87c 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/IntegrationClientServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/IntegrationClientServiceImpl.java @@ -22,11 +22,16 @@ import feign.RequestInterceptor; import org.wso2.carbon.apimgt.integration.client.publisher.PublisherClient; import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService; import org.wso2.carbon.apimgt.integration.client.store.StoreClient; +import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; + +import java.util.HashMap; +import java.util.Map; public class IntegrationClientServiceImpl implements IntegrationClientService { private static StoreClient storeClient; private static PublisherClient publisherClient; + private static Map tenantUserTokenMap = new HashMap<>(); public IntegrationClientServiceImpl() { RequestInterceptor oAuthRequestInterceptor = new OAuthRequestInterceptor(); @@ -42,4 +47,8 @@ public class IntegrationClientServiceImpl implements IntegrationClientService { public PublisherClient getPublisherClient() { return publisherClient; } + + public static Map getTenantUserTokenMap() { + return tenantUserTokenMap; + } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/OAuthRequestInterceptor.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/OAuthRequestInterceptor.java index a1ab7d6c73..b78f258c27 100755 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/OAuthRequestInterceptor.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/OAuthRequestInterceptor.java @@ -55,7 +55,6 @@ public class OAuthRequestInterceptor implements RequestInterceptor { private static final long DEFAULT_REFRESH_TIME_OFFSET_IN_MILLIS = 100000; private DCRClient dcrClient; private static OAuthApplication oAuthApplication; - private static Map tenantUserTokenMap = new HashMap<>(); private static final Log log = LogFactory.getLog(OAuthRequestInterceptor.class); /** @@ -89,7 +88,7 @@ public class OAuthRequestInterceptor implements RequestInterceptor { if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { username = username + "@" + tenantDomain; } - AccessTokenInfo tenantBasedAccessTokenInfo = tenantUserTokenMap.get(username); + AccessTokenInfo tenantBasedAccessTokenInfo = IntegrationClientServiceImpl.getTenantUserTokenMap().get(username); if ((tenantBasedAccessTokenInfo == null || ((System.currentTimeMillis() + DEFAULT_REFRESH_TIME_OFFSET_IN_MILLIS) > tenantBasedAccessTokenInfo.getExpiresIn()))) { @@ -106,7 +105,7 @@ public class OAuthRequestInterceptor implements RequestInterceptor { } if (tenantBasedAccessTokenInfo.getScopes().contains(APIM_SUBSCRIBE_SCOPE)) { - tenantUserTokenMap.put(username, tenantBasedAccessTokenInfo); + IntegrationClientServiceImpl.getTenantUserTokenMap().put(username, tenantBasedAccessTokenInfo); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index c617e38214..68b057e196 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -362,6 +362,11 @@ org.wso2.carbon.event.stream.persistence.stub provided + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.integration.client + provided + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/CredentialManagementResponseBuilder.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/CredentialManagementResponseBuilder.java index 7007aa0d3e..a44444aa3d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/CredentialManagementResponseBuilder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/CredentialManagementResponseBuilder.java @@ -20,7 +20,10 @@ package org.wso2.carbon.device.mgt.jaxrs.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.apimgt.integration.client.IntegrationClientServiceImpl; +import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService; import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper; @@ -63,6 +66,9 @@ public class CredentialManagementResponseBuilder { username = CarbonContext.getThreadLocalCarbonContext().getUsername(); userStoreManager.updateCredential(username, credentials.getNewPassword(), credentials.getOldPassword()); + IntegrationClientServiceImpl integrationClientService = (IntegrationClientServiceImpl) PrivilegedCarbonContext. + getThreadLocalCarbonContext().getOSGiService(IntegrationClientService.class, null); + integrationClientService.getTenantUserTokenMap().remove(username); return Response.status(Response.Status.OK).entity("UserImpl password by username: " + username + " was successfully changed.").build(); } catch (UserStoreException e) {