|
|
@ -20,6 +20,7 @@ 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.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.APIApplicationInfo;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
|
|
|
|
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.exceptions.APIServicesException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
|
|
@ -99,7 +100,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key)
|
|
|
|
public boolean isSharedScopeNameExists(APIApplicationInfo applicationInfo, String key)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace(Constants.QUERY_KEY_VALUE_SEPARATOR,
|
|
|
|
String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace(Constants.QUERY_KEY_VALUE_SEPARATOR,
|
|
|
@ -109,7 +110,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getScopeUrl)
|
|
|
|
.url(getScopeUrl)
|
|
|
|
.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())
|
|
|
|
.head()
|
|
|
|
.head()
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -118,11 +119,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} 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.
|
|
|
|
APIApplicationInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return isSharedScopeNameExists(apiApplicationKey, refreshedAccessToken, key);
|
|
|
|
return isSharedScopeNameExists(applicationInfo,key);
|
|
|
|
} 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);
|
|
|
@ -143,7 +143,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean addNewSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
|
|
|
|
public boolean addNewSharedScope(APIApplicationInfo applicationInfo, Scope scope)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String addNewSharedScopeEndPoint = endPointPrefix + Constants.SCOPE_API_ENDPOINT;
|
|
|
|
String addNewSharedScopeEndPoint = endPointPrefix + Constants.SCOPE_API_ENDPOINT;
|
|
|
@ -159,7 +159,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(addNewSharedScopeEndPoint)
|
|
|
|
.url(addNewSharedScopeEndPoint)
|
|
|
|
.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();
|
|
|
|
|
|
|
|
|
|
|
@ -169,11 +169,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} 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.
|
|
|
|
APIApplicationInfo refreshedApiApplicationInfo = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return addNewSharedScope(apiApplicationKey, refreshedAccessToken, scope);
|
|
|
|
return addNewSharedScope(refreshedApiApplicationInfo, scope);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid scope object";
|
|
|
|
String msg = "Bad Request, Invalid scope object";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -237,14 +236,14 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIIdentifier apiIdentifier)
|
|
|
|
public JSONObject getApi(APIApplicationInfo applicationInfo, APIIdentifier apiIdentifier)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllApi = endPointPrefix + Constants.API_ENDPOINT + apiIdentifier.getUUID();
|
|
|
|
String getAllApi = endPointPrefix + Constants.API_ENDPOINT + apiIdentifier.getUUID();
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getAllApi)
|
|
|
|
.url(getAllApi)
|
|
|
|
.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();
|
|
|
|
|
|
|
|
|
|
|
@ -255,11 +254,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
return jsonObject;
|
|
|
|
return jsonObject;
|
|
|
|
} 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.
|
|
|
|
APIApplicationInfo refreshedApplicationInfo = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return getApi(apiApplicationKey, refreshedAccessToken, apiIdentifier);
|
|
|
|
return getApi(refreshedApplicationInfo, apiIdentifier);
|
|
|
|
} 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);
|
|
|
@ -276,14 +274,14 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
|
|
|
public JSONObject getApis(APIApplicationInfo applicationInfo)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllApis = endPointPrefix + Constants.GET_ALL_APIS;
|
|
|
|
String getAllApis = endPointPrefix + Constants.GET_ALL_APIS;
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(getAllApis)
|
|
|
|
.url(getAllApis)
|
|
|
|
.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();
|
|
|
|
|
|
|
|
|
|
|
@ -294,11 +292,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
return jsonObject;
|
|
|
|
return jsonObject;
|
|
|
|
} 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.
|
|
|
|
APIApplicationInfo refreshedApiApplicationInfo = apiApplicationServices
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
.generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return getApis(apiApplicationKey, refreshedAccessToken);
|
|
|
|
return getApis(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);
|
|
|
@ -315,7 +312,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
|
|
|
|
public JSONObject addAPI(APIApplicationInfo applicationInfo, APIInfo api)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String addAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT;
|
|
|
|
String addAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT;
|
|
|
@ -370,7 +367,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(addAPIEndPoint)
|
|
|
|
.url(addAPIEndPoint)
|
|
|
|
.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();
|
|
|
|
|
|
|
|
|
|
|
@ -381,11 +378,9 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
return jsonObject;
|
|
|
|
return jsonObject;
|
|
|
|
} 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.
|
|
|
|
APIApplicationInfo refreshedApplicationToken = apiApplicationServices.generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return addAPI(apiApplicationKey, refreshedAccessToken, api);
|
|
|
|
return addAPI(refreshedApplicationToken, api);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid API request body";
|
|
|
|
String msg = "Bad Request, Invalid API request body";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -402,7 +397,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
|
|
|
|
public boolean updateApi(APIApplicationInfo applicationInfo, APIInfo api)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String updateAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId();
|
|
|
|
String updateAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId();
|
|
|
@ -457,7 +452,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(updateAPIEndPoint)
|
|
|
|
.url(updateAPIEndPoint)
|
|
|
|
.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())
|
|
|
|
.put(requestBody)
|
|
|
|
.put(requestBody)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
@ -468,11 +463,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
|
|
|
|
|
|
|
} 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.
|
|
|
|
APIApplicationInfo refreshedApplicationInfo = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return updateApi(apiApplicationKey, refreshedAccessToken, api);
|
|
|
|
return updateApi(refreshedApplicationInfo, api);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid API request body";
|
|
|
|
String msg = "Bad Request, Invalid API request body";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -489,8 +483,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean saveAsyncApiDefinition(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public boolean saveAsyncApiDefinition(APIApplicationInfo applicationInfo, String uuid, String asyncApiDefinition)
|
|
|
|
String uuid, String asyncApiDefinition)
|
|
|
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + uuid;
|
|
|
|
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + uuid;
|
|
|
@ -499,7 +492,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(addNewScope)
|
|
|
|
.url(addNewScope)
|
|
|
|
.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())
|
|
|
|
.put(requestBody)
|
|
|
|
.put(requestBody)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
@ -509,11 +502,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} 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.
|
|
|
|
APIApplicationInfo refreshedApplicationToken = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return saveAsyncApiDefinition(apiApplicationKey, refreshedAccessToken, uuid, asyncApiDefinition);
|
|
|
|
return saveAsyncApiDefinition(refreshedApplicationToken, uuid, asyncApiDefinition);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid API definition request body";
|
|
|
|
String msg = "Bad Request, Invalid API definition request body";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -571,8 +563,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean addApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public boolean addApiSpecificMediationPolicy(APIApplicationInfo applicationInfo, String uuid, Mediation mediation)
|
|
|
|
String uuid, Mediation mediation)
|
|
|
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String addAPIMediation = endPointPrefix + Constants.API_ENDPOINT + uuid + "/mediation-policies/" + mediation.getUuid()
|
|
|
|
String addAPIMediation = endPointPrefix + Constants.API_ENDPOINT + uuid + "/mediation-policies/" + mediation.getUuid()
|
|
|
@ -582,7 +573,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(addAPIMediation)
|
|
|
|
.url(addAPIMediation)
|
|
|
|
.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();
|
|
|
|
|
|
|
|
|
|
|
@ -592,11 +583,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} 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.
|
|
|
|
APIApplicationInfo refreshedApplicationToken = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return addApiSpecificMediationPolicy(apiApplicationKey, refreshedAccessToken, uuid, mediation);
|
|
|
|
return addApiSpecificMediationPolicy(refreshedApplicationToken, uuid, mediation);
|
|
|
|
} 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);
|
|
|
@ -658,7 +648,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean changeLifeCycleStatus(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public boolean changeLifeCycleStatus(APIApplicationInfo applicationInfo,
|
|
|
|
String uuid, String action)
|
|
|
|
String uuid, String action)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
@ -669,7 +659,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(changeAPIStatusEndPoint)
|
|
|
|
.url(changeAPIStatusEndPoint)
|
|
|
|
.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();
|
|
|
|
|
|
|
|
|
|
|
@ -679,11 +669,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} 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.
|
|
|
|
APIApplicationInfo refreshedApplicationInfo = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return changeLifeCycleStatus(apiApplicationKey, refreshedAccessToken, uuid, action);
|
|
|
|
return changeLifeCycleStatus(refreshedApplicationInfo, uuid, action);
|
|
|
|
} 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);
|
|
|
@ -742,7 +731,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIRevision apiRevision)
|
|
|
|
public JSONObject addAPIRevision(APIApplicationInfo applicationInfo, APIRevision apiRevision)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + apiRevision.getApiUUID() + "/revisions";
|
|
|
|
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + apiRevision.getApiUUID() + "/revisions";
|
|
|
@ -755,7 +744,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(addNewScope)
|
|
|
|
.url(addNewScope)
|
|
|
|
.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();
|
|
|
|
|
|
|
|
|
|
|
@ -766,11 +755,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
return jsonObject;
|
|
|
|
return jsonObject;
|
|
|
|
} 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.
|
|
|
|
APIApplicationInfo refreshedApplicationInfo = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return addAPIRevision(apiApplicationKey, refreshedAccessToken, apiRevision);
|
|
|
|
return addAPIRevision(refreshedApplicationInfo, apiRevision);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid API revision request body";
|
|
|
|
String msg = "Bad Request, Invalid API revision request body";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -787,7 +775,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deployAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
|
|
|
|
public boolean deployAPIRevision(APIApplicationInfo applicationInfo, String uuid,
|
|
|
|
String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeploymentList)
|
|
|
|
String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeploymentList)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
@ -806,7 +794,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(deployAPIRevisionEndPoint)
|
|
|
|
.url(deployAPIRevisionEndPoint)
|
|
|
|
.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();
|
|
|
|
|
|
|
|
|
|
|
@ -816,11 +804,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} 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.
|
|
|
|
APIApplicationInfo refreshedApplicationInfo = apiApplicationServices.
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
//TODO: max attempt count
|
|
|
|
return deployAPIRevision(apiApplicationKey, refreshedAccessToken, uuid, apiRevisionId,
|
|
|
|
return deployAPIRevision(refreshedApplicationInfo, uuid, apiRevisionId,
|
|
|
|
apiRevisionDeploymentList);
|
|
|
|
apiRevisionDeploymentList);
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
String msg = "Bad Request, Invalid API revision request body";
|
|
|
|
String msg = "Bad Request, Invalid API revision request body";
|
|
|
|