Combine methods on creating application and generate tokens

consumerRestApis
Pasindu Rupasinghe 1 year ago
parent 6bf6adf2b5
commit 1889d10937

@ -18,13 +18,14 @@
package io.entgra.device.mgt.core.apimgt.extension.rest.api;
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.AccessTokenInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
public interface APIApplicationServices {
APIApplicationKey createAndRetrieveApplicationCredentials() throws APIServicesException;
APIApplicationKey createAndRetrieveApplicationCredentials()
throws APIServicesException;
APIApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String tags[],
String keyType, String username,
@ -32,8 +33,9 @@ public interface APIApplicationServices {
String validityTime, String password)
throws APIServicesException;
AccessTokenInfo generateAccessTokenFromRegisteredApplication(String clientId, String clientSecret) throws APIServicesException;
AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String clientId, String clientSecret) throws APIServicesException;
APIApplicationInfo generateAccessTokenFromRegisteredApplication()
throws APIServicesException;
APIApplicationInfo generateAccessTokenFromRefreshToken(APIApplicationInfo applicationInfo)
throws APIServicesException;
}

@ -19,6 +19,7 @@
package io.entgra.device.mgt.core.apimgt.extension.rest.api;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationInfo;
import org.json.JSONObject;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
@ -112,7 +113,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices {
}
@Override
public AccessTokenInfo generateAccessTokenFromRegisteredApplication(String consumerKey, String consumerSecret)
public APIApplicationInfo generateAccessTokenFromRegisteredApplication()
throws APIServicesException {
String userName = config.getFirstProperty(Constants.SERVER_USER);
@ -123,21 +124,62 @@ public class APIApplicationServicesImpl implements APIApplicationServices {
params.put(Constants.PASSWORD_GRANT_TYPE_USERNAME, userName);
params.put(Constants.PASSWORD_GRANT_TYPE_PASSWORD, userPassword);
params.put(Constants.SCOPE_PARAM_NAME, Constants.SCOPES);
return getToken(params, consumerKey, consumerSecret);
APIApplicationKey apiApplicationKey = createAndRetrieveApplicationCredentials();
AccessTokenInfo accessTokenInfo = getToken(params, apiApplicationKey.getClientId(),
apiApplicationKey.getClientSecret());
APIApplicationInfo applicationInfo = null;
applicationInfo.setClientName(apiApplicationKey.getClientName());
applicationInfo.setClientId(apiApplicationKey.getClientId());
applicationInfo.setClientSecret(apiApplicationKey.getClientSecret());
applicationInfo.setCallBackURL(applicationInfo.getCallBackURL());
applicationInfo.setIsSaasApplication(applicationInfo.getIsSaasApplication());
applicationInfo.setAppOwner(apiApplicationKey.getIsSaasApplication());
applicationInfo.setJsonString(applicationInfo.getJsonString());
applicationInfo.setJsonAppAttribute(apiApplicationKey.getJsonAppAttribute());
applicationInfo.setToken_type(applicationInfo.getToken_type());
applicationInfo.setExpires_in(accessTokenInfo.getExpires_in());
applicationInfo.setRefresh_token(accessTokenInfo.getRefresh_token());
applicationInfo.setAccess_token(accessTokenInfo.getAccess_token());
applicationInfo.setScope(accessTokenInfo.getScope());
return applicationInfo;
}
@Override
public AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String consumerKey, String consumerSecret)
public APIApplicationInfo generateAccessTokenFromRefreshToken(APIApplicationInfo applicationInfo)
throws APIServicesException {
JSONObject params = new JSONObject();
params.put(Constants.GRANT_TYPE_PARAM_NAME, Constants.REFRESH_TOKEN_GRANT_TYPE);
params.put(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME, refreshToken);
params.put(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME, applicationInfo.getRefresh_token());
params.put(Constants.SCOPE_PARAM_NAME, Constants.SCOPES);
return getToken(params, consumerKey, consumerSecret);
AccessTokenInfo refreshedAccessTokenInfo = getToken(params, applicationInfo.getClientId(), applicationInfo.getClientSecret());
APIApplicationInfo refreshedApplicationInfo = null;
refreshedApplicationInfo.setClientName(applicationInfo.getClientName());
refreshedApplicationInfo.setClientId(applicationInfo.getClientId());
refreshedApplicationInfo.setClientSecret(applicationInfo.getClientSecret());
refreshedApplicationInfo.setCallBackURL(applicationInfo.getCallBackURL());
refreshedApplicationInfo.setIsSaasApplication(applicationInfo.getIsSaasApplication());
refreshedApplicationInfo.setAppOwner(applicationInfo.getIsSaasApplication());
refreshedApplicationInfo.setJsonString(applicationInfo.getJsonString());
refreshedApplicationInfo.setJsonAppAttribute(applicationInfo.getJsonAppAttribute());
refreshedApplicationInfo.setToken_type(applicationInfo.getToken_type());
refreshedApplicationInfo.setExpires_in(refreshedAccessTokenInfo.getExpires_in());
refreshedApplicationInfo.setRefresh_token(refreshedAccessTokenInfo.getRefresh_token());
refreshedApplicationInfo.setAccess_token(refreshedAccessTokenInfo.getAccess_token());
refreshedApplicationInfo.setScope(refreshedAccessTokenInfo.getScope());
return refreshedApplicationInfo;
}
public AccessTokenInfo getToken(JSONObject nameValuePairs, String clientId, String clientSecret)
private AccessTokenInfo getToken(JSONObject nameValuePairs, String clientId, String clientSecret)
throws APIServicesException {
String tokenEndPoint = config.getFirstProperty(Constants.TOKE_END_POINT);
@ -158,4 +200,58 @@ public class APIApplicationServicesImpl implements APIApplicationServices {
throw new APIServicesException(e);
}
}
@Override
public APIApplicationInfo apiApplicationInfoFromRegisterApplication() throws APIServicesException {
APIApplicationKey apiApplicationKey = createAndRetrieveApplicationCredentials();
AccessTokenInfo accessTokenInfo = generateAccessTokenFromRegisteredApplication(apiApplicationKey.getClientId(),
apiApplicationKey.getClientSecret());
APIApplicationInfo applicationInfo = null;
applicationInfo.setClientName(apiApplicationKey.getClientName());
applicationInfo.setClientId(apiApplicationKey.getClientId());
applicationInfo.setClientSecret(apiApplicationKey.getClientSecret());
applicationInfo.setCallBackURL(applicationInfo.getCallBackURL());
applicationInfo.setIsSaasApplication(applicationInfo.getIsSaasApplication());
applicationInfo.setAppOwner(apiApplicationKey.getIsSaasApplication());
applicationInfo.setJsonString(applicationInfo.getJsonString());
applicationInfo.setJsonAppAttribute(apiApplicationKey.getJsonAppAttribute());
applicationInfo.setToken_type(applicationInfo.getToken_type());
applicationInfo.setExpires_in(accessTokenInfo.getExpires_in());
applicationInfo.setRefresh_token(accessTokenInfo.getRefresh_token());
applicationInfo.setAccess_token(accessTokenInfo.getAccess_token());
applicationInfo.setScope(accessTokenInfo.getScope());
return applicationInfo;
}
@Override
public APIApplicationInfo apiApplicationInfoFromRefreshToken() throws APIServicesException {
APIApplicationKey apiApplicationKey = createAndRetrieveApplicationCredentials();
AccessTokenInfo accessTokenInfo = generateAccessTokenFromRegisteredApplication(apiApplicationKey.getClientId(),
apiApplicationKey.getClientSecret());
APIApplicationInfo applicationInfo = null;
applicationInfo.setClientName(apiApplicationKey.getClientName());
applicationInfo.setClientId(apiApplicationKey.getClientId());
applicationInfo.setClientSecret(apiApplicationKey.getClientSecret());
applicationInfo.setCallBackURL(applicationInfo.getCallBackURL());
applicationInfo.setIsSaasApplication(applicationInfo.getIsSaasApplication());
applicationInfo.setAppOwner(apiApplicationKey.getIsSaasApplication());
applicationInfo.setJsonString(applicationInfo.getJsonString());
applicationInfo.setJsonAppAttribute(apiApplicationKey.getJsonAppAttribute());
applicationInfo.setToken_type(applicationInfo.getToken_type());
applicationInfo.setExpires_in(accessTokenInfo.getExpires_in());
applicationInfo.setRefresh_token(accessTokenInfo.getRefresh_token());
applicationInfo.setAccess_token(accessTokenInfo.getAccess_token());
applicationInfo.setScope(accessTokenInfo.getScope());
return applicationInfo;
}
}

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.apimgt.extension.rest.api;
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.AccessTokenInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
@ -35,84 +36,38 @@ import org.wso2.carbon.apimgt.api.model.Documentation;
import java.util.List;
public interface PublisherRESTAPIServices {
JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean addNewSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIIdentifier apiIdentifier)
boolean isSharedScopeNameExists(APIApplicationInfo applicationInfo, String key)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
boolean addNewSharedScope(APIApplicationInfo applicationInfo, Scope scope)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
JSONObject getApi(APIApplicationInfo applicationInfo, APIIdentifier apiIdentifier)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean updateApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
JSONObject getApis(APIApplicationInfo applicationInfo)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean saveAsyncApiDefinition(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
String asyncApiDefinition)
JSONObject addAPI(APIApplicationInfo applicationInfo, APIInfo api)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIIdentifier apiIdentifier)
boolean updateApi(APIApplicationInfo applicationInfo, APIInfo api)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean addApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
String uuid, Mediation mediation)
boolean saveAsyncApiDefinition(APIApplicationInfo applicationInfo, String uuid, String asyncApiDefinition)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean updateApiSpecificMediationPolicyContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
String uuid, Mediation mediation)
boolean addApiSpecificMediationPolicy(APIApplicationInfo applicationInfo, String uuid, Mediation mediation)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean changeLifeCycleStatus(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
boolean changeLifeCycleStatus(APIApplicationInfo applicationInfo,
String uuid, String action)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
Boolean deploymentStatus)
JSONObject addAPIRevision(APIApplicationInfo applicationInfo, APIRevision apiRevision)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIRevision apiRevision)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean deployAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
boolean deployAPIRevision(APIApplicationInfo applicationInfo, String uuid,
String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeploymentList)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
abstract boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
JSONObject apiRevisionDeployment, String uuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
JSONObject apiRevision, String uuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
String uuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean deleteDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
String uuid, String documentID)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
Documentation addDocumentation(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
String uuid, Documentation documentation)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean addDocumentationContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIInfo api, String docId, String docContent)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
}

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

@ -0,0 +1,130 @@
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto;
public class APIApplicationInfo {
private String clientName;
private String clientId;
private String clientSecret;
private String callBackURL;
private String isSaasApplication;
private String appOwner;
private String jsonString;
private String jsonAppAttribute;
private String tokenType;
private String token_type;
private long expires_in;
private String refresh_token;
private String access_token;
private String scope;
public String getClientName() {
return clientName;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getClientSecret() {
return clientSecret;
}
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
public String getCallBackURL() {
return callBackURL;
}
public void setCallBackURL(String callBackURL) {
this.callBackURL = callBackURL;
}
public String getIsSaasApplication() {
return isSaasApplication;
}
public void setIsSaasApplication(String isSaasApplication) {
this.isSaasApplication = isSaasApplication;
}
public String getAppOwner() {
return appOwner;
}
public void setAppOwner(String appOwner) {
this.appOwner = appOwner;
}
public String getJsonString() {
return jsonString;
}
public void setJsonString(String jsonString) {
this.jsonString = jsonString;
}
public String getJsonAppAttribute() {
return jsonAppAttribute;
}
public void setJsonAppAttribute(String jsonAppAttribute) {
this.jsonAppAttribute = jsonAppAttribute;
}
public String getTokenType() {
return tokenType;
}
public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}
public String getToken_type() {
return token_type;
}
public void setToken_type(String token_type) {
this.token_type = token_type;
}
public long getExpires_in() {
return expires_in;
}
public void setExpires_in(long expires_in) {
this.expires_in = expires_in;
}
public String getRefresh_token() {
return refresh_token;
}
public void setRefresh_token(String refresh_token) {
this.refresh_token = refresh_token;
}
public String getAccess_token() {
return access_token;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
}

@ -22,6 +22,7 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationService
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServicesImpl;
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.AccessTokenInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
@ -103,12 +104,14 @@ public class APIPublisherServiceImpl implements APIPublisherService {
.getOSGiService(RealmService.class, null);
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
APIApplicationKey apiApplicationKey;
AccessTokenInfo accessTokenInfo;
APIApplicationInfo apiApplicationInfo;
// APIApplicationKey apiApplicationKey;
// AccessTokenInfo accessTokenInfo;
try {
apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials();
accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication(
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
apiApplicationInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication();
// apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials();
// accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication(
// apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
} catch (APIServicesException e) {
String errorMsg = "Error occurred while generating the API application";
log.error(errorMsg, e);
@ -156,7 +159,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
apiConfig.getName(), apiConfig.getVersion());
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
JSONArray apiList = (JSONArray) publisherRESTAPIServices.getApis(apiApplicationKey, accessTokenInfo).get("list");
JSONArray apiList = (JSONArray) publisherRESTAPIServices.getApis(apiApplicationInfo).get("list");
boolean apiFound = false;
for (int i = 0; i < apiList.length(); i++) {
JSONObject apiObj = apiList.getJSONObject(i);
@ -170,21 +173,20 @@ public class APIPublisherServiceImpl implements APIPublisherService {
if (!apiFound) {
// add new scopes as shared scopes
for (ApiScope apiScope : apiConfig.getScopes()) {
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo,
apiScope.getKey())) {
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationInfo, apiScope.getKey())) {
Scope scope = new Scope();
scope.setName(apiScope.getName());
scope.setDescription(apiScope.getDescription());
scope.setKey(apiScope.getKey());
scope.setRoles(apiScope.getRoles());
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
publisherRESTAPIServices.addNewSharedScope(apiApplicationInfo, scope);
}
}
APIInfo api = getAPI(apiConfig, true);
JSONObject createdAPI = publisherRESTAPIServices.addAPI(apiApplicationKey, accessTokenInfo, api);
JSONObject createdAPI = publisherRESTAPIServices.addAPI(apiApplicationInfo, api);
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo,
createdAPI.getString("id"), apiConfig.getAsyncApiDefinition());
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationInfo, createdAPI.getString("id"),
apiConfig.getAsyncApiDefinition());
}
if (CREATED_STATUS.equals(createdAPI.getString("lifeCycleStatus"))) {
// if endpoint type "dynamic" and then add in sequence
@ -194,17 +196,15 @@ public class APIPublisherServiceImpl implements APIPublisherService {
mediation.setConfig(apiConfig.getInSequenceConfig());
mediation.setType("in");
mediation.setGlobal(false);
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
accessTokenInfo, createdAPI.getString("id"), mediation);
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationInfo,
createdAPI.getString("id"), mediation);
}
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey, accessTokenInfo,
createdAPI.getString("id"), PUBLISH_ACTION);
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationInfo, createdAPI.getString("id"), PUBLISH_ACTION);
APIRevision apiRevision = new APIRevision();
apiRevision.setApiUUID(createdAPI.getString("id"));
apiRevision.setDescription("Initial Revision");
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
accessTokenInfo, apiRevision).getString("id");
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationInfo, apiRevision).getString("id");
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setDeployment(API_PUBLISH_ENVIRONMENT);
@ -213,8 +213,8 @@ public class APIPublisherServiceImpl implements APIPublisherService {
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();
apiRevisionDeploymentList.add(apiRevisionDeployment);
publisherRESTAPIServices.deployAPIRevision(apiApplicationKey, accessTokenInfo,
createdAPI.getString("id"), apiRevisionId, apiRevisionDeploymentList);
publisherRESTAPIServices.deployAPIRevision(apiApplicationInfo, createdAPI.getString("id"),
apiRevisionId, apiRevisionDeploymentList);
}
} else {
if (WebappPublisherConfig.getInstance().isEnabledUpdateApi()) {
@ -237,8 +237,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
for (ApiScope apiScope : apiConfig.getScopes()) {
// if the scope is not available as shared scope, and it is assigned to an API as a local scope
// need remove the local scope and add as a shared scope
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo,
apiScope.getKey())) {
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationInfo, apiScope.getKey())) {
//resolve- todo:apim- resolve
// if (apiProvider.isScopeKeyAssignedLocally(apiIdentifier, apiScope.getKey(), tenantId)) {
if (true) {
@ -251,20 +250,19 @@ public class APIPublisherServiceImpl implements APIPublisherService {
scope.setDescription(apiScope.getDescription());
scope.setKey(apiScope.getKey());
scope.setRoles(apiScope.getRoles());
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
publisherRESTAPIServices.addNewSharedScope(apiApplicationInfo, scope);
}
}
}
// Get existing API
JSONObject existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo,
apiIdentifier);
JSONObject existingAPI = publisherRESTAPIServices.getApi(apiApplicationInfo, apiIdentifier);
if (scopesToMoveAsSharedScopes.size() > 0) {
// update API to remove local scopes
APIInfo api = getAPI(apiConfig, false);
api.setLifeCycleStatus(existingAPI.getString("lifeCycleStatus"));
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
publisherRESTAPIServices.updateApi(apiApplicationInfo, api);
for (ApiScope apiScope : scopesToMoveAsSharedScopes) {
Scope scope = new Scope();
@ -272,19 +270,19 @@ public class APIPublisherServiceImpl implements APIPublisherService {
scope.setDescription(apiScope.getDescription());
scope.setKey(apiScope.getKey());
scope.setRoles(apiScope.getRoles());
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
publisherRESTAPIServices.addNewSharedScope(apiApplicationInfo, scope);
}
}
existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo, apiIdentifier);
existingAPI = publisherRESTAPIServices.getApi(apiApplicationInfo, apiIdentifier);
APIInfo api = getAPI(apiConfig, true);
api.setLastUpdatedTime(existingAPI.getString("lifeCycleStatus"));
api.setId(existingAPI.getString("id"));
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
publisherRESTAPIServices.updateApi(apiApplicationInfo, api);
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo,
existingAPI.getString("id"), apiConfig.getAsyncApiDefinition());
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationInfo, existingAPI.getString("id"),
apiConfig.getAsyncApiDefinition());
}
// if endpoint type "dynamic" and then add /update in sequence
@ -311,8 +309,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
}
}
if (!isMediationPolicyFound) {
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
accessTokenInfo, existingAPI.getString("id"), mediation);
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationInfo, existingAPI.getString("id"), mediation);
}
}
@ -338,8 +335,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
APIRevision apiRevision = new APIRevision();
apiRevision.setApiUUID(existingAPI.getString("id"));
apiRevision.setDescription("Updated Revision");
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
accessTokenInfo, apiRevision).getString("id");
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationInfo, apiRevision).getString("id");
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setDeployment(API_PUBLISH_ENVIRONMENT);
@ -349,12 +345,11 @@ public class APIPublisherServiceImpl implements APIPublisherService {
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();
apiRevisionDeploymentList.add(apiRevisionDeployment);
publisherRESTAPIServices.deployAPIRevision(apiApplicationKey, accessTokenInfo,
existingAPI.getString("id"), apiRevisionId, apiRevisionDeploymentList);
publisherRESTAPIServices.deployAPIRevision(apiApplicationInfo, existingAPI.getString("id"),
apiRevisionId, apiRevisionDeploymentList);
if (CREATED_STATUS.equals(existingAPI.getString("lifeCycleStatus"))) {
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey,accessTokenInfo,
existingAPI.getString("id"), PUBLISH_ACTION);
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationInfo, existingAPI.getString("id"), PUBLISH_ACTION);
}
}
}
@ -433,12 +428,14 @@ public class APIPublisherServiceImpl implements APIPublisherService {
tenants.addAll(config.getTenants().getTenant());
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
APIApplicationKey apiApplicationKey;
AccessTokenInfo accessTokenInfo;
APIApplicationInfo applicationInfo;
// APIApplicationKey apiApplicationKey;
// AccessTokenInfo accessTokenInfo;
try {
apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials();
accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication(
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
applicationInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication();
// apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials();
// accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication(
// apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
} catch (APIServicesException e) {
String errorMsg = "Error occurred while generating the API application";
log.error(errorMsg, e);
@ -506,7 +503,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
}
}
if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getKey())) {
if (publisherRESTAPIServices.isSharedScopeNameExists(applicationInfo, scope.getKey())) {
publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope);
} else {
// todo: come to this level means, that scope is removed from API, but haven't removed from the scope-role-permission-mappings list

Loading…
Cancel
Save