Search in sources :

Example 1 with AaiSecurityScheme

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;
}
Also used : Extension(io.apicurio.datamodels.core.models.Extension) AaiSecurityScheme(io.apicurio.datamodels.asyncapi.models.AaiSecurityScheme) HashMap(java.util.HashMap) ScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO) APIScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO) Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

AaiSecurityScheme (io.apicurio.datamodels.asyncapi.models.AaiSecurityScheme)1 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)1 Extension (io.apicurio.datamodels.core.models.Extension)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 APIScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO)1 ScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO)1