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;
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations