use of org.wso2.securevault.SecretResolver in project carbon-business-process by wso2.
the class HumanTaskServerConfiguration method getAuthenticationConfig.
private void getAuthenticationConfig(File file, TRegServiceAuth authentication) {
// Since secretResolver only accept Element we have to build Element here.
SecretResolver secretResolver = null;
InputStream in = null;
try {
in = new FileInputStream(file);
StAXOMBuilder builder = new StAXOMBuilder(in);
secretResolver = SecretResolverFactory.create(builder.getDocumentElement(), true);
} catch (Exception e) {
log.warn("Error occurred while retrieving secured TaskEngineProtocolHandler configuration.", e);
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
log.error(e.getLocalizedMessage(), e);
}
}
// Get Username
if (secretResolver != null && secretResolver.isInitialized() && secretResolver.isTokenProtected(HumanTaskConstants.B4P_REGISTRATIONS_USERNAME_ALIAS)) {
this.registrationServiceAuthUsername = secretResolver.resolve(HumanTaskConstants.B4P_REGISTRATIONS_USERNAME_ALIAS);
if (log.isDebugEnabled()) {
log.debug("Loaded Registration service admin username from secure vault");
}
} else {
if (authentication.getUsername() != null) {
this.registrationServiceAuthUsername = authentication.getUsername();
}
}
// Get Password
if (secretResolver != null && secretResolver.isInitialized() && secretResolver.isTokenProtected(HumanTaskConstants.B4P_REGISTRATIONS_PASSWORD_ALIAS)) {
this.registrationServiceAuthPassword = secretResolver.resolve(HumanTaskConstants.B4P_REGISTRATIONS_PASSWORD_ALIAS);
if (log.isDebugEnabled()) {
log.debug("Loaded Registration service admin password from secure vault");
}
} else {
if (authentication.getPassword() != null) {
this.registrationServiceAuthPassword = authentication.getPassword();
}
}
}
use of org.wso2.securevault.SecretResolver in project carbon-business-process by wso2.
the class CoordinationConfiguration method getAuthenticationConfig.
/**
* Get protocol handler admin username and password from secure vault. If secure vault not set then
* parse authentication configuration and extract protocol handler admin username and password
*
* @param file
* @param authentication
*/
private void getAuthenticationConfig(File file, TTaskAuthenticationConfig authentication) {
// Since secretResolver only accept Element we have to build Element here.
SecretResolver secretResolver = null;
InputStream in = null;
try {
in = new FileInputStream(file);
StAXOMBuilder builder = new StAXOMBuilder(in);
secretResolver = SecretResolverFactory.create(builder.getDocumentElement(), true);
} catch (Exception e) {
log.warn("Error occurred while retrieving secured TaskEngineProtocolHandler configuration.", e);
} finally {
try {
in.close();
} catch (IOException e) {
log.error(e.getLocalizedMessage(), e);
}
}
// Get Username
if (secretResolver != null && secretResolver.isInitialized() && secretResolver.isTokenProtected(PROTOCOL_HANDLER_USERNAME_ALIAS)) {
protocolHandlerAdminUser = secretResolver.resolve(PROTOCOL_HANDLER_USERNAME_ALIAS);
if (log.isDebugEnabled()) {
log.debug("Loaded TaskEngine's protocol handler username from secure vault");
}
} else {
if (authentication.getUsername() != null) {
this.protocolHandlerAdminUser = authentication.getUsername();
}
}
// Get Password
if (secretResolver != null && secretResolver.isInitialized() && secretResolver.isTokenProtected(PROTOCOL_HANDLER_PASSWORD_ALIAS)) {
protocolHandlerAdminPassword = secretResolver.resolve(PROTOCOL_HANDLER_PASSWORD_ALIAS);
if (log.isDebugEnabled()) {
log.debug("Loaded TaskEngine's protocol handler password from secure vault");
}
} else {
if (authentication.getPassword() != null) {
this.protocolHandlerAdminPassword = authentication.getPassword();
}
}
}
use of org.wso2.securevault.SecretResolver in project carbon-apimgt by wso2.
the class APIManagerConfiguration method setThrottleProperties.
/**
* set the Advance Throttle Properties into Configuration
*
* @param element
*/
private void setThrottleProperties(OMElement element) {
OMElement throttleConfigurationElement = element.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.THROTTLING_CONFIGURATIONS));
if (throttleConfigurationElement != null) {
// Check unlimited tier enabled
OMElement enableUnlimitedTierElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLE_UNLIMITED_TIER));
if (enableUnlimitedTierElement != null) {
throttleProperties.setEnableUnlimitedTier(JavaUtils.isTrueExplicitly(enableUnlimitedTierElement.getText()));
}
// Check header condition enable
OMElement enableHeaderConditionsElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLE_HEADER_CONDITIONS));
if (enableHeaderConditionsElement != null) {
throttleProperties.setEnableHeaderConditions(JavaUtils.isTrueExplicitly(enableHeaderConditionsElement.getText()));
}
// Check JWT condition enable
OMElement enableJwtElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLE_JWT_CLAIM_CONDITIONS));
if (enableJwtElement != null) {
throttleProperties.setEnableJwtConditions(JavaUtils.isTrueExplicitly(enableJwtElement.getText()));
}
// Check query param condition enable
OMElement enableQueryParamElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLE_QUERY_PARAM_CONDITIONS));
if (enableQueryParamElement != null) {
throttleProperties.setEnableQueryParamConditions(JavaUtils.isTrueExplicitly(enableQueryParamElement.getText()));
}
// Check skip redeploy throttle policies
OMElement skipRedeployingPoliciesElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.SKIP_REDEPLOYING_POLICIES));
if (skipRedeployingPoliciesElement != null) {
throttleProperties.setSkipRedeployingPolicies(skipRedeployingPoliciesElement.getText().split(APIConstants.DELEM_COMMA));
}
OMElement enablePolicyDeployElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLE_POLICY_DEPLOYMENT));
if (enablePolicyDeployElement != null) {
throttleProperties.setEnablePolicyDeployment(Boolean.parseBoolean(enablePolicyDeployElement.getText()));
}
// Check subscription spike arrest enable
OMElement enabledSubscriptionLevelSpikeArrestElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLE_SUBSCRIPTION_SPIKE_ARREST));
if (enabledSubscriptionLevelSpikeArrestElement != null) {
throttleProperties.setEnabledSubscriptionLevelSpikeArrest(JavaUtils.isTrueExplicitly(enabledSubscriptionLevelSpikeArrestElement.getText()));
}
// Reading TrafficManager configuration
OMElement trafficManagerConfigurationElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.TRAFFIC_MANAGER));
ThrottleProperties.TrafficManager trafficManager = new ThrottleProperties.TrafficManager();
if (trafficManagerConfigurationElement != null) {
OMElement receiverUrlGroupElement = trafficManagerConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURAION_REVEIVER_URL_GROUP));
if (receiverUrlGroupElement != null) {
trafficManager.setReceiverUrlGroup(APIUtil.replaceSystemProperty(receiverUrlGroupElement.getText()));
}
OMElement authUrlGroupElement = trafficManagerConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURAION_AUTH_URL_GROUP));
if (authUrlGroupElement != null) {
trafficManager.setAuthUrlGroup(APIUtil.replaceSystemProperty(authUrlGroupElement.getText()));
}
OMElement dataPublisherUsernameElement = trafficManagerConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.USERNAME));
if (dataPublisherUsernameElement != null) {
trafficManager.setUsername(APIUtil.replaceSystemProperty(dataPublisherUsernameElement.getText()));
}
OMElement dataPublisherTypeElement = trafficManagerConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURAION_TYPE));
if (dataPublisherTypeElement != null) {
trafficManager.setType(dataPublisherTypeElement.getText());
}
String dataPublisherConfigurationPassword;
OMElement dataPublisherConfigurationPasswordOmElement = trafficManagerConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.PASSWORD));
dataPublisherConfigurationPassword = MiscellaneousUtil.resolve(dataPublisherConfigurationPasswordOmElement, secretResolver);
trafficManager.setPassword(APIUtil.replaceSystemProperty(dataPublisherConfigurationPassword));
throttleProperties.setTrafficManager(trafficManager);
}
// Configuring throttle data publisher
ThrottleProperties.DataPublisher dataPublisher = new ThrottleProperties.DataPublisher();
OMElement dataPublisherConfigurationElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURATION));
if (dataPublisherConfigurationElement != null) {
OMElement dataPublisherEnabledElement = dataPublisherConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLED));
dataPublisher.setEnabled(JavaUtils.isTrueExplicitly(dataPublisherEnabledElement.getText()));
dataPublisher.setAuthUrlGroup(trafficManager.getAuthUrlGroup());
dataPublisher.setReceiverUrlGroup(trafficManager.getReceiverUrlGroup());
dataPublisher.setUsername(trafficManager.getUsername());
dataPublisher.setPassword(trafficManager.getPassword());
dataPublisher.setType(trafficManager.getType());
}
if (dataPublisher.isEnabled()) {
throttleProperties.setDataPublisher(dataPublisher);
// Data publisher pool configuration
OMElement dataPublisherPoolConfigurationElement = dataPublisherConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_POOL_CONFIGURATION));
ThrottleProperties.DataPublisherPool dataPublisherPool = new ThrottleProperties.DataPublisherPool();
OMElement maxIdleElement = dataPublisherPoolConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_POOL_CONFIGURAION_MAX_IDLE));
if (maxIdleElement != null) {
dataPublisherPool.setMaxIdle(Integer.parseInt(maxIdleElement.getText()));
}
OMElement initIdleElement = dataPublisherPoolConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_POOL_CONFIGURAION_INIT_IDLE));
if (initIdleElement != null) {
dataPublisherPool.setInitIdleCapacity(Integer.parseInt(initIdleElement.getText()));
}
throttleProperties.setDataPublisherPool(dataPublisherPool);
// Data publisher thread pool configuration
OMElement dataPublisherThreadPoolConfigurationElement = dataPublisherConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_THREAD_POOL_CONFIGURATION));
ThrottleProperties.DataPublisherThreadPool dataPublisherThreadPool = new ThrottleProperties.DataPublisherThreadPool();
if (dataPublisherThreadPoolConfigurationElement != null) {
OMElement corePoolSizeElement = dataPublisherThreadPoolConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_THREAD_POOL_CONFIGURATION_CORE_POOL_SIZE));
if (corePoolSizeElement != null) {
dataPublisherThreadPool.setCorePoolSize(Integer.parseInt(corePoolSizeElement.getText()));
}
OMElement maximumPoolSizeElement = dataPublisherThreadPoolConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_THREAD_POOL_CONFIGURATION_MAXMIMUM_POOL_SIZE));
if (maximumPoolSizeElement != null) {
dataPublisherThreadPool.setMaximumPoolSize(Integer.parseInt(maximumPoolSizeElement.getText()));
}
OMElement keepAliveTimeElement = dataPublisherThreadPoolConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_THREAD_POOL_CONFIGURATION_KEEP_ALIVE_TIME));
if (keepAliveTimeElement != null) {
dataPublisherThreadPool.setKeepAliveTime(Long.parseLong(keepAliveTimeElement.getText()));
}
}
throttleProperties.setDataPublisherThreadPool(dataPublisherThreadPool);
}
// Configuring JMSConnectionDetails
ThrottleProperties.JMSConnectionProperties jmsConnectionProperties = new ThrottleProperties.JMSConnectionProperties();
OMElement jmsConnectionDetailElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.JMS_CONNECTION_DETAILS));
if (jmsConnectionDetailElement != null) {
OMElement jmsConnectionEnabledElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLED));
jmsConnectionProperties.setEnabled(JavaUtils.isTrueExplicitly(jmsConnectionEnabledElement.getText()));
OMElement jmsConnectionUrlElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.SERVICE_URL));
if (jmsConnectionUrlElement != null) {
jmsConnectionProperties.setServiceUrl(APIUtil.replaceSystemProperty(jmsConnectionUrlElement.getText()));
System.setProperty("jms.url", jmsConnectionProperties.getServiceUrl());
}
OMElement jmsConnectionUserElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.USERNAME));
if (jmsConnectionUserElement != null) {
jmsConnectionProperties.setUsername(APIUtil.replaceSystemProperty(jmsConnectionUserElement.getText()));
System.setProperty("jms.username", jmsConnectionProperties.getUsername());
}
OMElement jmsConnectionPasswordElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.PASSWORD));
if (jmsConnectionPasswordElement != null) {
OMElement jmsConnectionPasswordOmElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.PASSWORD));
String jmsConnectionPassword = MiscellaneousUtil.resolve(jmsConnectionPasswordOmElement, secretResolver);
jmsConnectionProperties.setPassword(APIUtil.replaceSystemProperty(jmsConnectionPassword));
System.setProperty("jms.password", jmsConnectionProperties.getPassword());
}
OMElement jmsConnectionParameterElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.JMS_CONNECTION_PARAMETERS));
if (jmsConnectionParameterElement != null) {
Iterator jmsProperties = jmsConnectionParameterElement.getChildElements();
Properties properties = new Properties();
while (jmsProperties.hasNext()) {
OMElement property = (OMElement) jmsProperties.next();
String value = MiscellaneousUtil.resolve(property, secretResolver);
properties.put(property.getLocalName(), APIUtil.replaceSystemProperty(value));
}
jmsConnectionProperties.setJmsConnectionProperties(properties);
}
// Configuring JMS Task Manager
ThrottleProperties.JMSConnectionProperties.JMSTaskManagerProperties jmsTaskManagerProperties = new ThrottleProperties.JMSConnectionProperties.JMSTaskManagerProperties();
OMElement jmsTaskManagerElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.JMS_TASK_MANAGER));
if (jmsTaskManagerElement != null) {
OMElement minThreadPoolSizeElement = jmsTaskManagerElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.MIN_THREAD_POOL_SIZE));
if (minThreadPoolSizeElement != null) {
jmsTaskManagerProperties.setMinThreadPoolSize(Integer.parseInt(minThreadPoolSizeElement.getText()));
}
OMElement maxThreadPoolSizeElement = jmsTaskManagerElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.MAX_THREAD_POOL_SIZE));
if (maxThreadPoolSizeElement != null) {
jmsTaskManagerProperties.setMaxThreadPoolSize(Integer.parseInt(maxThreadPoolSizeElement.getText()));
}
OMElement keepAliveTimeInMillisElement = jmsTaskManagerElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.KEEP_ALIVE_TIME_IN_MILLIS));
if (keepAliveTimeInMillisElement != null) {
jmsTaskManagerProperties.setKeepAliveTimeInMillis(Integer.parseInt(keepAliveTimeInMillisElement.getText()));
}
OMElement jobQueueSizeElement = jmsTaskManagerElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.JOB_QUEUE_SIZE));
if (keepAliveTimeInMillisElement != null) {
jmsTaskManagerProperties.setJobQueueSize(Integer.parseInt(jobQueueSizeElement.getText()));
}
}
jmsConnectionProperties.setJmsTaskManagerProperties(jmsTaskManagerProperties);
OMElement jmsConnectionInitialDelayElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.BLOCK_CONDITION_RETRIEVER_INIT_DELAY));
if (jmsConnectionInitialDelayElement != null) {
jmsConnectionProperties.setInitialDelay(Long.parseLong(jmsConnectionInitialDelayElement.getText()));
}
}
throttleProperties.setJmsConnectionProperties(jmsConnectionProperties);
// Configuring default tier limits
Map<String, Long> defaultThrottleTierLimits = new HashMap<String, Long>();
OMElement defaultTierLimits = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DEFAULT_THROTTLE_LIMITS));
if (defaultTierLimits != null) {
OMElement subscriptionPolicyLimits = defaultTierLimits.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.SUBSCRIPTION_THROTTLE_LIMITS));
if (subscriptionPolicyLimits != null) {
OMElement goldTierElement = subscriptionPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_SUB_POLICY_GOLD));
if (goldTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_SUB_POLICY_GOLD, Long.parseLong(goldTierElement.getText()));
}
OMElement silverTierElement = subscriptionPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_SUB_POLICY_SILVER));
if (silverTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_SUB_POLICY_SILVER, Long.parseLong(silverTierElement.getText()));
}
OMElement bronzeTierElement = subscriptionPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_SUB_POLICY_BRONZE));
if (bronzeTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_SUB_POLICY_BRONZE, Long.parseLong(bronzeTierElement.getText()));
}
OMElement unauthenticatedTierElement = subscriptionPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_SUB_POLICY_UNAUTHENTICATED));
if (unauthenticatedTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_SUB_POLICY_UNAUTHENTICATED, Long.parseLong(unauthenticatedTierElement.getText()));
}
}
OMElement applicationPolicyLimits = defaultTierLimits.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.APPLICATION_THROTTLE_LIMITS));
if (subscriptionPolicyLimits != null) {
OMElement largeTierElement = applicationPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_APP_POLICY_FIFTY_REQ_PER_MIN));
if (largeTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_APP_POLICY_FIFTY_REQ_PER_MIN, Long.parseLong(largeTierElement.getText()));
}
OMElement mediumTierElement = applicationPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_APP_POLICY_TWENTY_REQ_PER_MIN));
if (mediumTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_APP_POLICY_TWENTY_REQ_PER_MIN, Long.parseLong(mediumTierElement.getText()));
}
OMElement smallTierElement = applicationPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_APP_POLICY_TEN_REQ_PER_MIN));
if (smallTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_APP_POLICY_TEN_REQ_PER_MIN, Long.parseLong(smallTierElement.getText()));
}
}
OMElement resourceLevelPolicyLimits = defaultTierLimits.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.RESOURCE_THROTTLE_LIMITS));
if (resourceLevelPolicyLimits != null) {
OMElement ultimateTierElement = resourceLevelPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_API_POLICY_FIFTY_THOUSAND_REQ_PER_MIN));
if (ultimateTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_API_POLICY_FIFTY_THOUSAND_REQ_PER_MIN, Long.parseLong(ultimateTierElement.getText()));
}
OMElement plusTierElement = resourceLevelPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_API_POLICY_TWENTY_THOUSAND_REQ_PER_MIN));
if (plusTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_API_POLICY_TWENTY_THOUSAND_REQ_PER_MIN, Long.parseLong(plusTierElement.getText()));
}
OMElement basicTierElement = resourceLevelPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_API_POLICY_TEN_THOUSAND_REQ_PER_MIN));
if (basicTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_API_POLICY_TEN_THOUSAND_REQ_PER_MIN, Long.parseLong(basicTierElement.getText()));
}
}
}
throttleProperties.setDefaultThrottleTierLimits(defaultThrottleTierLimits);
// Configuring policy deployer
OMElement policyDeployerConnectionElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.POLICY_DEPLOYER_CONFIGURATION));
ThrottleProperties.PolicyDeployer policyDeployerConfiguration = new ThrottleProperties.PolicyDeployer();
if (policyDeployerConnectionElement != null) {
OMElement policyDeployerConnectionEnabledElement = policyDeployerConnectionElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLED));
policyDeployerConfiguration.setEnabled(JavaUtils.isTrueExplicitly(policyDeployerConnectionEnabledElement.getText()));
OMElement policyDeployerServiceUrlElement = policyDeployerConnectionElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.SERVICE_URL));
if (policyDeployerServiceUrlElement != null) {
policyDeployerConfiguration.setServiceUrl(APIUtil.replaceSystemProperty(policyDeployerServiceUrlElement.getText()));
}
OMElement policyDeployerServiceServiceUsernameElement = policyDeployerConnectionElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.USERNAME));
if (policyDeployerServiceServiceUsernameElement != null) {
policyDeployerConfiguration.setUsername(APIUtil.replaceSystemProperty(policyDeployerServiceServiceUsernameElement.getText()));
}
OMElement policyDeployerServicePasswordElement = policyDeployerConnectionElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.PASSWORD));
String policyDeployerServicePassword = MiscellaneousUtil.resolve(policyDeployerServicePasswordElement, secretResolver);
policyDeployerConfiguration.setPassword(APIUtil.replaceSystemProperty(policyDeployerServicePassword));
}
throttleProperties.setPolicyDeployer(policyDeployerConfiguration);
// Configuring Block Condition retriever configuration
OMElement blockConditionRetrieverElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.BLOCK_CONDITION_RETRIEVER_CONFIGURATION));
ThrottleProperties.BlockCondition blockConditionRetrieverConfiguration = new ThrottleProperties.BlockCondition();
if (blockConditionRetrieverElement != null) {
OMElement blockingConditionEnabledElement = blockConditionRetrieverElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLED));
blockConditionRetrieverConfiguration.setEnabled(JavaUtils.isTrueExplicitly(blockingConditionEnabledElement.getText()));
OMElement blockConditionRetrieverServiceUrlElement = blockConditionRetrieverElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.SERVICE_URL));
if (blockConditionRetrieverServiceUrlElement != null) {
blockConditionRetrieverConfiguration.setServiceUrl(APIUtil.replaceSystemProperty(blockConditionRetrieverServiceUrlElement.getText()));
} else {
String serviceUrl = "https://" + System.getProperty(APIConstants.KEYMANAGER_HOSTNAME) + ":" + System.getProperty(APIConstants.KEYMANAGER_PORT) + APIConstants.INTERNAL_WEB_APP_EP;
blockConditionRetrieverConfiguration.setServiceUrl(serviceUrl);
}
blockConditionRetrieverConfiguration.setUsername(getFirstProperty(APIConstants.API_KEY_VALIDATOR_USERNAME));
OMElement blockConditionRetrieverThreadPoolSizeElement = blockConditionRetrieverElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.MAX_THREAD_POOL_SIZE));
if (blockConditionRetrieverThreadPoolSizeElement != null) {
blockConditionRetrieverConfiguration.setCorePoolSize(Integer.parseInt(blockConditionRetrieverThreadPoolSizeElement.getText()));
}
OMElement blockConditionRetrieverInitIdleElement = blockConditionRetrieverElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.BLOCK_CONDITION_RETRIEVER_INIT_DELAY));
if (blockConditionRetrieverInitIdleElement != null) {
blockConditionRetrieverConfiguration.setInitDelay(Long.parseLong(blockConditionRetrieverInitIdleElement.getText()));
}
OMElement blockConditionRetrieverTimeIntervalElement = blockConditionRetrieverElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.BLOCK_CONDITION_RETRIEVER_PERIOD));
if (blockConditionRetrieverTimeIntervalElement != null) {
blockConditionRetrieverConfiguration.setPeriod(Long.parseLong(blockConditionRetrieverTimeIntervalElement.getText()));
}
blockConditionRetrieverConfiguration.setPassword(getFirstProperty(APIConstants.API_KEY_VALIDATOR_PASSWORD));
}
throttleProperties.setBlockCondition(blockConditionRetrieverConfiguration);
}
}
use of org.wso2.securevault.SecretResolver in project carbon-apimgt by wso2.
the class APIManagerConfiguration method setEventHubConfiguration.
private void setEventHubConfiguration(OMElement omElement) {
EventHubConfigurationDto eventHubConfigurationDto = new EventHubConfigurationDto();
OMElement enableElement = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.ENABLE));
if (enableElement != null && Boolean.parseBoolean(enableElement.getText())) {
eventHubConfigurationDto.setEnabled(true);
OMElement serviceUrlElement = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.SERVICE_URL));
if (serviceUrlElement != null) {
String serviceUrl = APIUtil.replaceSystemProperty(serviceUrlElement.getText());
if (StringUtils.isNotEmpty(serviceUrl)) {
serviceUrl = serviceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0];
eventHubConfigurationDto.setServiceUrl(serviceUrl);
}
}
OMElement initDelay = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.INIT_DELAY));
if (initDelay != null) {
eventHubConfigurationDto.setInitDelay(Integer.parseInt(initDelay.getText()));
}
OMElement usernameElement = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.USERNAME));
if (usernameElement != null) {
eventHubConfigurationDto.setUsername(usernameElement.getText());
}
OMElement passwordElement = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.PASSWORD));
if (passwordElement != null) {
String password = MiscellaneousUtil.resolve(passwordElement, secretResolver);
eventHubConfigurationDto.setPassword(APIUtil.replaceSystemProperty(password).toCharArray());
}
OMElement configurationRetrieverElement = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.EVENT_RECEIVER_CONFIGURATION));
if (configurationRetrieverElement != null) {
EventHubConfigurationDto.EventHubReceiverConfiguration eventHubReceiverConfiguration = new EventHubConfigurationDto.EventHubReceiverConfiguration();
Iterator receiverConnectionDetailsElements = configurationRetrieverElement.getChildElements();
Properties properties = new Properties();
while (receiverConnectionDetailsElements.hasNext()) {
OMElement element = (OMElement) receiverConnectionDetailsElements.next();
String value = MiscellaneousUtil.resolve(element, secretResolver);
properties.put(element.getLocalName(), APIUtil.replaceSystemProperty(value));
}
eventHubReceiverConfiguration.setJmsConnectionParameters(properties);
eventHubConfigurationDto.setEventHubReceiverConfiguration(eventHubReceiverConfiguration);
}
OMElement eventPublisherElement = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.EVENT_PUBLISHER_CONFIGURATIONS));
EventHubConfigurationDto.EventHubPublisherConfiguration eventHubPublisherConfiguration = new EventHubConfigurationDto.EventHubPublisherConfiguration();
if (eventPublisherElement != null) {
OMElement receiverUrlGroupElement = eventPublisherElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURAION_REVEIVER_URL_GROUP));
if (receiverUrlGroupElement != null) {
eventHubPublisherConfiguration.setReceiverUrlGroup(APIUtil.replaceSystemProperty(receiverUrlGroupElement.getText()));
}
OMElement authUrlGroupElement = eventPublisherElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURAION_AUTH_URL_GROUP));
if (authUrlGroupElement != null) {
eventHubPublisherConfiguration.setAuthUrlGroup(APIUtil.replaceSystemProperty(authUrlGroupElement.getText()));
}
OMElement eventTypeElement = eventPublisherElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURAION_TYPE));
if (eventTypeElement != null) {
eventHubPublisherConfiguration.setType(eventTypeElement.getText().trim());
}
Map<String, String> publisherProps = extractPublisherProperties(eventPublisherElement);
if (publisherProps != null) {
eventHubPublisherConfiguration.setProperties(publisherProps);
}
eventHubConfigurationDto.setEventHubPublisherConfiguration(eventHubPublisherConfiguration);
}
}
this.eventHubConfigurationDto = eventHubConfigurationDto;
}
use of org.wso2.securevault.SecretResolver in project carbon-apimgt by wso2.
the class APIManagerConfiguration method load.
/**
* Populate this configuration by reading an XML file at the given location. This method
* can be executed only once on a given APIManagerConfiguration instance. Once invoked and
* successfully populated, it will ignore all subsequent invocations.
*
* @param filePath Path of the XML descriptor file
* @throws APIManagementException If an error occurs while reading the XML descriptor
*/
public void load(String filePath) throws APIManagementException {
if (initialized) {
return;
}
InputStream in = null;
int offset = APIUtil.getPortOffset();
int receiverPort = 9611 + offset;
int authUrlPort = 9711 + offset;
int jmsPort = 5672 + offset;
System.setProperty(RECEIVER_URL_PORT, "" + receiverPort);
System.setProperty(AUTH_URL_PORT, "" + authUrlPort);
System.setProperty(JMS_PORT, "" + jmsPort);
try {
in = FileUtils.openInputStream(new File(filePath));
StAXOMBuilder builder = new StAXOMBuilder(in);
secretResolver = SecretResolverFactory.create(builder.getDocumentElement(), true);
readChildElements(builder.getDocumentElement(), new Stack<String>());
initialized = true;
String url = getFirstProperty(APIConstants.API_KEY_VALIDATOR_URL);
if (url == null) {
log.error("API_KEY_VALIDATOR_URL is null");
}
} catch (IOException e) {
log.error(e.getMessage());
throw new APIManagementException("I/O error while reading the API manager " + "configuration: " + filePath, e);
} catch (XMLStreamException e) {
log.error(e.getMessage());
throw new APIManagementException("Error while parsing the API manager " + "configuration: " + filePath, e);
} catch (OMException e) {
log.error(e.getMessage());
throw new APIManagementException("Error while parsing API Manager configuration: " + filePath, e);
} catch (Exception e) {
log.error(e.getMessage());
throw new APIManagementException("Unexpected error occurred while parsing configuration: " + filePath, e);
} finally {
IOUtils.closeQuietly(in);
}
}
Aggregations