Improve API key generating method

licensing-improvements
Dharmakeerthi Lasantha 1 year ago
parent ad537f3461
commit 1edaa8a2a5

@ -173,7 +173,15 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
MetadataManagementService metadataManagementService = APIApplicationManagerExtensionDataHolder.getInstance().getMetadataManagementService(); MetadataManagementService metadataManagementService = APIApplicationManagerExtensionDataHolder.getInstance().getMetadataManagementService();
if (isNewApplication) { if (isNewApplication) {
KeyManager keyManager = consumerRESTAPIServices.getAllKeyManagers(applicationInfo)[0]; KeyManager[] keyManagers = consumerRESTAPIServices.getAllKeyManagers(applicationInfo);
KeyManager keyManager;
if (keyManagers.length == 1) {
keyManager = keyManagers[0];
} else {
String msg =
"Found invalid number of key managers. No of key managers found from the APIM: " + keyManagers.length;
throw new APIManagerException(msg);
}
ApplicationKey applicationKey = consumerRESTAPIServices.generateApplicationKeys(applicationInfo, application, keyManager); ApplicationKey applicationKey = consumerRESTAPIServices.generateApplicationKeys(applicationInfo, application, keyManager);
ApiApplicationKey apiApplicationKey = new ApiApplicationKey(); ApiApplicationKey apiApplicationKey = new ApiApplicationKey();
apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey()); apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey());
@ -199,21 +207,22 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
try { try {
Metadata metaData = metadataManagementService.retrieveMetadata(applicationName); Metadata metaData = metadataManagementService.retrieveMetadata(applicationName);
if (metaData == null) { if (metaData == null) {
String msg = String msg = "Couldn't find application key data from meta data mgt service. Meta key: "
"Couldn't find application key data from meta data mgt service. Meta key: " + applicationName; + applicationName;
log.error(msg); log.error(msg);
throw new APIManagerException(msg); throw new APIManagerException(msg);
} }
String[] metaValues = metaData.getMetaValue().split(":"); String[] metaValues = metaData.getMetaValue().split(":");
if (metaValues.length != 2) { if (metaValues.length != 2) {
String msg = "Found invalid Meta value for meta key: " + applicationName; String msg = "Found invalid Meta value for meta key: " + applicationName + ". Meta Value: "
+ metaData.getMetaValue();
log.error(msg); log.error(msg);
throw new APIManagerException(msg); throw new APIManagerException(msg);
} }
String applicationId = metaValues[0]; String applicationId = metaValues[0];
String keyMappingId = metaValues[1]; String keyMappingId = metaValues[1];
ApplicationKey applicationKey = consumerRESTAPIServices.getKeyDetails(applicationInfo, applicationId, keyMappingId); ApplicationKey applicationKey = consumerRESTAPIServices.getKeyDetails(applicationInfo, applicationId, keyMappingId);
ApiApplicationKey apiApplicationKey = null; ApiApplicationKey apiApplicationKey = new ApiApplicationKey();
apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey()); apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey());
apiApplicationKey.setConsumerSecret(applicationKey.getConsumerSecret()); apiApplicationKey.setConsumerSecret(applicationKey.getConsumerSecret());
return apiApplicationKey; return apiApplicationKey;
@ -222,7 +231,6 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
log.error(msg, e); log.error(msg, e);
throw new APIManagerException(msg, e); throw new APIManagerException(msg, e);
} }
return null;
} }
} catch (APIServicesException e) { } catch (APIServicesException e) {
String msg = "Error occurred while processing the response of APIM REST endpoints."; String msg = "Error occurred while processing the response of APIM REST endpoints.";

Loading…
Cancel
Save