|
|
@ -18,7 +18,6 @@
|
|
|
|
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.annotations.Scopes;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
|
|
|
@ -43,7 +42,6 @@ import io.entgra.device.mgt.core.device.mgt.core.config.permission.ScopeMapping;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.wso2.carbon.CarbonConstants;
|
|
|
|
import org.wso2.carbon.CarbonConstants;
|
|
|
|
import org.wso2.carbon.apimgt.api.APIManagementException;
|
|
|
|
import org.wso2.carbon.apimgt.api.APIManagementException;
|
|
|
@ -109,7 +107,8 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
RealmService realmService = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
|
|
|
RealmService realmService = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
|
|
|
.getOSGiService(RealmService.class, null);
|
|
|
|
.getOSGiService(RealmService.class, null);
|
|
|
|
|
|
|
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = APIPublisherDataHolder.getInstance().getApiApplicationServices();
|
|
|
|
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
|
|
|
|
APIApplicationKey apiApplicationKey;
|
|
|
|
APIApplicationKey apiApplicationKey;
|
|
|
|
AccessTokenInfo accessTokenInfo;
|
|
|
|
AccessTokenInfo accessTokenInfo;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -162,7 +161,6 @@ 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());
|
|
|
|
|
|
|
|
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
|
|
|
|
|
|
|
|
APIInfo[] apiList = publisherRESTAPIServices.getApis(apiApplicationKey, accessTokenInfo);
|
|
|
|
APIInfo[] apiList = publisherRESTAPIServices.getApis(apiApplicationKey, accessTokenInfo);
|
|
|
|
boolean apiFound = false;
|
|
|
|
boolean apiFound = false;
|
|
|
|
for (int i = 0; i < apiList.length; i++) {
|
|
|
|
for (int i = 0; i < apiList.length; i++) {
|
|
|
@ -444,7 +442,9 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
public void addDefaultScopesIfNotExist() {
|
|
|
|
public void addDefaultScopesIfNotExist() {
|
|
|
|
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
|
|
|
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
|
|
|
DefaultPermissions defaultPermissions = deviceManagementConfig.getDefaultPermissions();
|
|
|
|
DefaultPermissions defaultPermissions = deviceManagementConfig.getDefaultPermissions();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = APIPublisherDataHolder.getInstance().getApiApplicationServices();
|
|
|
|
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
APIApplicationKey apiApplicationKey =
|
|
|
|
APIApplicationKey apiApplicationKey =
|
|
|
|
apiApplicationServices.createAndRetrieveApplicationCredentials();
|
|
|
|
apiApplicationServices.createAndRetrieveApplicationCredentials();
|
|
|
@ -452,8 +452,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
apiApplicationServices.generateAccessTokenFromRegisteredApplication(
|
|
|
|
apiApplicationServices.generateAccessTokenFromRegisteredApplication(
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
|
|
|
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(apiApplicationKey, accessTokenInfo,
|
|
|
@ -484,7 +482,9 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
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 = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = APIPublisherDataHolder.getInstance().getApiApplicationServices();
|
|
|
|
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
|
|
|
|
|
|
|
|
|
|
|
|
APIApplicationKey apiApplicationKey;
|
|
|
|
APIApplicationKey apiApplicationKey;
|
|
|
|
AccessTokenInfo accessTokenInfo;
|
|
|
|
AccessTokenInfo accessTokenInfo;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -502,7 +502,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
for (String tenantDomain : tenants) {
|
|
|
|
for (String tenantDomain : tenants) {
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String fileName =
|
|
|
|
String fileName =
|
|
|
@ -618,7 +617,8 @@ 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 {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = APIPublisherDataHolder.getInstance().getApiApplicationServices();
|
|
|
|
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
|
|
|
|
APIApplicationKey apiApplicationKey;
|
|
|
|
APIApplicationKey apiApplicationKey;
|
|
|
|
AccessTokenInfo accessTokenInfo;
|
|
|
|
AccessTokenInfo accessTokenInfo;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -632,7 +632,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
|
|
|
|
|
|
|
|
Scope[] scopeList = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo);
|
|
|
|
Scope[] scopeList = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo);
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> permScopeMap = APIPublisherDataHolder.getInstance().getPermScopeMapping();
|
|
|
|
Map<String, String> permScopeMap = APIPublisherDataHolder.getInstance().getPermScopeMapping();
|
|
|
|