|
|
@ -19,14 +19,10 @@
|
|
|
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api;
|
|
|
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api;
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.APIInfo;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.*;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.APIKey;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Subscription;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.KeyManager;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.ApiApplicationInfo;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
|
|
|
@ -54,14 +50,14 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
+ Constants.COLON + port;
|
|
|
|
+ Constants.COLON + port;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Application[] getAllApplications(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String appName)
|
|
|
|
public Application[] getAllApplications(ApiApplicationInfo applicationInfo, String appName)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllApplicationsUrl = endPointPrefix + Constants.APPLICATIONS_API + "?query=" + appName;
|
|
|
|
String getAllApplicationsUrl = endPointPrefix + Constants.APPLICATIONS_API + "?query=" + appName;
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getAllApplicationsUrl)
|
|
|
|
.url(getAllApplicationsUrl)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
.get()
|
|
|
|
.get()
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
@ -73,10 +69,11 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo.getRefresh_token(),
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
applicationInfo.getClientId(), applicationInfo.getClientSecret());
|
|
|
|
|
|
|
|
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(applicationInfo, refreshedAccessToken);
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return getAllApplications(apiApplicationKey, refreshedAccessToken, appName);
|
|
|
|
return getAllApplications(refreshedApiApplicationInfo, appName);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -93,15 +90,14 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Application getDetailsOfAnApplication(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public Application getDetailsOfAnApplication(ApiApplicationInfo apiApplicationInfo, String applicationId)
|
|
|
|
String applicationId)
|
|
|
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllApplicationsUrl = endPointPrefix + Constants.APPLICATIONS_API + Constants.SLASH + applicationId;
|
|
|
|
String getAllApplicationsUrl = endPointPrefix + Constants.APPLICATIONS_API + Constants.SLASH + applicationId;
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getAllApplicationsUrl)
|
|
|
|
.url(getAllApplicationsUrl)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
+ apiApplicationInfo.getAccess_token())
|
|
|
|
.get()
|
|
|
|
.get()
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
@ -112,10 +108,11 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
|
|
|
|
|
|
|
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return getDetailsOfAnApplication(apiApplicationKey, refreshedAccessToken, applicationId);
|
|
|
|
return getDetailsOfAnApplication(refreshedApiApplicationInfo, applicationId);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -132,8 +129,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Application createApplication(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public Application createApplication(ApiApplicationInfo apiApplicationInfo, Application application)
|
|
|
|
Application application)
|
|
|
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllScopesUrl = endPointPrefix + Constants.APPLICATIONS_API;
|
|
|
|
String getAllScopesUrl = endPointPrefix + Constants.APPLICATIONS_API;
|
|
|
@ -152,7 +148,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getAllScopesUrl)
|
|
|
|
.url(getAllScopesUrl)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
+ apiApplicationInfo.getAccess_token())
|
|
|
|
.post(requestBody)
|
|
|
|
.post(requestBody)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
@ -163,10 +159,11 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
|
|
|
|
|
|
|
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return createApplication(apiApplicationKey, refreshedAccessToken, application);
|
|
|
|
return createApplication(refreshedApiApplicationInfo, application);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid request body";
|
|
|
|
String msg = "Bad Request, Invalid request body";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -183,15 +180,14 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Subscription[] getAllSubscriptions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public Subscription[] getAllSubscriptions(ApiApplicationInfo apiApplicationInfo, String applicationId)
|
|
|
|
String applicationId)
|
|
|
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllScopesUrl = endPointPrefix + Constants.SUBSCRIPTION_API + "?applicationId=" + applicationId;
|
|
|
|
String getAllScopesUrl = endPointPrefix + Constants.SUBSCRIPTION_API + "?applicationId=" + applicationId;
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getAllScopesUrl)
|
|
|
|
.url(getAllScopesUrl)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
+ apiApplicationInfo.getAccess_token())
|
|
|
|
.get()
|
|
|
|
.get()
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
@ -203,10 +199,11 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
|
|
|
|
|
|
|
ApiApplicationInfo rehreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return getAllSubscriptions(apiApplicationKey, refreshedAccessToken, applicationId);
|
|
|
|
return getAllSubscriptions(rehreshedApiApplicationInfo, applicationId);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -223,8 +220,8 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public APIInfo[] getAllApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public APIInfo[] getAllApis(ApiApplicationInfo applicationInfo, Map<String, String> queryParams,
|
|
|
|
Map<String, String> queryParams, Map<String, String> headerParams)
|
|
|
|
Map<String, String> headerParams)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAPIsURL = endPointPrefix + Constants.DEV_PORTAL_API;
|
|
|
|
String getAPIsURL = endPointPrefix + Constants.DEV_PORTAL_API;
|
|
|
@ -236,7 +233,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
Request.Builder builder = new Request.Builder();
|
|
|
|
Request.Builder builder = new Request.Builder();
|
|
|
|
builder.url(getAPIsURL);
|
|
|
|
builder.url(getAPIsURL);
|
|
|
|
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
builder.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
+ accessTokenInfo.getAccess_token());
|
|
|
|
+ applicationInfo.getAccess_token());
|
|
|
|
for (Map.Entry<String, String> header : headerParams.entrySet()) {
|
|
|
|
for (Map.Entry<String, String> header : headerParams.entrySet()) {
|
|
|
|
builder.addHeader(header.getKey(), header.getValue());
|
|
|
|
builder.addHeader(header.getKey(), header.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -251,10 +248,11 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo.getRefresh_token(),
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
applicationInfo.getClientId(), applicationInfo.getClientSecret());
|
|
|
|
|
|
|
|
ApiApplicationInfo rehreshedApiApplicationInfo = returnApplicationInfo(applicationInfo, refreshedAccessToken);
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return getAllApis(apiApplicationKey, refreshedAccessToken, queryParams, headerParams);
|
|
|
|
return getAllApis(rehreshedApiApplicationInfo, queryParams, headerParams);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -271,8 +269,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Subscription createSubscription(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public Subscription createSubscription(ApiApplicationInfo applicationInfo, Subscription subscriptions)
|
|
|
|
Subscription subscriptions)
|
|
|
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllScopesUrl = endPointPrefix + Constants.SUBSCRIPTION_API;
|
|
|
|
String getAllScopesUrl = endPointPrefix + Constants.SUBSCRIPTION_API;
|
|
|
@ -288,7 +285,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getAllScopesUrl)
|
|
|
|
.url(getAllScopesUrl)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
.post(requestBody)
|
|
|
|
.post(requestBody)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
@ -299,10 +296,11 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo.getRefresh_token(),
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
applicationInfo.getClientId(), applicationInfo.getClientSecret());
|
|
|
|
|
|
|
|
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(applicationInfo, refreshedAccessToken);
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return createSubscription(apiApplicationKey, refreshedAccessToken, subscriptions);
|
|
|
|
return createSubscription(refreshedApiApplicationInfo, subscriptions);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid request body";
|
|
|
|
String msg = "Bad Request, Invalid request body";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -319,8 +317,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Subscription[] createSubscriptions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public Subscription[] createSubscriptions(ApiApplicationInfo apiApplicationInfo, List<Subscription> subscriptions)
|
|
|
|
List<Subscription> subscriptions)
|
|
|
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllScopesUrl = endPointPrefix + Constants.SUBSCRIPTION_API + "/multiple";
|
|
|
|
String getAllScopesUrl = endPointPrefix + Constants.SUBSCRIPTION_API + "/multiple";
|
|
|
@ -331,7 +328,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getAllScopesUrl)
|
|
|
|
.url(getAllScopesUrl)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
+ apiApplicationInfo.getAccess_token())
|
|
|
|
.post(requestBody)
|
|
|
|
.post(requestBody)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
@ -343,10 +340,11 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
|
|
|
|
|
|
|
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return createSubscriptions(apiApplicationKey, refreshedAccessToken, subscriptions);
|
|
|
|
return createSubscriptions(refreshedApiApplicationInfo, subscriptions);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid request body";
|
|
|
|
String msg = "Bad Request, Invalid request body";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -363,15 +361,25 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public APIKey generateApplicationKeys(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public ApplicationKey generateApplicationKeys(ApiApplicationInfo apiApplicationInfo, Application application)
|
|
|
|
String applicationId)
|
|
|
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllScopesUrl = endPointPrefix + Constants.SUBSCRIPTION_API + Constants.SLASH + applicationId +
|
|
|
|
String getAllScopesUrl = endPointPrefix + Constants.SUBSCRIPTION_API + Constants.SLASH +
|
|
|
|
"/generate-keys";
|
|
|
|
application.getApplicationId() + "/generate-keys";
|
|
|
|
|
|
|
|
|
|
|
|
String keyInfo = "{\n" +
|
|
|
|
String keyInfo = "{\n" +
|
|
|
|
" \"validityPeriod\": 3600,\n" +
|
|
|
|
" \"keyType\": \"PRODUCTION\",\n" +
|
|
|
|
|
|
|
|
" \"keyManager\": \"Resident Key Manager\",\n" +
|
|
|
|
|
|
|
|
" \"grantTypesToBeSupported\": [\n" +
|
|
|
|
|
|
|
|
" \"password\",\n" +
|
|
|
|
|
|
|
|
" \"client_credentials\"\n" +
|
|
|
|
|
|
|
|
" ],\n" +
|
|
|
|
|
|
|
|
" \"callbackUrl\": \"http://sample.com/callback/url\",\n" +
|
|
|
|
|
|
|
|
" \"scopes\": [\n" +
|
|
|
|
|
|
|
|
" \"am_application_scope\",\n" +
|
|
|
|
|
|
|
|
" \"default\"\n" +
|
|
|
|
|
|
|
|
" ],\n" +
|
|
|
|
|
|
|
|
" \"validityTime\": 3600,\n" +
|
|
|
|
" \"additionalProperties\": {}\n" +
|
|
|
|
" \"additionalProperties\": {}\n" +
|
|
|
|
"}";
|
|
|
|
"}";
|
|
|
|
|
|
|
|
|
|
|
@ -379,21 +387,22 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getAllScopesUrl)
|
|
|
|
.url(getAllScopesUrl)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
+ apiApplicationInfo.getAccess_token())
|
|
|
|
.post(requestBody)
|
|
|
|
.post(requestBody)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
if (HttpStatus.SC_OK == response.code()) {
|
|
|
|
if (HttpStatus.SC_OK == response.code()) {
|
|
|
|
return gson.fromJson(response.body().string(), APIKey.class);
|
|
|
|
return gson.fromJson(response.body().string(), ApplicationKey.class);
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
|
|
|
|
|
|
|
ApiApplicationInfo refreshedApiApplicationKey = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return generateApplicationKeys(apiApplicationKey, refreshedAccessToken, applicationId);
|
|
|
|
return generateApplicationKeys(refreshedApiApplicationKey, application);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid request body";
|
|
|
|
String msg = "Bad Request, Invalid request body";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -410,14 +419,14 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public KeyManager[] getAllKeyManagers(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
|
|
|
public KeyManager[] getAllKeyManagers(ApiApplicationInfo apiApplicationInfo)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllKeyManagersUrl = endPointPrefix + Constants.KEY_MANAGERS_API;
|
|
|
|
String getAllKeyManagersUrl = endPointPrefix + Constants.KEY_MANAGERS_API;
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getAllKeyManagersUrl)
|
|
|
|
.url(getAllKeyManagersUrl)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
+ apiApplicationInfo.getAccess_token())
|
|
|
|
.get()
|
|
|
|
.get()
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
@ -429,10 +438,11 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(apiApplicationInfo.getRefresh_token(),
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
apiApplicationInfo.getClientId(), apiApplicationInfo.getClientSecret());
|
|
|
|
|
|
|
|
ApiApplicationInfo refreshedApiApplicationInfo = returnApplicationInfo(apiApplicationInfo, refreshedAccessToken);
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return getAllKeyManagers(apiApplicationKey, refreshedAccessToken);
|
|
|
|
return getAllKeyManagers(refreshedApiApplicationInfo);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -447,4 +457,15 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|
|
|
throw new APIServicesException(msg, e);
|
|
|
|
throw new APIServicesException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ApiApplicationInfo returnApplicationInfo(ApiApplicationInfo refreshedApplicationInfo, AccessTokenInfo refreshedToken) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApiApplicationInfo applicationInfo = null;
|
|
|
|
|
|
|
|
applicationInfo.setClientId(refreshedApplicationInfo.getClientId());
|
|
|
|
|
|
|
|
applicationInfo.setClientSecret(refreshedApplicationInfo.getClientSecret());
|
|
|
|
|
|
|
|
applicationInfo.setAccess_token(refreshedToken.getAccess_token());
|
|
|
|
|
|
|
|
applicationInfo.setRefresh_token(refreshedToken.getRefresh_token());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return applicationInfo;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|