use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdSwaggerGet.
/**
* Retrieves the swagger document of an API
*
* @param apiId API identifier
* @param environmentName name of the gateway environment
* @param ifNoneMatch If-None-Match header value
* @param xWSO2Tenant requested tenant domain for cross tenant invocations
* @param messageContext CXF message context
* @return Swagger document of the API for the given cluster or gateway environment
*/
@Override
public Response apisApiIdSwaggerGet(String apiId, String environmentName, String ifNoneMatch, String xWSO2Tenant, MessageContext messageContext) {
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
API api = apiConsumer.getLightweightAPIByUUID(apiId, organization);
if (api.getUuid() == null) {
api.setUuid(apiId);
}
if (api.getSwaggerDefinition() != null) {
api.setSwaggerDefinition(APIUtil.removeXMediationScriptsFromSwagger(api.getSwaggerDefinition()));
} else {
api.setSwaggerDefinition(apiConsumer.getOpenAPIDefinition(apiId, organization));
}
// gets the first available environment if environment is not provided
if (StringUtils.isEmpty(environmentName)) {
Map<String, Environment> existingEnvironments = APIUtil.getEnvironments(organization);
// then the old gateway environment name becomes invalid
for (String environmentNameOfApi : api.getEnvironments()) {
if (existingEnvironments.get(environmentNameOfApi) != null) {
environmentName = environmentNameOfApi;
break;
}
}
// if all environment of API are invalid or there are no environments (i.e. empty)
if (StringUtils.isEmpty(environmentName)) {
// This is to make sure the swagger doesn't have invalid endpoints
if (!existingEnvironments.keySet().isEmpty()) {
environmentName = existingEnvironments.keySet().iterator().next();
}
}
}
String apiSwagger = null;
if (StringUtils.isNotEmpty(environmentName)) {
try {
apiSwagger = apiConsumer.getOpenAPIDefinitionForEnvironment(api, environmentName);
} catch (APIManagementException e) {
// handle gateway not found exception otherwise pass it
if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError("Gateway environment '" + environmentName + "' not found", e, log);
return null;
}
throw e;
}
} else {
apiSwagger = api.getSwaggerDefinition();
}
return Response.ok().entity(apiSwagger).header("Content-Disposition", "attachment; filename=\"" + "swagger.json" + "\"").build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_API, apiId, e, log);
} else if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else {
String errorMessage = "Error while retrieving swagger of API : " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.Environment in project wso2-synapse by wso2.
the class JmxAdapter method createContextMap.
/**
* Creates an environment context map containing the configuration used to start the
* server connector.
*
* @return an environment context map containing the configuration used to start the server
* connector
*/
private Map<String, Object> createContextMap() {
Map<String, Object> env = new HashMap<String, Object>();
if (jmxInformation.isAuthenticate()) {
if (jmxInformation.getRemotePasswordFile() != null) {
env.put("jmx.remote.x.password.file", jmxInformation.getRemotePasswordFile());
} else {
SecretInformation secretInformation = jmxInformation.getSecretInformation();
// Get the global secret resolver
// TODO This should be properly implemented if JMX adapter is going to use out side synapse
PasswordManager pwManager = PasswordManager.getInstance();
if (pwManager.isInitialized()) {
secretInformation.setGlobalSecretResolver(pwManager.getSecretResolver());
}
env.put(JMXConnectorServer.AUTHENTICATOR, new JmxSecretAuthenticator(jmxInformation.getSecretInformation()));
}
if (jmxInformation.getRemoteAccessFile() != null) {
env.put("jmx.remote.x.access.file", jmxInformation.getRemoteAccessFile());
}
} else {
log.warn("Using unsecured JMX remote access!");
}
if (jmxInformation.isRemoteSSL()) {
log.info("Activated SSL communication");
env.put("jmx.remote.rmi.client.socket.factory", new SslRMIClientSocketFactory());
env.put("jmx.remote.rmi.server.socket.factory", new SslRMIServerSocketFactory());
}
return env;
}
use of org.wso2.carbon.apimgt.api.model.Environment in project airavata by apache.
the class Wso2IdentityServerClient method getAdminServiceClient.
public static RemoteUserStoreManagerServiceStub getAdminServiceClient(String adminUserName, String adminPassword, String adminService) {
/**
* trust store path. this must contains server's certificate or Server's CA chain
*/
/* The below code snippet is intentionally commented for the build to pass,
* because the private key and certificate file are not committed to GitHub,
* which are needed to run the client */
// String trustStore = System.getProperty("user.dir") + File.separator +
// "modules" + File.separator + "user-profile-migration" + File.separator +
// "src" + File.separator + "main" + File.separator +
// "resources" + File.separator + "wso2carbon.jks";
// System.out.println("file path : " + trustStore);
/**
* Call to https://localhost:9443/services/ uses HTTPS protocol.
* Therefore we to validate the server certificate or CA chain. The server certificate is looked up in the
* trust store.
* Following code sets what trust-store to look for and its JKs password.
*/
// System.setProperty("javax.net.ssl.trustStore", trustStore );
// System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
// idp.scigap.org:9443 certificate has expired, so the following disables checking the certificate
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
} };
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
SSLContext.setDefault(sc);
} catch (KeyManagementException e) {
throw new RuntimeException(e);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
/**
* Axis2 configuration context
*/
ConfigurationContext configContext;
RemoteUserStoreManagerServiceStub adminStub;
try {
/**
* Create a configuration context. A configuration context contains information for
* axis2 environment. This is needed to create an axis2 service client
*/
configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
/**
* end point url with service name
*/
// String serviceEndPoint = SEVER_URL + "RemoteUserStoreManagerService";
String serviceEndPoint = SEVER_URL + adminService;
/**
* create stub and service client
*/
adminStub = new RemoteUserStoreManagerServiceStub(configContext, serviceEndPoint);
ServiceClient client = adminStub._getServiceClient();
Options option = client.getOptions();
/**
* Setting a authenticated cookie that is received from Carbon server.
* If you have authenticated with Carbon server earlier, you can use that cookie, if
* it has not been expired
*/
option.setProperty(HTTPConstants.COOKIE_STRING, null);
/**
* Setting basic auth headers for authentication for carbon server
*/
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setUsername(adminUserName);
auth.setPassword(adminPassword);
auth.setPreemptiveAuthentication(true);
option.setProperty(HTTPConstants.AUTHENTICATE, auth);
option.setManageSession(true);
return adminStub;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.Environment in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
@Override
public void visit(BLangForkJoin forkJoin) {
SymbolEnv forkJoinEnv = SymbolEnv.createFolkJoinEnv(forkJoin, this.env);
forkJoin.workers.forEach(e -> this.symbolEnter.defineNode(e, forkJoinEnv));
forkJoin.workers.forEach(e -> this.analyzeDef(e, forkJoinEnv));
if (!this.isJoinResultType(forkJoin.joinResultVar)) {
this.dlog.error(forkJoin.joinResultVar.pos, DiagnosticCode.INVALID_WORKER_JOIN_RESULT_TYPE);
}
/* create code black and environment for join result section, i.e. (map results) */
BLangBlockStmt joinResultsBlock = this.generateCodeBlock(this.createVarDef(forkJoin.joinResultVar));
SymbolEnv joinResultsEnv = SymbolEnv.createBlockEnv(joinResultsBlock, this.env);
this.analyzeNode(joinResultsBlock, joinResultsEnv);
/* create an environment for the join body, making the enclosing environment the earlier
* join result's environment */
SymbolEnv joinBodyEnv = SymbolEnv.createBlockEnv(forkJoin.joinedBody, joinResultsEnv);
this.analyzeNode(forkJoin.joinedBody, joinBodyEnv);
if (forkJoin.timeoutExpression != null) {
if (!this.isJoinResultType(forkJoin.timeoutVariable)) {
this.dlog.error(forkJoin.timeoutVariable.pos, DiagnosticCode.INVALID_WORKER_TIMEOUT_RESULT_TYPE);
}
/* create code black and environment for timeout section */
BLangBlockStmt timeoutVarBlock = this.generateCodeBlock(this.createVarDef(forkJoin.timeoutVariable));
SymbolEnv timeoutVarEnv = SymbolEnv.createBlockEnv(timeoutVarBlock, this.env);
this.typeChecker.checkExpr(forkJoin.timeoutExpression, timeoutVarEnv, Arrays.asList(symTable.intType));
this.analyzeNode(timeoutVarBlock, timeoutVarEnv);
/* create an environment for the timeout body, making the enclosing environment the earlier
* timeout var's environment */
SymbolEnv timeoutBodyEnv = SymbolEnv.createBlockEnv(forkJoin.timeoutBody, timeoutVarEnv);
this.analyzeNode(forkJoin.timeoutBody, timeoutBodyEnv);
}
this.validateJoinWorkerList(forkJoin, forkJoinEnv);
}
use of org.wso2.carbon.apimgt.api.model.Environment in project ballerina by ballerina-lang.
the class CodeGenerator method visitXMLTagName.
/**
* Visit XML tag name and return the index of the tag name in the reference registry.
*
* @param tagName Tag name expression
* @param xmlElementEnv Environment of the XML element of the tag
* @param xmlElementLiteral XML element literal to which the tag name belongs to
* @return Index of the tag name, in the reference registry
*/
private RegIndex visitXMLTagName(BLangExpression tagName, SymbolEnv xmlElementEnv, BLangXMLElementLiteral xmlElementLiteral) {
genNode(tagName, xmlElementEnv);
RegIndex startTagNameRegIndex = tagName.regIndex;
// If this is a string representation of element name, generate the namespace lookup instructions
if (tagName.getKind() != NodeKind.XML_QNAME) {
RegIndex localNameRegIndex = getRegIndex(TypeTags.STRING);
RegIndex uriRegIndex = getRegIndex(TypeTags.STRING);
emit(InstructionCodes.S2QNAME, startTagNameRegIndex, localNameRegIndex, uriRegIndex);
startTagNameRegIndex = getRegIndex(TypeTags.XML);
generateURILookupInstructions(xmlElementLiteral.namespacesInScope, localNameRegIndex, uriRegIndex, startTagNameRegIndex, xmlElementLiteral.pos, xmlElementEnv);
tagName.regIndex = startTagNameRegIndex;
}
return startTagNameRegIndex;
}
Aggregations