Search in sources :

Example 71 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-apimgt by wso2.

the class DefaultScopeRegistrationImpl method getScopeInfo.

private ScopeInfo getScopeInfo(Scope scope) {
    ScopeInfo scopeInfo = new ScopeInfo();
    scopeInfo.setName(scope.getName());
    scopeInfo.setDescription(scope.getDescription());
    scopeInfo.setBindings(scope.getBindings());
    return scopeInfo;
}
Also used : ScopeInfo(org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo)

Example 72 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-apimgt by wso2.

the class WSO2ISScopeRegistrationImpl method getScopeInfo.

private ScopeInfo getScopeInfo(Scope scope) {
    ScopeInfo scopeInfo = new ScopeInfo();
    scopeInfo.setName(scope.getName());
    scopeInfo.setDisplayName(scope.getName());
    scopeInfo.setDescription(scope.getDescription());
    scopeInfo.setBindings(scope.getBindings());
    return scopeInfo;
}
Also used : ScopeInfo(org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo)

Example 73 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-apimgt by wso2.

the class DefaultScopeRegistrationImpl method registerScope.

@Override
public boolean registerScope(Scope scope) throws KeyManagementException {
    ScopeInfo scopeInfo = getScopeInfo(scope);
    Response response = scopeRegistrationServiceStub.registerScope(scopeInfo);
    if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_201_CREATED) {
        return true;
    } else {
        throw new KeyManagementException("Scope Registration Failed", ExceptionCodes.SCOPE_REGISTRATION_FAILED);
    }
}
Also used : Response(feign.Response) ScopeInfo(org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo) KeyManagementException(org.wso2.carbon.apimgt.core.exception.KeyManagementException)

Example 74 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20 method extractScopesFromJson.

/*
    *  This method extracts scopes from scoped json defined
    *
    *  @param  JSONObject scopes as a json object
    *  @return Map<String, Scope> map of scopes
    *
    * */
private Map<String, Scope> extractScopesFromJson(JSONObject scopesJson) {
    Map<String, Scope> scopeMap = new HashMap<>();
    if (scopesJson != null) {
        Iterator<?> scopesIterator = ((JSONArray) ((JSONObject) scopesJson.get(APIMgtConstants.SWAGGER_OBJECT_NAME_APIM)).get(APIMgtConstants.SWAGGER_X_WSO2_SCOPES)).iterator();
        while (scopesIterator.hasNext()) {
            Scope scope = new Gson().fromJson(((JSONObject) scopesIterator.next()).toJSONString(), Scope.class);
            scopeMap.put(scope.getName(), scope);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Unable to extract scopes from provided json as it is null.");
        }
    }
    log.debug("Scopes of extracted from Swagger: {}", scopeMap);
    return scopeMap;
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) Gson(com.google.gson.Gson)

Example 75 with Scope

use of org.wso2.ballerinalang.compiler.semantics.model.Scope in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20 method addScopeToSwaggerDefinition.

@Override
public String addScopeToSwaggerDefinition(String resourceConfigJSON, Scope scope) {
    KeyMgtConfigurations keyManagerConfigs = ServiceReferenceHolder.getInstance().getAPIMConfiguration().getKeyManagerConfigs();
    SwaggerParser swaggerParser = new SwaggerParser();
    Swagger swagger = swaggerParser.parse(resourceConfigJSON);
    Map<String, SecuritySchemeDefinition> securitySchemeDefinitionMap = swagger.getSecurityDefinitions();
    if (securitySchemeDefinitionMap != null && !securitySchemeDefinitionMap.isEmpty() && securitySchemeDefinitionMap.containsKey(APIMgtConstants.OAUTH2SECURITY)) {
        OAuth2Definition oAuth2Definition = (OAuth2Definition) securitySchemeDefinitionMap.get(APIMgtConstants.OAUTH2SECURITY);
        // Removing Scope from Swagger SecurityDefinition
        Map<String, String> scopeMap = oAuth2Definition.getScopes();
        if (scopeMap != null) {
            scopeMap.put(scope.getName(), scope.getDescription());
        }
    } else {
        OAuth2Definition oAuth2Definition = new OAuth2Definition();
        oAuth2Definition.setType("oauth2");
        oAuth2Definition.setFlow("password");
        oAuth2Definition.setTokenUrl(keyManagerConfigs.getTokenEndpoint());
        Map<String, String> scopes = new HashMap<>();
        scopes.put(scope.getName(), scope.getDescription());
        oAuth2Definition.setScopes(scopes);
        if (securitySchemeDefinitionMap != null) {
            securitySchemeDefinitionMap.put(APIMgtConstants.OAUTH2SECURITY, oAuth2Definition);
        } else {
            securitySchemeDefinitionMap = new HashMap<>();
            securitySchemeDefinitionMap.put(APIMgtConstants.OAUTH2SECURITY, oAuth2Definition);
            swagger.setSecurityDefinitions(securitySchemeDefinitionMap);
        }
    }
    return Json.pretty(swagger);
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) KeyMgtConfigurations(org.wso2.carbon.apimgt.core.configuration.models.KeyMgtConfigurations) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Swagger(io.swagger.models.Swagger) OAuth2Definition(io.swagger.models.auth.OAuth2Definition) SecuritySchemeDefinition(io.swagger.models.auth.SecuritySchemeDefinition)

Aggregations

Scope (org.wso2.carbon.apimgt.core.models.Scope)41 HashMap (java.util.HashMap)25 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)25 Test (org.testng.annotations.Test)23 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)19 Response (javax.ws.rs.core.Response)16 ScopeInfo (org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo)15 FileInputStream (java.io.FileInputStream)14 API (org.wso2.carbon.apimgt.core.models.API)14 ArrayList (java.util.ArrayList)13 KeyManager (org.wso2.carbon.apimgt.core.api.KeyManager)13 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)13 Map (java.util.Map)12 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)12 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)12 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)12 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)11 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)10