use of io.apicurio.datamodels.core.models.Extension in project carbon-apimgt by wso2.
the class AsyncApiParser method updateAsyncAPIDefinition.
public String updateAsyncAPIDefinition(String oldDefinition, API apiToUpdate) {
Aai20Document document = (Aai20Document) Library.readDocumentFromJSONString(oldDefinition);
if (document.components == null) {
document.components = document.createComponents();
}
// add scopes
if (document.components.securitySchemes == null) {
document.components.securitySchemes = new HashMap<>();
}
Aai20SecurityScheme oauth2SecurityScheme = new Aai20SecurityScheme(document.components, APIConstants.DEFAULT_API_SECURITY_OAUTH2);
oauth2SecurityScheme.type = APIConstants.DEFAULT_API_SECURITY_OAUTH2;
if (oauth2SecurityScheme.flows == null) {
oauth2SecurityScheme.flows = new Aai20OAuthFlows(oauth2SecurityScheme);
}
if (oauth2SecurityScheme.flows.implicit == null) {
oauth2SecurityScheme.flows.implicit = new Aai20ImplicitOAuthFlow(oauth2SecurityScheme.flows);
}
oauth2SecurityScheme.flows.implicit.authorizationUrl = "http://localhost:9999";
Map<String, String> scopes = new HashMap<>();
Map<String, String> scopeBindings = new HashMap<>();
Iterator<Scope> iterator = apiToUpdate.getScopes().iterator();
while (iterator.hasNext()) {
Scope scope = iterator.next();
scopes.put(scope.getName(), scope.getDescription());
scopeBindings.put(scope.getName(), scope.getRoles());
}
oauth2SecurityScheme.flows.implicit.scopes = scopes;
Extension xScopeBindings = oauth2SecurityScheme.flows.implicit.createExtension();
xScopeBindings.name = APIConstants.SWAGGER_X_SCOPES_BINDINGS;
xScopeBindings.value = scopeBindings;
oauth2SecurityScheme.flows.implicit.addExtension(APIConstants.SWAGGER_X_SCOPES_BINDINGS, xScopeBindings);
document.components.securitySchemes.put(APIConstants.DEFAULT_API_SECURITY_OAUTH2, oauth2SecurityScheme);
return Library.writeDocumentToJSONString(document);
}
use of io.apicurio.datamodels.core.models.Extension in project carbon-apimgt by wso2.
the class AsyncApiParser method buildURITemplate.
private URITemplate buildURITemplate(String target, String verb, Aai20Operation operation, Set<Scope> scopes, Aai20ChannelItem channel) throws APIManagementException {
URITemplate template = new URITemplate();
template.setHTTPVerb(verb);
template.setHttpVerbs(verb);
template.setUriTemplate(target);
Extension authTypeExtension = channel.getExtension(APIConstants.SWAGGER_X_AUTH_TYPE);
if (authTypeExtension != null && authTypeExtension.value instanceof String) {
template.setAuthType(authTypeExtension.value.toString());
}
List<String> opScopes = getScopeOfOperations(operation);
if (!opScopes.isEmpty()) {
if (opScopes.size() == 1) {
String firstScope = opScopes.get(0);
Scope scope = APIUtil.findScopeByKey(scopes, firstScope);
if (scope == null) {
throw new APIManagementException("Scope '" + firstScope + "' not found.");
}
template.setScope(scope);
template.setScopes(scope);
} else {
for (String scopeName : opScopes) {
Scope scope = APIUtil.findScopeByKey(scopes, scopeName);
if (scope == null) {
throw new APIManagementException("Resource Scope '" + scopeName + "' not found.");
}
template.setScopes(scope);
}
}
}
return template;
}
use of io.apicurio.datamodels.core.models.Extension in project carbon-apimgt by wso2.
the class SolaceApiParser method getVendorFromExtension.
/**
* This method will extract the vendor provider or the API specification form the extensions list
*
* @param definition String
* @return String
*/
@Override
public String getVendorFromExtension(String definition) {
Aai20Document aai20Document = (Aai20Document) Library.readDocumentFromJSONString(definition);
Extension origin = aai20Document.info.getExtension("x-origin");
if (origin != null) {
ObjectMapper objectMapper = new ObjectMapper();
Map originMap = objectMapper.convertValue(origin.value, Map.class);
if (originMap.containsKey("vendor")) {
if (SolaceConstants.SOLACE_ENVIRONMENT.equalsIgnoreCase(originMap.get("vendor").toString())) {
return SolaceConstants.SOLACE_ENVIRONMENT;
}
}
}
return null;
}
use of io.apicurio.datamodels.core.models.Extension in project carbon-apimgt by wso2.
the class AsyncApiParser method getScopes.
@Override
public Set<Scope> getScopes(String resourceConfigsJSON) throws APIManagementException {
Set<Scope> scopeSet = new LinkedHashSet<>();
Aai20Document document = (Aai20Document) Library.readDocumentFromJSONString(resourceConfigsJSON);
if (document.components != null && document.components.securitySchemes != null) {
Aai20SecurityScheme oauth2 = (Aai20SecurityScheme) document.components.securitySchemes.get("oauth2");
if (oauth2 != null && oauth2.flows != null && oauth2.flows.implicit != null) {
Map<String, String> scopes = oauth2.flows.implicit.scopes;
Extension xScopesBindings = oauth2.flows.implicit.getExtension(APIConstants.SWAGGER_X_SCOPES_BINDINGS);
Map<String, String> scopeBindings = new HashMap<>();
if (xScopesBindings != null) {
scopeBindings = (Map<String, String>) xScopesBindings.value;
}
if (scopes != null) {
for (Map.Entry<String, String> entry : scopes.entrySet()) {
Scope scope = new Scope();
scope.setKey(entry.getKey());
scope.setName(entry.getKey());
scope.setDescription(entry.getValue());
String scopeBinding = scopeBindings.get(scope.getKey());
if (scopeBinding != null) {
scope.setRoles(scopeBinding);
}
scopeSet.add(scope);
}
}
}
}
return scopeSet;
}
use of io.apicurio.datamodels.core.models.Extension in project carbon-apimgt by wso2.
the class AsyncApiParser method buildWSUriMapping.
public Map<String, String> buildWSUriMapping(String apiDefinition) {
Map<String, String> wsUriMapping = new HashMap<>();
Aai20Document document = (Aai20Document) Library.readDocumentFromJSONString(apiDefinition);
for (Map.Entry<String, AaiChannelItem> entry : document.channels.entrySet()) {
AaiOperation publishOperation = entry.getValue().publish;
if (publishOperation != null) {
Extension xUriMapping = publishOperation.getExtension("x-uri-mapping");
if (xUriMapping != null) {
wsUriMapping.put("PUBLISH_" + entry.getKey(), xUriMapping.value.toString());
}
}
AaiOperation subscribeOperation = entry.getValue().subscribe;
if (subscribeOperation != null) {
Extension xUriMapping = subscribeOperation.getExtension("x-uri-mapping");
if (xUriMapping != null) {
wsUriMapping.put("SUBSCRIBE_" + entry.getKey(), xUriMapping.value.toString());
}
}
}
return wsUriMapping;
}
Aggregations