|
|
@ -24,7 +24,11 @@ import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplication
|
|
|
|
import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.application.extension.internal.APIApplicationManagerExtensionDataHolder;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.application.extension.internal.APIApplicationManagerExtensionDataHolder;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.application.extension.util.APIManagerUtil;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.application.extension.util.APIManagerUtil;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.*;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.APIInfo;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.ApplicationGrantTypeUpdater;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.ApplicationKey;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.KeyManager;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Subscription;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.TokenInfo;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.TokenInfo;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataKeyAlreadyExistsException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataKeyAlreadyExistsException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
|
|
@ -106,35 +110,42 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
// @Override
|
|
|
|
public synchronized ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String[] tags,
|
|
|
|
// public synchronized ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String[] tags,
|
|
|
|
String keyType,
|
|
|
|
// String keyType,
|
|
|
|
boolean isAllowedAllDomains,
|
|
|
|
// boolean isAllowedAllDomains,
|
|
|
|
String validityTime, String accessToken) throws APIManagerException {
|
|
|
|
// String validityTime, String accessToken) throws APIManagerException {
|
|
|
|
TokenInfo tokenInfo = new TokenInfo();
|
|
|
|
// TokenInfo tokenInfo = new TokenInfo();
|
|
|
|
tokenInfo.setApiApplicationInfo(null);
|
|
|
|
// tokenInfo.setApiApplicationInfo(null);
|
|
|
|
tokenInfo.setAccessToken(accessToken);
|
|
|
|
// tokenInfo.setAccessToken(accessToken);
|
|
|
|
return generateAndRetrieveApplicationKeys(applicationName, tags, keyType, isAllowedAllDomains, validityTime, tokenInfo);
|
|
|
|
// return generateAndRetrieveApplicationKeys(applicationName, tags, keyType, isAllowedAllDomains, validityTime,
|
|
|
|
}
|
|
|
|
// tokenInfo, null, false);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public synchronized ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String[] tags,
|
|
|
|
public synchronized ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String[] tags,
|
|
|
|
String keyType, String username,
|
|
|
|
String keyType, String username,
|
|
|
|
boolean isAllowedAllDomains,
|
|
|
|
boolean isAllowedAllDomains,
|
|
|
|
String validityTime, String password)
|
|
|
|
String validityTime, String password,
|
|
|
|
|
|
|
|
ApplicationGrantTypeUpdater applicationGrantTypeUpdater,
|
|
|
|
|
|
|
|
boolean isMappingRequired)
|
|
|
|
throws APIManagerException {
|
|
|
|
throws APIManagerException {
|
|
|
|
|
|
|
|
|
|
|
|
ApiApplicationInfo applicationInfo = getApplicationInfo(username, password);
|
|
|
|
ApiApplicationInfo applicationInfo = getApplicationInfo(username, password);
|
|
|
|
TokenInfo tokenInfo = new TokenInfo();
|
|
|
|
TokenInfo tokenInfo = new TokenInfo();
|
|
|
|
tokenInfo.setApiApplicationInfo(applicationInfo);
|
|
|
|
tokenInfo.setApiApplicationInfo(applicationInfo);
|
|
|
|
tokenInfo.setAccessToken(null);
|
|
|
|
tokenInfo.setAccessToken(null);
|
|
|
|
return generateAndRetrieveApplicationKeys(applicationName, tags, keyType, isAllowedAllDomains, validityTime, tokenInfo);
|
|
|
|
return generateAndRetrieveApplicationKeys(applicationName, tags, keyType, isAllowedAllDomains, validityTime,
|
|
|
|
|
|
|
|
tokenInfo, applicationGrantTypeUpdater, isMappingRequired);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String[] tags,
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public synchronized ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String[] tags,
|
|
|
|
String keyType,
|
|
|
|
String keyType,
|
|
|
|
boolean isAllowedAllDomains,
|
|
|
|
boolean isAllowedAllDomains,
|
|
|
|
String validityTime, TokenInfo tokenInfo) throws APIManagerException {
|
|
|
|
String validityTime, TokenInfo tokenInfo,
|
|
|
|
|
|
|
|
ApplicationGrantTypeUpdater applicationGrantTypeUpdater,
|
|
|
|
|
|
|
|
boolean isMappingRequired) throws APIManagerException {
|
|
|
|
|
|
|
|
|
|
|
|
ConsumerRESTAPIServices consumerRESTAPIServices =
|
|
|
|
ConsumerRESTAPIServices consumerRESTAPIServices =
|
|
|
|
APIApplicationManagerExtensionDataHolder.getInstance().getConsumerRESTAPIServices();
|
|
|
|
APIApplicationManagerExtensionDataHolder.getInstance().getConsumerRESTAPIServices();
|
|
|
@ -160,7 +171,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|
|
|
consumerRESTAPIServices.getAllApplications(tokenInfo, applicationName);
|
|
|
|
consumerRESTAPIServices.getAllApplications(tokenInfo, applicationName);
|
|
|
|
if (applications.length == 0) {
|
|
|
|
if (applications.length == 0) {
|
|
|
|
return handleNewAPIApplication(applicationName, uniqueApiList, tokenInfo, keyType,
|
|
|
|
return handleNewAPIApplication(applicationName, uniqueApiList, tokenInfo, keyType,
|
|
|
|
validityTime);
|
|
|
|
validityTime, applicationGrantTypeUpdater, isMappingRequired);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (applications.length == 1) {
|
|
|
|
if (applications.length == 1) {
|
|
|
|
Optional<io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application> applicationOpt =
|
|
|
|
Optional<io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application> applicationOpt =
|
|
|
@ -173,7 +184,8 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|
|
|
if (metaData == null) {
|
|
|
|
if (metaData == null) {
|
|
|
|
// Todo add a comment
|
|
|
|
// Todo add a comment
|
|
|
|
consumerRESTAPIServices.deleteApplication(tokenInfo, application.getApplicationId());
|
|
|
|
consumerRESTAPIServices.deleteApplication(tokenInfo, application.getApplicationId());
|
|
|
|
return handleNewAPIApplication(applicationName, uniqueApiList, tokenInfo, keyType, validityTime);
|
|
|
|
return handleNewAPIApplication(applicationName, uniqueApiList, tokenInfo, keyType,
|
|
|
|
|
|
|
|
validityTime, applicationGrantTypeUpdater, isMappingRequired);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Subscription[] subscriptions = consumerRESTAPIServices.getAllSubscriptions(tokenInfo, application.getApplicationId());
|
|
|
|
Subscription[] subscriptions = consumerRESTAPIServices.getAllSubscriptions(tokenInfo, application.getApplicationId());
|
|
|
|
for (Subscription subscription : subscriptions) {
|
|
|
|
for (Subscription subscription : subscriptions) {
|
|
|
@ -265,6 +277,14 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|
|
|
applicationKey = consumerRESTAPIServices.generateApplicationKeys(tokenInfo, application.getApplicationId(),
|
|
|
|
applicationKey = consumerRESTAPIServices.generateApplicationKeys(tokenInfo, application.getApplicationId(),
|
|
|
|
keyManager.getName(), validityTime, keyType);
|
|
|
|
keyManager.getName(), validityTime, keyType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ApplicationKey updateGrantType(TokenInfo tokenInfo, String applicationId, String keyMapId, String keyManager,
|
|
|
|
|
|
|
|
// String supportedGrantTypes, String callbackUrl)
|
|
|
|
|
|
|
|
if (applicationGrantTypeUpdater != null) {
|
|
|
|
|
|
|
|
applicationKey = consumerRESTAPIServices.updateGrantType(tokenInfo, application.getApplicationId(),
|
|
|
|
|
|
|
|
applicationKey.getKeyMappingId(), keyManager.getName(),
|
|
|
|
|
|
|
|
applicationGrantTypeUpdater.getSupportedGrantTypes(),
|
|
|
|
|
|
|
|
applicationGrantTypeUpdater.getCallbackUrl());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ApplicationKey applicationKey = consumerRESTAPIServices.mapApplicationKeys(tokenInfo, application,
|
|
|
|
// ApplicationKey applicationKey = consumerRESTAPIServices.mapApplicationKeys(tokenInfo, application,
|
|
|
@ -651,7 +671,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|
|
|
registrationProfile.getTags(), tokenType, PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
|
|
|
|
registrationProfile.getTags(), tokenType, PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
|
|
|
|
.getRealmConfiguration().getAdminUserName(),
|
|
|
|
.getRealmConfiguration().getAdminUserName(),
|
|
|
|
registrationProfile.isAllowedToAllDomains(), validityPeriod, PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
|
|
|
|
registrationProfile.isAllowedToAllDomains(), validityPeriod, PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
|
|
|
|
.getRealmConfiguration().getAdminPassword());
|
|
|
|
.getRealmConfiguration().getAdminPassword(), null, false);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|