|
|
@ -15,12 +15,15 @@
|
|
|
|
package org.wso2.carbon.apimgt.integration.client;
|
|
|
|
package org.wso2.carbon.apimgt.integration.client;
|
|
|
|
|
|
|
|
|
|
|
|
import feign.Feign;
|
|
|
|
import feign.Feign;
|
|
|
|
|
|
|
|
import feign.Logger;
|
|
|
|
import feign.RequestInterceptor;
|
|
|
|
import feign.RequestInterceptor;
|
|
|
|
import feign.RequestTemplate;
|
|
|
|
import feign.RequestTemplate;
|
|
|
|
import feign.auth.BasicAuthRequestInterceptor;
|
|
|
|
import feign.auth.BasicAuthRequestInterceptor;
|
|
|
|
import feign.gson.GsonDecoder;
|
|
|
|
import feign.gson.GsonDecoder;
|
|
|
|
import feign.gson.GsonEncoder;
|
|
|
|
import feign.gson.GsonEncoder;
|
|
|
|
import feign.jaxrs.JAXRSContract;
|
|
|
|
import feign.jaxrs.JAXRSContract;
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.apimgt.integration.client.configs.APIMConfigReader;
|
|
|
|
import org.wso2.carbon.apimgt.integration.client.configs.APIMConfigReader;
|
|
|
|
import org.wso2.carbon.apimgt.integration.client.exception.APIMClientOAuthException;
|
|
|
|
import org.wso2.carbon.apimgt.integration.client.exception.APIMClientOAuthException;
|
|
|
|
import org.wso2.carbon.apimgt.integration.client.internal.APIIntegrationClientDataHolder;
|
|
|
|
import org.wso2.carbon.apimgt.integration.client.internal.APIIntegrationClientDataHolder;
|
|
|
@ -47,10 +50,12 @@ public class OAuthRequestInterceptor implements RequestInterceptor {
|
|
|
|
private static final String REQUIRED_SCOPE =
|
|
|
|
private static final String REQUIRED_SCOPE =
|
|
|
|
"apim:api_create apim:api_view apim:api_publish apim:subscribe apim:tier_view apim:tier_manage " +
|
|
|
|
"apim:api_create apim:api_view apim:api_publish apim:subscribe apim:tier_view apim:tier_manage " +
|
|
|
|
"apim:subscription_view apim:subscription_block";
|
|
|
|
"apim:subscription_view apim:subscription_block";
|
|
|
|
|
|
|
|
private static final String APIM_SUBSCRIBE_SCOPE = "apim:subscribe";
|
|
|
|
private static final long DEFAULT_REFRESH_TIME_OFFSET_IN_MILLIS = 100000;
|
|
|
|
private static final long DEFAULT_REFRESH_TIME_OFFSET_IN_MILLIS = 100000;
|
|
|
|
private DCRClient dcrClient;
|
|
|
|
private DCRClient dcrClient;
|
|
|
|
private static OAuthApplication oAuthApplication;
|
|
|
|
private static OAuthApplication oAuthApplication;
|
|
|
|
private static Map<String, AccessTokenInfo> tenantUserTokenMap = new HashMap<>();
|
|
|
|
private static Map<String, AccessTokenInfo> tenantUserTokenMap = new HashMap<>();
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(OAuthRequestInterceptor.class);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Creates an interceptor that authenticates all requests.
|
|
|
|
* Creates an interceptor that authenticates all requests.
|
|
|
@ -58,8 +63,8 @@ public class OAuthRequestInterceptor implements RequestInterceptor {
|
|
|
|
public OAuthRequestInterceptor() {
|
|
|
|
public OAuthRequestInterceptor() {
|
|
|
|
String username = APIMConfigReader.getInstance().getConfig().getUsername();
|
|
|
|
String username = APIMConfigReader.getInstance().getConfig().getUsername();
|
|
|
|
String password = APIMConfigReader.getInstance().getConfig().getPassword();
|
|
|
|
String password = APIMConfigReader.getInstance().getConfig().getPassword();
|
|
|
|
dcrClient = Feign.builder().client(Utils.getSSLClient()).requestInterceptor(
|
|
|
|
dcrClient = Feign.builder().client(Utils.getSSLClient()).logger(Utils.getLogger(log)).logLevel(
|
|
|
|
new BasicAuthRequestInterceptor(username, password))
|
|
|
|
Logger.Level.FULL).requestInterceptor(new BasicAuthRequestInterceptor(username, password))
|
|
|
|
.contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder())
|
|
|
|
.contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder())
|
|
|
|
.target(DCRClient.class, Utils.replaceProperties(
|
|
|
|
.target(DCRClient.class, Utils.replaceProperties(
|
|
|
|
APIMConfigReader.getInstance().getConfig().getDcrEndpoint()));
|
|
|
|
APIMConfigReader.getInstance().getConfig().getDcrEndpoint()));
|
|
|
@ -95,7 +100,9 @@ public class OAuthRequestInterceptor implements RequestInterceptor {
|
|
|
|
REQUIRED_SCOPE);
|
|
|
|
REQUIRED_SCOPE);
|
|
|
|
tenantBasedAccessTokenInfo.setExpiresIn(
|
|
|
|
tenantBasedAccessTokenInfo.setExpiresIn(
|
|
|
|
System.currentTimeMillis() + (tenantBasedAccessTokenInfo.getExpiresIn() * 1000));
|
|
|
|
System.currentTimeMillis() + (tenantBasedAccessTokenInfo.getExpiresIn() * 1000));
|
|
|
|
tenantUserTokenMap.put(username, tenantBasedAccessTokenInfo);
|
|
|
|
if (tenantBasedAccessTokenInfo.getScopes().contains(APIM_SUBSCRIBE_SCOPE)) {
|
|
|
|
|
|
|
|
tenantUserTokenMap.put(username, tenantBasedAccessTokenInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tenantBasedAccessTokenInfo.getAccessToken() != null) {
|
|
|
|
if (tenantBasedAccessTokenInfo.getAccessToken() != null) {
|
|
|
|