mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge pull request #927 from amalhub/master
Resolves: https://github.com/wso2/product-iots/issues/1339, https://g…
This commit is contained in:
commit
aeb1f3a995
@ -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<String, AccessTokenInfo> 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<String, AccessTokenInfo> getTenantUserTokenMap() {
|
||||
return tenantUserTokenMap;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<String, AccessTokenInfo> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -362,6 +362,11 @@
|
||||
<artifactId>org.wso2.carbon.event.stream.persistence.stub</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.integration.client</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user