|
|
@ -18,10 +18,8 @@
|
|
|
|
package io.entgra.device.mgt.core.apimgt.webapp.publisher;
|
|
|
|
package io.entgra.device.mgt.core.apimgt.webapp.publisher;
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
|
|
|
|
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.APIInfo.APIInfo;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIInfo;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIRevision;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIRevision;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIRevisionDeployment;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIRevisionDeployment;
|
|
|
@ -31,7 +29,6 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Mediation
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.MediationPolicy;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.MediationPolicy;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Operations;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Operations;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Scope;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Scope;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
@ -68,8 +65,6 @@ import org.wso2.carbon.user.core.tenant.Tenant;
|
|
|
|
import org.wso2.carbon.user.core.tenant.TenantSearchResult;
|
|
|
|
import org.wso2.carbon.user.core.tenant.TenantSearchResult;
|
|
|
|
import org.wso2.carbon.utils.CarbonUtils;
|
|
|
|
import org.wso2.carbon.utils.CarbonUtils;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.permission.mgt.PermissionUtils;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.permission.mgt.PermissionManagementException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.permission.mgt.PermissionManagementException;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.BufferedReader;
|
|
|
@ -117,11 +112,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
tenants.addAll(config.getTenants().getTenant());
|
|
|
|
tenants.addAll(config.getTenants().getTenant());
|
|
|
|
RealmService realmService = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
|
|
|
RealmService realmService = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
|
|
|
.getOSGiService(RealmService.class, null);
|
|
|
|
.getOSGiService(RealmService.class, null);
|
|
|
|
|
|
|
|
|
|
|
|
APIApplicationServices apiApplicationServices = APIPublisherDataHolder.getInstance().getApiApplicationServices();
|
|
|
|
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
|
|
|
|
APIApplicationKey apiApplicationKey;
|
|
|
|
|
|
|
|
AccessTokenInfo accessTokenInfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
boolean tenantFound = false;
|
|
|
|
boolean tenantFound = false;
|
|
|
@ -156,17 +147,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(apiConfig.getOwner());
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(apiConfig.getOwner());
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
APIPublisherUtils.createScopePublishUserIfNotExists(tenantDomain);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
throw new APIManagerPublisherException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
apiConfig.setOwner(APIUtil.getTenantAdminUserName(tenantDomain));
|
|
|
|
apiConfig.setOwner(APIUtil.getTenantAdminUserName(tenantDomain));
|
|
|
|
apiConfig.setTenantDomain(tenantDomain);
|
|
|
|
apiConfig.setTenantDomain(tenantDomain);
|
|
|
@ -174,7 +154,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
APIIdentifier apiIdentifier = new APIIdentifier(APIUtil.replaceEmailDomain(apiConfig.getOwner()),
|
|
|
|
APIIdentifier apiIdentifier = new APIIdentifier(APIUtil.replaceEmailDomain(apiConfig.getOwner()),
|
|
|
|
apiConfig.getName(), apiConfig.getVersion());
|
|
|
|
apiConfig.getName(), apiConfig.getVersion());
|
|
|
|
|
|
|
|
|
|
|
|
APIInfo[] apiList = publisherRESTAPIServices.getApis(apiApplicationKey, accessTokenInfo);
|
|
|
|
APIInfo[] apiList = publisherRESTAPIServices.getApis();
|
|
|
|
boolean apiFound = false;
|
|
|
|
boolean apiFound = false;
|
|
|
|
for (int i = 0; i < apiList.length; i++) {
|
|
|
|
for (int i = 0; i < apiList.length; i++) {
|
|
|
|
APIInfo apiObj = apiList[i];
|
|
|
|
APIInfo apiObj = apiList[i];
|
|
|
@ -189,8 +169,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
if (!apiFound) {
|
|
|
|
if (!apiFound) {
|
|
|
|
// add new scopes as shared scopes
|
|
|
|
// add new scopes as shared scopes
|
|
|
|
for (ApiScope apiScope : apiConfig.getScopes()) {
|
|
|
|
for (ApiScope apiScope : apiConfig.getScopes()) {
|
|
|
|
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo,
|
|
|
|
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiScope.getKey())) {
|
|
|
|
apiScope.getKey())) {
|
|
|
|
|
|
|
|
Scope scope = new Scope();
|
|
|
|
Scope scope = new Scope();
|
|
|
|
scope.setDisplayName(apiScope.getName());
|
|
|
|
scope.setDisplayName(apiScope.getName());
|
|
|
|
scope.setDescription(apiScope.getDescription());
|
|
|
|
scope.setDescription(apiScope.getDescription());
|
|
|
@ -198,15 +177,14 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
List<String> bindings = new ArrayList<>(apiScope.getRoles());
|
|
|
|
List<String> bindings = new ArrayList<>(apiScope.getRoles());
|
|
|
|
bindings.add(ADMIN_ROLE_KEY);
|
|
|
|
bindings.add(ADMIN_ROLE_KEY);
|
|
|
|
scope.setBindings(bindings);
|
|
|
|
scope.setBindings(bindings);
|
|
|
|
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
|
|
|
publisherRESTAPIServices.addNewSharedScope(scope);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
APIInfo api = getAPI(apiConfig, true);
|
|
|
|
APIInfo api = getAPI(apiConfig, true);
|
|
|
|
APIInfo createdAPI = publisherRESTAPIServices.addAPI(apiApplicationKey, accessTokenInfo, api);
|
|
|
|
APIInfo createdAPI = publisherRESTAPIServices.addAPI(api);
|
|
|
|
apiUuid = createdAPI.getId();
|
|
|
|
apiUuid = createdAPI.getId();
|
|
|
|
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
|
|
|
|
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
|
|
|
|
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo,
|
|
|
|
publisherRESTAPIServices.saveAsyncApiDefinition(apiUuid, apiConfig.getAsyncApiDefinition());
|
|
|
|
apiUuid, apiConfig.getAsyncApiDefinition());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CREATED_STATUS.equals(createdAPI.getLifeCycleStatus())) {
|
|
|
|
if (CREATED_STATUS.equals(createdAPI.getLifeCycleStatus())) {
|
|
|
|
// if endpoint type "dynamic" and then add in sequence
|
|
|
|
// if endpoint type "dynamic" and then add in sequence
|
|
|
@ -216,17 +194,14 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
mediation.setConfig(apiConfig.getInSequenceConfig());
|
|
|
|
mediation.setConfig(apiConfig.getInSequenceConfig());
|
|
|
|
mediation.setType("in");
|
|
|
|
mediation.setType("in");
|
|
|
|
mediation.setGlobal(false);
|
|
|
|
mediation.setGlobal(false);
|
|
|
|
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
|
|
|
|
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiUuid, mediation);
|
|
|
|
accessTokenInfo, apiUuid, mediation);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey, accessTokenInfo,
|
|
|
|
publisherRESTAPIServices.changeLifeCycleStatus(apiUuid, PUBLISH_ACTION);
|
|
|
|
apiUuid, PUBLISH_ACTION);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
APIRevision apiRevision = new APIRevision();
|
|
|
|
APIRevision apiRevision = new APIRevision();
|
|
|
|
apiRevision.setApiUUID(apiUuid);
|
|
|
|
apiRevision.setApiUUID(apiUuid);
|
|
|
|
apiRevision.setDescription("Initial Revision");
|
|
|
|
apiRevision.setDescription("Initial Revision");
|
|
|
|
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
|
|
|
|
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiRevision).getId();
|
|
|
|
accessTokenInfo, apiRevision).getId();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
|
|
|
|
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
|
|
|
|
apiRevisionDeployment.setName(API_PUBLISH_ENVIRONMENT);
|
|
|
|
apiRevisionDeployment.setName(API_PUBLISH_ENVIRONMENT);
|
|
|
@ -235,8 +210,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
|
|
|
|
|
|
|
|
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();
|
|
|
|
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();
|
|
|
|
apiRevisionDeploymentList.add(apiRevisionDeployment);
|
|
|
|
apiRevisionDeploymentList.add(apiRevisionDeployment);
|
|
|
|
publisherRESTAPIServices.deployAPIRevision(apiApplicationKey, accessTokenInfo,
|
|
|
|
publisherRESTAPIServices.deployAPIRevision(apiUuid, apiRevisionId, apiRevisionDeploymentList);
|
|
|
|
apiUuid, apiRevisionId, apiRevisionDeploymentList);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (WebappPublisherConfig.getInstance().isEnabledUpdateApi()) {
|
|
|
|
if (WebappPublisherConfig.getInstance().isEnabledUpdateApi()) {
|
|
|
@ -259,8 +233,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
for (ApiScope apiScope : apiConfig.getScopes()) {
|
|
|
|
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
|
|
|
|
// 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
|
|
|
|
// need remove the local scope and add as a shared scope
|
|
|
|
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo,
|
|
|
|
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiScope.getKey())) {
|
|
|
|
apiScope.getKey())) {
|
|
|
|
|
|
|
|
if (apiProvider.isScopeKeyAssignedLocally(apiIdentifier, apiScope.getKey(), tenantId)) {
|
|
|
|
if (apiProvider.isScopeKeyAssignedLocally(apiIdentifier, apiScope.getKey(), tenantId)) {
|
|
|
|
// collect scope to move as shared scopes
|
|
|
|
// collect scope to move as shared scopes
|
|
|
|
scopesToMoveAsSharedScopes.add(apiScope);
|
|
|
|
scopesToMoveAsSharedScopes.add(apiScope);
|
|
|
@ -273,20 +246,19 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
List<String> bindings = new ArrayList<>(apiScope.getRoles());
|
|
|
|
List<String> bindings = new ArrayList<>(apiScope.getRoles());
|
|
|
|
bindings.add(ADMIN_ROLE_KEY);
|
|
|
|
bindings.add(ADMIN_ROLE_KEY);
|
|
|
|
scope.setBindings(bindings);
|
|
|
|
scope.setBindings(bindings);
|
|
|
|
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
|
|
|
publisherRESTAPIServices.addNewSharedScope(scope);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get existing API
|
|
|
|
// Get existing API
|
|
|
|
APIInfo existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo,
|
|
|
|
APIInfo existingAPI = publisherRESTAPIServices.getApi(apiUuid);
|
|
|
|
apiUuid);
|
|
|
|
|
|
|
|
if (scopesToMoveAsSharedScopes.size() > 0) {
|
|
|
|
if (scopesToMoveAsSharedScopes.size() > 0) {
|
|
|
|
// update API to remove local scopes
|
|
|
|
// update API to remove local scopes
|
|
|
|
APIInfo api = getAPI(apiConfig, false);
|
|
|
|
APIInfo api = getAPI(apiConfig, false);
|
|
|
|
api.setLifeCycleStatus(existingAPI.getLifeCycleStatus());
|
|
|
|
api.setLifeCycleStatus(existingAPI.getLifeCycleStatus());
|
|
|
|
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
|
|
|
|
publisherRESTAPIServices.updateApi(api);
|
|
|
|
|
|
|
|
|
|
|
|
for (ApiScope apiScope : scopesToMoveAsSharedScopes) {
|
|
|
|
for (ApiScope apiScope : scopesToMoveAsSharedScopes) {
|
|
|
|
Scope scope = new Scope();
|
|
|
|
Scope scope = new Scope();
|
|
|
@ -296,19 +268,18 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
List<String> bindings = new ArrayList<>(apiScope.getRoles());
|
|
|
|
List<String> bindings = new ArrayList<>(apiScope.getRoles());
|
|
|
|
bindings.add(ADMIN_ROLE_KEY);
|
|
|
|
bindings.add(ADMIN_ROLE_KEY);
|
|
|
|
scope.setBindings(bindings);
|
|
|
|
scope.setBindings(bindings);
|
|
|
|
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
|
|
|
publisherRESTAPIServices.addNewSharedScope(scope);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo, apiUuid);
|
|
|
|
existingAPI = publisherRESTAPIServices.getApi(apiUuid);
|
|
|
|
APIInfo api = getAPI(apiConfig, true);
|
|
|
|
APIInfo api = getAPI(apiConfig, true);
|
|
|
|
api.setLifeCycleStatus(existingAPI.getLifeCycleStatus());
|
|
|
|
api.setLifeCycleStatus(existingAPI.getLifeCycleStatus());
|
|
|
|
api.setId(apiUuid);
|
|
|
|
api.setId(apiUuid);
|
|
|
|
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
|
|
|
|
publisherRESTAPIServices.updateApi(api);
|
|
|
|
|
|
|
|
|
|
|
|
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
|
|
|
|
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
|
|
|
|
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo,
|
|
|
|
publisherRESTAPIServices.saveAsyncApiDefinition(apiUuid, apiConfig.getAsyncApiDefinition());
|
|
|
|
apiUuid, apiConfig.getAsyncApiDefinition());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if endpoint type "dynamic" and then add /update in sequence
|
|
|
|
// if endpoint type "dynamic" and then add /update in sequence
|
|
|
@ -320,45 +291,37 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
mediation.setGlobal(false);
|
|
|
|
mediation.setGlobal(false);
|
|
|
|
|
|
|
|
|
|
|
|
MediationPolicy[] mediationList = publisherRESTAPIServices
|
|
|
|
MediationPolicy[] mediationList = publisherRESTAPIServices
|
|
|
|
.getAllApiSpecificMediationPolicies(apiApplicationKey, accessTokenInfo, apiUuid);
|
|
|
|
.getAllApiSpecificMediationPolicies(apiUuid);
|
|
|
|
|
|
|
|
|
|
|
|
boolean isMediationPolicyFound = false;
|
|
|
|
boolean isMediationPolicyFound = false;
|
|
|
|
for (int i = 0; i < mediationList.length; i++) {
|
|
|
|
for (int i = 0; i < mediationList.length; i++) {
|
|
|
|
MediationPolicy mediationPolicy = mediationList[i];
|
|
|
|
MediationPolicy mediationPolicy = mediationList[i];
|
|
|
|
if (apiConfig.getInSequenceName().equals(mediationPolicy.getName())) {
|
|
|
|
if (apiConfig.getInSequenceName().equals(mediationPolicy.getName())) {
|
|
|
|
mediation.setUuid(mediationPolicy.getId());
|
|
|
|
mediation.setUuid(mediationPolicy.getId());
|
|
|
|
publisherRESTAPIServices.deleteApiSpecificMediationPolicy(apiApplicationKey,
|
|
|
|
publisherRESTAPIServices.deleteApiSpecificMediationPolicy(apiUuid, mediation);
|
|
|
|
accessTokenInfo, apiUuid, mediation);
|
|
|
|
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiUuid, mediation);
|
|
|
|
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
|
|
|
|
|
|
|
|
accessTokenInfo, apiUuid, mediation);
|
|
|
|
|
|
|
|
isMediationPolicyFound = true;
|
|
|
|
isMediationPolicyFound = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isMediationPolicyFound) {
|
|
|
|
if (!isMediationPolicyFound) {
|
|
|
|
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
|
|
|
|
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiUuid, mediation);
|
|
|
|
accessTokenInfo, apiUuid, mediation);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int apiRevisionCount = publisherRESTAPIServices.getAPIRevisions(apiApplicationKey,
|
|
|
|
int apiRevisionCount = publisherRESTAPIServices.getAPIRevisions(apiUuid, null).length;
|
|
|
|
accessTokenInfo, apiUuid, null).length;
|
|
|
|
|
|
|
|
if (apiRevisionCount >= 5) {
|
|
|
|
if (apiRevisionCount >= 5) {
|
|
|
|
// This will retrieve the deployed revision
|
|
|
|
// This will retrieve the deployed revision
|
|
|
|
APIRevision[] revisionDeploymentList = publisherRESTAPIServices.getAPIRevisions(
|
|
|
|
APIRevision[] revisionDeploymentList = publisherRESTAPIServices.getAPIRevisions(apiUuid, true);
|
|
|
|
apiApplicationKey, accessTokenInfo, apiUuid, true);
|
|
|
|
|
|
|
|
if (revisionDeploymentList.length > 0) {
|
|
|
|
if (revisionDeploymentList.length > 0) {
|
|
|
|
APIRevision latestRevisionDeployment = revisionDeploymentList[0];
|
|
|
|
APIRevision latestRevisionDeployment = revisionDeploymentList[0];
|
|
|
|
publisherRESTAPIServices.undeployAPIRevisionDeployment(apiApplicationKey,
|
|
|
|
publisherRESTAPIServices.undeployAPIRevisionDeployment(latestRevisionDeployment, apiUuid);
|
|
|
|
accessTokenInfo, latestRevisionDeployment, apiUuid);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// This will retrieve the undeployed revision list
|
|
|
|
// This will retrieve the undeployed revision list
|
|
|
|
APIRevision[] undeployedRevisionList = publisherRESTAPIServices.getAPIRevisions(apiApplicationKey,
|
|
|
|
APIRevision[] undeployedRevisionList = publisherRESTAPIServices.getAPIRevisions(apiUuid, false);
|
|
|
|
accessTokenInfo, apiUuid, false);
|
|
|
|
|
|
|
|
if (undeployedRevisionList.length > 0) {
|
|
|
|
if (undeployedRevisionList.length > 0) {
|
|
|
|
APIRevision earliestUndeployRevision = undeployedRevisionList[0];
|
|
|
|
APIRevision earliestUndeployRevision = undeployedRevisionList[0];
|
|
|
|
publisherRESTAPIServices.deleteAPIRevision(apiApplicationKey, accessTokenInfo,
|
|
|
|
publisherRESTAPIServices.deleteAPIRevision(earliestUndeployRevision, apiUuid);
|
|
|
|
earliestUndeployRevision, apiUuid);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -366,8 +329,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
APIRevision apiRevision = new APIRevision();
|
|
|
|
APIRevision apiRevision = new APIRevision();
|
|
|
|
apiRevision.setApiUUID(apiUuid);
|
|
|
|
apiRevision.setApiUUID(apiUuid);
|
|
|
|
apiRevision.setDescription("Updated Revision");
|
|
|
|
apiRevision.setDescription("Updated Revision");
|
|
|
|
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
|
|
|
|
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiRevision).getId();
|
|
|
|
accessTokenInfo, apiRevision).getId();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
|
|
|
|
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
|
|
|
|
apiRevisionDeployment.setName(API_PUBLISH_ENVIRONMENT);
|
|
|
|
apiRevisionDeployment.setName(API_PUBLISH_ENVIRONMENT);
|
|
|
@ -377,12 +339,10 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();
|
|
|
|
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();
|
|
|
|
apiRevisionDeploymentList.add(apiRevisionDeployment);
|
|
|
|
apiRevisionDeploymentList.add(apiRevisionDeployment);
|
|
|
|
|
|
|
|
|
|
|
|
publisherRESTAPIServices.deployAPIRevision(apiApplicationKey, accessTokenInfo,
|
|
|
|
publisherRESTAPIServices.deployAPIRevision(apiUuid, apiRevisionId, apiRevisionDeploymentList);
|
|
|
|
apiUuid, apiRevisionId, apiRevisionDeploymentList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (CREATED_STATUS.equals(existingAPI.getLifeCycleStatus())) {
|
|
|
|
if (CREATED_STATUS.equals(existingAPI.getLifeCycleStatus())) {
|
|
|
|
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey, accessTokenInfo,
|
|
|
|
publisherRESTAPIServices.changeLifeCycleStatus(apiUuid, PUBLISH_ACTION);
|
|
|
|
apiUuid, PUBLISH_ACTION);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -412,26 +372,23 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
apiDocumentation.setSummary(apiConfig.getApiDocumentationSummary());
|
|
|
|
apiDocumentation.setSummary(apiConfig.getApiDocumentationSummary());
|
|
|
|
apiDocumentation.setOtherTypeName(null);
|
|
|
|
apiDocumentation.setOtherTypeName(null);
|
|
|
|
|
|
|
|
|
|
|
|
Documentation[] documentList = publisherRESTAPIServices.getDocumentations(apiApplicationKey,
|
|
|
|
Documentation[] documentList = publisherRESTAPIServices.getDocumentations(apiUuid);
|
|
|
|
accessTokenInfo, apiUuid);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (documentList.length > 0) {
|
|
|
|
if (documentList.length > 0) {
|
|
|
|
for (int i = 0; i < documentList.length; i++) {
|
|
|
|
for (int i = 0; i < documentList.length; i++) {
|
|
|
|
Documentation existingDoc = documentList[i];
|
|
|
|
Documentation existingDoc = documentList[i];
|
|
|
|
if (existingDoc.getName().equals(apiConfig.getApiDocumentationName())
|
|
|
|
if (existingDoc.getName().equals(apiConfig.getApiDocumentationName())
|
|
|
|
&& existingDoc.getType().equals(Documentation.DocumentationType.HOWTO.name())) {
|
|
|
|
&& existingDoc.getType().equals(Documentation.DocumentationType.HOWTO.name())) {
|
|
|
|
publisherRESTAPIServices.deleteDocumentations(apiApplicationKey, accessTokenInfo,
|
|
|
|
publisherRESTAPIServices.deleteDocumentations(apiUuid, existingDoc.getDocumentId());
|
|
|
|
apiUuid, existingDoc.getDocumentId());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
log.info("There is no any existing api documentation.");
|
|
|
|
log.info("There is no any existing api documentation.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Documentation createdDoc = publisherRESTAPIServices.addDocumentation(apiApplicationKey, accessTokenInfo,
|
|
|
|
Documentation createdDoc = publisherRESTAPIServices.addDocumentation(apiUuid, apiDocumentation);
|
|
|
|
apiUuid, apiDocumentation);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
publisherRESTAPIServices.addDocumentationContent(apiApplicationKey, accessTokenInfo, apiUuid,
|
|
|
|
publisherRESTAPIServices.addDocumentationContent(apiUuid,
|
|
|
|
createdDoc.getDocumentId(), docContent);
|
|
|
|
createdDoc.getDocumentId(), docContent);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -441,7 +398,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new APIManagerPublisherException(e);
|
|
|
|
throw new APIManagerPublisherException(e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
APIPublisherUtils.removeScopePublishUserIfExists(tenantDomain);
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -461,7 +417,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
|
|
|
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
|
|
|
DefaultPermissions defaultPermissions = deviceManagementConfig.getDefaultPermissions();
|
|
|
|
DefaultPermissions defaultPermissions = deviceManagementConfig.getDefaultPermissions();
|
|
|
|
APIApplicationServices apiApplicationServices = APIPublisherDataHolder.getInstance().getApiApplicationServices();
|
|
|
|
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
|
|
|
|
|
|
|
|
|
|
|
|
for (String tenantDomain : tenants) {
|
|
|
|
for (String tenantDomain : tenants) {
|
|
|
@ -469,17 +424,9 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
|
|
|
|
|
|
|
|
|
|
|
APIPublisherUtils.createScopePublishUserIfNotExists(tenantDomain);
|
|
|
|
|
|
|
|
APIApplicationKey apiApplicationKey =
|
|
|
|
|
|
|
|
apiApplicationServices.createAndRetrieveApplicationCredentials();
|
|
|
|
|
|
|
|
AccessTokenInfo accessTokenInfo =
|
|
|
|
|
|
|
|
apiApplicationServices.generateAccessTokenFromRegisteredApplication(
|
|
|
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Scope scope = new Scope();
|
|
|
|
Scope scope = new Scope();
|
|
|
|
for (DefaultPermission defaultPermission : defaultPermissions.getDefaultPermissions()) {
|
|
|
|
for (DefaultPermission defaultPermission : defaultPermissions.getDefaultPermissions()) {
|
|
|
|
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo,
|
|
|
|
if (!publisherRESTAPIServices.isSharedScopeNameExists(defaultPermission.getScopeMapping().getKey())) {
|
|
|
|
defaultPermission.getScopeMapping().getKey())) {
|
|
|
|
|
|
|
|
ScopeMapping scopeMapping = defaultPermission.getScopeMapping();
|
|
|
|
ScopeMapping scopeMapping = defaultPermission.getScopeMapping();
|
|
|
|
|
|
|
|
|
|
|
|
List<String> bindings = new ArrayList<>(
|
|
|
|
List<String> bindings = new ArrayList<>(
|
|
|
@ -489,7 +436,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
scope.setDescription(scopeMapping.getName());
|
|
|
|
scope.setDescription(scopeMapping.getName());
|
|
|
|
scope.setDisplayName(scopeMapping.getName());
|
|
|
|
scope.setDisplayName(scopeMapping.getName());
|
|
|
|
scope.setBindings(bindings);
|
|
|
|
scope.setBindings(bindings);
|
|
|
|
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
|
|
|
publisherRESTAPIServices.addNewSharedScope(scope);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (BadRequestException | UnexpectedResponseException | APIServicesException e) {
|
|
|
|
} catch (BadRequestException | UnexpectedResponseException | APIServicesException e) {
|
|
|
@ -497,7 +444,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
throw new APIManagerPublisherException(e);
|
|
|
|
throw new APIManagerPublisherException(e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
APIPublisherUtils.removeScopePublishUserIfExists(tenantDomain);
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -511,12 +457,8 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
WebappPublisherConfig config = WebappPublisherConfig.getInstance();
|
|
|
|
WebappPublisherConfig config = WebappPublisherConfig.getInstance();
|
|
|
|
List<String> tenants = new ArrayList<>(Collections.singletonList(APIConstants.SUPER_TENANT_DOMAIN));
|
|
|
|
List<String> tenants = new ArrayList<>(Collections.singletonList(APIConstants.SUPER_TENANT_DOMAIN));
|
|
|
|
tenants.addAll(config.getTenants().getTenant());
|
|
|
|
tenants.addAll(config.getTenants().getTenant());
|
|
|
|
|
|
|
|
|
|
|
|
APIApplicationServices apiApplicationServices = APIPublisherDataHolder.getInstance().getApiApplicationServices();
|
|
|
|
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
|
|
|
|
|
|
|
|
|
|
|
|
APIApplicationKey apiApplicationKey;
|
|
|
|
|
|
|
|
AccessTokenInfo accessTokenInfo;
|
|
|
|
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
UserStoreManager userStoreManager;
|
|
|
|
String fileName = null;
|
|
|
|
String fileName = null;
|
|
|
|
|
|
|
|
|
|
|
@ -524,16 +466,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
|
|
|
try {
|
|
|
|
|
|
|
|
APIPublisherUtils.createScopePublishUserIfNotExists(tenantDomain);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
throw new APIManagerPublisherException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
fileName =
|
|
|
|
fileName =
|
|
|
@ -599,7 +531,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Set scope details which related to the scope key
|
|
|
|
//Set scope details which related to the scope key
|
|
|
|
Scope[] scopes = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo);
|
|
|
|
Scope[] scopes = publisherRESTAPIServices.getScopes();
|
|
|
|
for (int i = 0; i < scopes.length; i++) {
|
|
|
|
for (int i = 0; i < scopes.length; i++) {
|
|
|
|
Scope relatedScope = scopes[i];
|
|
|
|
Scope relatedScope = scopes[i];
|
|
|
|
if (relatedScope.getName().equals(scopeMapping[2].toString())) {
|
|
|
|
if (relatedScope.getName().equals(scopeMapping[2].toString())) {
|
|
|
@ -611,13 +543,13 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scope.setBindings(rolesList);
|
|
|
|
scope.setBindings(rolesList);
|
|
|
|
|
|
|
|
|
|
|
|
if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getName())) {
|
|
|
|
if (publisherRESTAPIServices.isSharedScopeNameExists(scope.getName())) {
|
|
|
|
publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
|
|
|
publisherRESTAPIServices.updateSharedScope(scope);
|
|
|
|
// todo: permission changed in update path, is not handled yet.
|
|
|
|
// todo: permission changed in update path, is not handled yet.
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// This scope doesn't have an api attached.
|
|
|
|
// This scope doesn't have an api attached.
|
|
|
|
log.warn(scope.getName() + " not available as shared, add as new scope");
|
|
|
|
log.warn(scope.getName() + " not available as shared, add as new scope");
|
|
|
|
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
|
|
|
publisherRESTAPIServices.addNewSharedScope(scope);
|
|
|
|
// add permission if not exist
|
|
|
|
// add permission if not exist
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PermissionUtils.putPermission(permission);
|
|
|
|
PermissionUtils.putPermission(permission);
|
|
|
@ -652,7 +584,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
throw new APIManagerPublisherException(e);
|
|
|
|
throw new APIManagerPublisherException(e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
APIPublisherUtils.removeScopePublishUserIfExists(tenantDomain);
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -661,31 +592,18 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void updateScopeRoleMapping(String roleName, String[] permissions, String[] removedPermissions) throws APIManagerPublisherException {
|
|
|
|
public void updateScopeRoleMapping(String roleName, String[] permissions, String[] removedPermissions) throws APIManagerPublisherException {
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
APIApplicationServices apiApplicationServices = APIPublisherDataHolder.getInstance().getApiApplicationServices();
|
|
|
|
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
|
|
|
|
APIApplicationKey apiApplicationKey;
|
|
|
|
|
|
|
|
AccessTokenInfo accessTokenInfo;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
APIPublisherUtils.createScopePublishUserIfNotExists(tenantDomain);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
throw new APIManagerPublisherException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
Scope[] scopeList = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo);
|
|
|
|
Scope[] scopeList = publisherRESTAPIServices.getScopes();
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> permScopeMap = APIPublisherDataHolder.getInstance().getPermScopeMapping();
|
|
|
|
Map<String, String> permScopeMap = APIPublisherDataHolder.getInstance().getPermScopeMapping();
|
|
|
|
if (permissions.length != 0) {
|
|
|
|
if (permissions.length != 0) {
|
|
|
|
updateScopes(roleName, publisherRESTAPIServices, apiApplicationKey, accessTokenInfo, scopeList, permissions, permScopeMap, false);
|
|
|
|
updateScopes(roleName, publisherRESTAPIServices, scopeList, permissions, permScopeMap, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (removedPermissions.length != 0) {
|
|
|
|
if (removedPermissions.length != 0) {
|
|
|
|
updateScopes(roleName, publisherRESTAPIServices, apiApplicationKey, accessTokenInfo, scopeList, removedPermissions, permScopeMap, true);
|
|
|
|
updateScopes(roleName, publisherRESTAPIServices, scopeList, removedPermissions, permScopeMap, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -707,8 +625,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
String errorMsg = "Unexpected response from the server";
|
|
|
|
String errorMsg = "Unexpected response from the server";
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
throw new APIManagerPublisherException(errorMsg, e);
|
|
|
|
throw new APIManagerPublisherException(errorMsg, e);
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
APIPublisherUtils.removeScopePublishUserIfExists(tenantDomain);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -717,17 +633,13 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param roleName Role Name
|
|
|
|
* @param roleName Role Name
|
|
|
|
* @param publisherRESTAPIServices {@link PublisherRESTAPIServices}
|
|
|
|
* @param publisherRESTAPIServices {@link PublisherRESTAPIServices}
|
|
|
|
* @param apiApplicationKey {@link APIApplicationKey}
|
|
|
|
|
|
|
|
* @param accessTokenInfo {@link AccessTokenInfo}
|
|
|
|
|
|
|
|
* @param scopeList scope list returning from APIM
|
|
|
|
* @param scopeList scope list returning from APIM
|
|
|
|
* @param permissions List of permissions
|
|
|
|
* @param permissions List of permissions
|
|
|
|
* @param permScopeMap Permission Scope map
|
|
|
|
* @param permScopeMap Permission Scope map
|
|
|
|
* @param removingPermissions if list of permissions has to be removed from the role send true, otherwise sends false.
|
|
|
|
* @param removingPermissions if list of permissions has to be removed from the role send true, otherwise sends false.
|
|
|
|
* @throws APIManagerPublisherException If the method receives invalid permission to update.
|
|
|
|
* @throws APIManagerPublisherException If the method receives invalid permission to update.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void updateScopes (String roleName, PublisherRESTAPIServices publisherRESTAPIServices,
|
|
|
|
private void updateScopes (String roleName, PublisherRESTAPIServices publisherRESTAPIServices, Scope[] scopeList, String[] permissions, Map<String, String> permScopeMap, boolean removingPermissions )
|
|
|
|
APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
|
|
|
|
Scope[] scopeList, String[] permissions, Map<String, String> permScopeMap, boolean removingPermissions )
|
|
|
|
|
|
|
|
throws APIManagerPublisherException {
|
|
|
|
throws APIManagerPublisherException {
|
|
|
|
for (String permission : permissions) {
|
|
|
|
for (String permission : permissions) {
|
|
|
|
String scopeValue = permScopeMap.get(permission);
|
|
|
|
String scopeValue = permScopeMap.get(permission);
|
|
|
@ -765,8 +677,8 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
scope.setBindings(existingRoleList);
|
|
|
|
scope.setBindings(existingRoleList);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getName())) {
|
|
|
|
if (publisherRESTAPIServices.isSharedScopeNameExists(scope.getName())) {
|
|
|
|
publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
|
|
|
publisherRESTAPIServices.updateSharedScope(scope);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// todo: come to this level means, that scope is removed from API, but haven't removed from the scope-role-permission-mappings list
|
|
|
|
// todo: come to this level means, that scope is removed from API, but haven't removed from the scope-role-permission-mappings list
|
|
|
|
log.warn(scope.getName() + " not available as shared scope");
|
|
|
|
log.warn(scope.getName() + " not available as shared scope");
|
|
|
|