use of org.wso2.carbon.apimgt.core.impl.APIDefinitionFromSwagger20 in project carbon-apimgt by wso2.
the class APIStoreImpl method addCompositeApiFromDefinition.
/**
* {@inheritDoc}
*/
@Override
public String addCompositeApiFromDefinition(InputStream apiDefinition) throws APIManagementException {
try {
String apiDefinitionString = IOUtils.toString(apiDefinition);
CompositeAPI.Builder apiBuilder = apiDefinitionFromSwagger20.generateCompositeApiFromSwaggerResource(getUsername(), apiDefinitionString);
apiBuilder.apiDefinition(apiDefinitionString);
addCompositeApi(apiBuilder);
return apiBuilder.getId();
} catch (IOException e) {
throw new APIManagementException("Couldn't Generate ApiDefinition from file", ExceptionCodes.API_DEFINITION_MALFORMED);
}
}
use of org.wso2.carbon.apimgt.core.impl.APIDefinitionFromSwagger20 in project carbon-apimgt by wso2.
the class AuthenticatorService method getApplicationScopes.
/**
* This method returns the scopes for a given application.
*
* @param appName Name the application
* @return scopes - A space separated list of scope keys
* @throws APIManagementException When retrieving scopes from swagger definition fails
*/
private String getApplicationScopes(String appName) throws APIManagementException {
String scopes;
String applicationRestAPI = null;
if (AuthenticatorConstants.STORE_APPLICATION.equals(appName)) {
applicationRestAPI = RestApiUtil.getStoreRestAPIResource();
} else if (AuthenticatorConstants.PUBLISHER_APPLICATION.equals(appName)) {
applicationRestAPI = RestApiUtil.getPublisherRestAPIResource();
} else if (AuthenticatorConstants.ADMIN_APPLICATION.equals(appName)) {
applicationRestAPI = RestApiUtil.getAdminRestAPIResource();
}
try {
if (applicationRestAPI != null) {
APIDefinition apiDefinitionFromSwagger20 = new APIDefinitionFromSwagger20();
Map<String, Scope> applicationScopesMap = apiDefinitionFromSwagger20.getScopesFromSecurityDefinitionForWebApps(applicationRestAPI);
scopes = String.join(" ", applicationScopesMap.keySet());
// Set openid scope
if (StringUtils.isEmpty(scopes)) {
scopes = KeyManagerConstants.OPEN_ID_CONNECT_SCOPE;
} else {
scopes = scopes + " " + KeyManagerConstants.OPEN_ID_CONNECT_SCOPE;
}
} else {
String errorMsg = "Error while getting application rest API resource.";
log.error(errorMsg, ExceptionCodes.INTERNAL_ERROR);
throw new APIManagementException(errorMsg, ExceptionCodes.INTERNAL_ERROR);
}
} catch (APIManagementException e) {
String errorMsg = "Error while reading scopes from swagger definition.";
log.error(errorMsg, e, ExceptionCodes.INTERNAL_ERROR);
throw new APIManagementException(errorMsg, e, ExceptionCodes.INTERNAL_ERROR);
}
return scopes;
}
Aggregations