use of org.wso2.carbon.identity.application.common.model.Property in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticatorTest method testGetConfigurationProperties.
@Test
public void testGetConfigurationProperties() {
List<Property> configProperties = new ArrayList<Property>();
Property smsUrl = new Property();
configProperties.add(smsUrl);
Property httpMethod = new Property();
configProperties.add(httpMethod);
Property headers = new Property();
configProperties.add(headers);
Property payload = new Property();
configProperties.add(payload);
Property httpResponse = new Property();
configProperties.add(httpResponse);
Assert.assertEquals(configProperties.size(), smsotpAuthenticator.getConfigurationProperties().size());
}
use of org.wso2.carbon.identity.application.common.model.Property in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticator method getConfigurationProperties.
/**
* Get the configuration properties of UI
*/
@Override
public List<Property> getConfigurationProperties() {
List<Property> configProperties = new ArrayList<Property>();
Property smsUrl = new Property();
smsUrl.setName(SMSOTPConstants.SMS_URL);
smsUrl.setDisplayName("SMS URL");
smsUrl.setRequired(true);
smsUrl.setDescription("Enter client sms url value. If the phone number and text message are in URL, " + "specify them as $ctx.num and $ctx.msg");
smsUrl.setDisplayOrder(0);
configProperties.add(smsUrl);
Property httpMethod = new Property();
httpMethod.setName(SMSOTPConstants.HTTP_METHOD);
httpMethod.setDisplayName("HTTP Method");
httpMethod.setRequired(true);
httpMethod.setDescription("Enter the HTTP Method used by the SMS API");
httpMethod.setDisplayOrder(1);
configProperties.add(httpMethod);
Property headers = new Property();
headers.setName(SMSOTPConstants.HEADERS);
headers.setDisplayName("HTTP Headers");
headers.setRequired(false);
headers.setDescription("Enter the headers used by the API separated by comma, with the Header name and value " + "separated by \":\". If the phone number and text message are in Headers, specify them as $ctx.num and $ctx.msg");
headers.setDisplayOrder(2);
configProperties.add(headers);
Property payload = new Property();
payload.setName(SMSOTPConstants.PAYLOAD);
payload.setDisplayName("HTTP Payload");
payload.setRequired(false);
payload.setDescription("Enter the HTTP Payload used by the SMS API. If the phone number and text message are " + "in Payload, specify them as $ctx.num and $ctx.msg");
payload.setDisplayOrder(3);
configProperties.add(payload);
Property httpResponse = new Property();
httpResponse.setName(SMSOTPConstants.HTTP_RESPONSE);
httpResponse.setDisplayName("HTTP Response Code");
httpResponse.setRequired(false);
httpResponse.setDescription("Enter the HTTP response code the API sends upon successful call. Leave empty if unknown");
httpResponse.setDisplayOrder(4);
configProperties.add(httpResponse);
return configProperties;
}
use of org.wso2.carbon.identity.application.common.model.Property in project carbon-apimgt by wso2.
the class ApiStoreSdkGenerationManager method generateSdkForApi.
/*
* This method generates the client side SDK for the API with API ID (apiID) and SDK language (language)
*
* @param apiId ID for the specific API
* @param language preferred language to generate the SDK
* @throws ApiStoreSdkGenerationException if failed to generate the SDK
* */
public String generateSdkForApi(String apiId, String language, String userName) throws ApiStoreSdkGenerationException, APIManagementException {
APIStore apiStore = APIManagerFactory.getInstance().getAPIConsumer(userName);
API api = apiStore.getAPIbyUUID(apiId);
if (api == null) {
String errorMessage = "Cannot find API for specified API ID";
throw new APIManagementException(errorMessage, ExceptionCodes.API_NOT_FOUND);
}
String apiName = api.getName();
String apiVersion = api.getVersion();
String swaggerDefinitionForApi = null;
try {
swaggerDefinitionForApi = apiStore.getApiSwaggerDefinition(apiId);
} catch (APIManagementException e) {
handleSdkGenException("Error retrieving swagger definition for API " + apiId + " from database.", e);
}
Swagger swaggerDoc = new SwaggerParser().parse(swaggerDefinitionForApi);
if (swaggerDoc == null) {
handleSdkGenException("Error while parsing retrieved swagger definition");
}
// Format the swagger definition as a string before writing to the file.
String formattedSwaggerDefinitionForSdk = Json.pretty(swaggerDoc);
Path tempSdkGenDir = null;
File swaggerDefJsonFile = null;
try {
// Create a temporary directory to store the API files
tempSdkGenDir = Files.createTempDirectory(apiName + "_" + language + "_" + apiVersion);
// Create a temporary file to store the swagger definition
swaggerDefJsonFile = Files.createTempFile(tempSdkGenDir, apiId + "_" + language, APIMgtConstants.APIFileUtilConstants.JSON_EXTENSION).toFile();
} catch (IOException e) {
handleSdkGenException("Error creating temporary directory or json file for swagger definition!", e);
}
String tempZipFilePath = "";
if (swaggerDefJsonFile.exists()) {
try (Writer swaggerFileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(swaggerDefJsonFile.getAbsoluteFile()), "UTF-8"))) {
swaggerFileWriter.write(formattedSwaggerDefinitionForSdk);
log.debug("Writing the swagger definition was sucessful to file {}", swaggerDefJsonFile.getAbsolutePath());
} catch (IOException e) {
handleSdkGenException("Error writing swagger definition to file in " + tempSdkGenDir, e);
}
// Generate the SDK for the specified language
generateSdkForSwaggerDef(language, swaggerDefJsonFile.getAbsolutePath(), tempSdkGenDir.toString());
log.debug("Generating SDK for the swagger definition {} was successful.", swaggerDefJsonFile.getAbsolutePath());
String archiveName = apiName + "_" + language + "_" + apiVersion;
tempZipFilePath = tempSdkGenDir + File.separator + archiveName + ".zip";
APIFileUtils.archiveDirectory(tempSdkGenDir.toString(), tempSdkGenDir.toString(), archiveName);
log.debug("Generating the archive was successful for directory {}.", tempSdkGenDir.toString());
} else {
handleSdkGenException("Swagger definition file not found!");
}
try {
// Set deleteOnExit property to generated SDK directory, all sub directories and files.
recursiveDeleteOnExit(tempSdkGenDir);
} catch (IOException e) {
handleSdkGenException("Error while deleting temporary directory " + tempSdkGenDir, e);
}
return tempZipFilePath;
}
use of org.wso2.carbon.identity.application.common.model.Property in project carbon-apimgt by wso2.
the class APIStoreImpl method updateCompositeApi.
/**
* {@inheritDoc}
*/
@Override
public void updateCompositeApi(CompositeAPI.Builder apiBuilder) throws APIManagementException {
apiBuilder.provider(getUsername());
apiBuilder.updatedBy(getUsername());
CompositeAPI originalAPI = getApiDAO().getCompositeAPI(apiBuilder.getId());
apiBuilder.createdTime(originalAPI.getCreatedTime());
// workflow status is an internal property and shouldn't be allowed to update externally
apiBuilder.workflowStatus(originalAPI.getWorkflowStatus());
APIUtils.verifyValidityOfApiUpdate(apiBuilder, originalAPI);
try {
String updatedSwagger = apiDefinitionFromSwagger20.generateSwaggerFromResources(apiBuilder);
InputStream gatewayConfig = getApiDAO().getCompositeAPIGatewayConfig(apiBuilder.getId());
GatewaySourceGenerator gatewaySourceGenerator = getGatewaySourceGenerator();
APIConfigContext apiConfigContext = new APIConfigContext(apiBuilder.build(), config.getGatewayPackageName());
gatewaySourceGenerator.setApiConfigContext(apiConfigContext);
String updatedGatewayConfig = gatewaySourceGenerator.getGatewayConfigFromSwagger(IOUtils.toString(gatewayConfig, StandardCharsets.UTF_8), updatedSwagger);
CompositeAPI api = apiBuilder.build();
if (originalAPI.getContext() != null && !originalAPI.getContext().equals(apiBuilder.getContext())) {
if (isContextExist(api.getContext())) {
throw new APIManagementException("Context already Exist", ExceptionCodes.API_ALREADY_EXISTS);
}
}
// publishing config to gateway
gateway.addCompositeAPI(api);
getApiDAO().updateApiDefinition(api.getId(), updatedSwagger, api.getUpdatedBy());
getApiDAO().updateCompositeAPIGatewayConfig(api.getId(), new ByteArrayInputStream(updatedGatewayConfig.getBytes(StandardCharsets.UTF_8)), api.getUpdatedBy());
if (log.isDebugEnabled()) {
log.debug("API " + api.getName() + "-" + api.getVersion() + " was updated successfully.");
}
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while updating the API - " + apiBuilder.getName();
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
} catch (IOException e) {
String errorMsg = "Error occurred while reading gateway configuration the API - " + apiBuilder.getName();
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, ExceptionCodes.APIMGT_DAO_EXCEPTION);
}
}
use of org.wso2.carbon.identity.application.common.model.Property in project wso2-synapse by wso2.
the class EventSourceSerializer method serializeEventSource.
public static OMElement serializeEventSource(OMElement elem, SynapseEventSource eventSource) {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace nullNS = fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");
OMElement evenSourceElem = fac.createOMElement("eventSource", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
if (eventSource.getName() != null) {
evenSourceElem.addAttribute(fac.createOMAttribute("name", nullNS, eventSource.getName()));
}
if (eventSource.getSubscriptionManager() != null) {
OMElement subManagerElem = fac.createOMElement("subscriptionManager", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
subManagerElem.addAttribute(fac.createOMAttribute("class", nullNS, eventSource.getSubscriptionManager().getClass().getName()));
Collection<String> names = (Collection<String>) eventSource.getSubscriptionManager().getPropertyNames();
for (String name : names) {
String value;
if (eventSource.isContainsConfigurationProperty(name)) {
value = eventSource.getConfigurationProperty(name);
} else {
value = eventSource.getSubscriptionManager().getPropertyValue(name);
}
OMElement propElem = fac.createOMElement("property", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
propElem.addAttribute(fac.createOMAttribute("name", nullNS, name));
propElem.addAttribute(fac.createOMAttribute("value", nullNS, value));
subManagerElem.addChild(propElem);
}
evenSourceElem.addChild(subManagerElem);
// Adding static subscriptions
List<Subscription> staticSubscriptionList = eventSource.getSubscriptionManager().getStaticSubscriptions();
for (Iterator<Subscription> iterator = staticSubscriptionList.iterator(); iterator.hasNext(); ) {
Subscription staticSubscription = iterator.next();
OMElement staticSubElem = fac.createOMElement("subscription", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
staticSubElem.addAttribute(fac.createOMAttribute("id", nullNS, staticSubscription.getId()));
OMElement filterElem = fac.createOMElement("filter", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
filterElem.addAttribute(fac.createOMAttribute("source", nullNS, (String) staticSubscription.getFilterValue()));
filterElem.addAttribute(fac.createOMAttribute("dialect", nullNS, (String) staticSubscription.getFilterDialect()));
staticSubElem.addChild(filterElem);
OMElement endpointElem = fac.createOMElement("endpoint", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
OMElement addressElem = fac.createOMElement("address", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
addressElem.addAttribute(fac.createOMAttribute("uri", nullNS, staticSubscription.getEndpointUrl()));
endpointElem.addChild(addressElem);
staticSubElem.addChild(endpointElem);
if (staticSubscription.getExpires() != null) {
OMElement expiresElem = fac.createOMElement("expires", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
fac.createOMText(expiresElem, ConverterUtil.convertToString(staticSubscription.getExpires()));
staticSubElem.addChild(expiresElem);
}
evenSourceElem.addChild(staticSubElem);
}
}
if (elem != null) {
elem.addChild(evenSourceElem);
}
return evenSourceElem;
}
Aggregations