use of io.apicurio.datamodels.asyncapi.models.AaiSecurityScheme in project carbon-apimgt by wso2.
the class APIMappingUtil method getScopesFromAsyncAPI.
private static List<ScopeDTO> getScopesFromAsyncAPI(String asyncAPIDefinition) {
Aai20Document document = (Aai20Document) Library.readDocumentFromJSONString(asyncAPIDefinition);
List<ScopeDTO> scopeDTOS = new ArrayList<>();
if (document.components == null || document.components.securitySchemes == null || document.components.securitySchemes.get("oauth2") == null) {
return scopeDTOS;
}
AaiSecurityScheme securityScheme = document.components.securitySchemes.get("oauth2");
if (securityScheme.flows == null || securityScheme.flows.implicit == null || securityScheme.flows.implicit.scopes == null) {
return scopeDTOS;
}
Map<String, String> scopes = securityScheme.flows.implicit.scopes;
Map<String, String> scopeBindings = new HashMap<>();
Extension xScopesBindings = securityScheme.flows.implicit.getExtension("x-scopes-bindings");
if (xScopesBindings != null) {
scopeBindings = (Map<String, String>) xScopesBindings.value;
}
for (Map.Entry<String, String> aScope : scopes.entrySet()) {
ScopeDTO scopeDTO = new ScopeDTO();
scopeDTO.setName(aScope.getKey());
scopeDTO.setDisplayName(aScope.getKey());
scopeDTO.setDescription(aScope.getValue());
String roles = scopeBindings.get(aScope.getKey());
if (roles == null || roles.isEmpty()) {
scopeDTO.setBindings(Collections.emptyList());
} else {
scopeDTO.setBindings(Arrays.asList((roles).split(",")));
}
scopeDTOS.add(scopeDTO);
}
return scopeDTOS;
}
Aggregations