use of org.wso2.securevault.secret.SecretInformation in project wso2-synapse by wso2.
the class DataSourceInformationFactory method createDataSourceInformation.
/**
* Factory method to create a DataSourceInformation instance based on given properties
*
* @param dsName DataSource Name
* @param properties Properties to create and configure DataSource
* @return DataSourceInformation instance
*/
public static DataSourceInformation createDataSourceInformation(String dsName, Properties properties) {
if (dsName == null || "".equals(dsName)) {
if (log.isDebugEnabled()) {
log.debug("DataSource name is either empty or null, ignoring..");
}
return null;
}
StringBuffer buffer = new StringBuffer();
buffer.append(DataSourceConstants.PROP_SYNAPSE_PREFIX_DS);
buffer.append(DataSourceConstants.DOT_STRING);
buffer.append(dsName);
buffer.append(DataSourceConstants.DOT_STRING);
// Prefix for getting particular data source's properties
String prefix = buffer.toString();
String driver = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_DRIVER_CLS_NAME, null);
if (driver == null) {
handleException(prefix + DataSourceConstants.PROP_DRIVER_CLS_NAME + " cannot be found.");
}
String url = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_URL, null);
if (url == null) {
handleException(prefix + DataSourceConstants.PROP_URL + " cannot be found.");
}
DataSourceInformation datasourceInformation = new DataSourceInformation();
datasourceInformation.setAlias(dsName);
datasourceInformation.setDriver(driver);
datasourceInformation.setUrl(url);
String dataSourceName = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_DS_NAME, dsName, String.class);
datasourceInformation.setDatasourceName(dataSourceName);
String dsType = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_TYPE, DataSourceConstants.PROP_BASIC_DATA_SOURCE, String.class);
datasourceInformation.setType(dsType);
String repositoryType = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_REGISTRY, DataSourceConstants.PROP_REGISTRY_MEMORY, String.class);
datasourceInformation.setRepositoryType(repositoryType);
Integer maxActive = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_MAX_ACTIVE, GenericObjectPool.DEFAULT_MAX_ACTIVE, Integer.class);
datasourceInformation.setMaxActive(maxActive);
Integer maxIdle = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_MAX_IDLE, GenericObjectPool.DEFAULT_MAX_IDLE, Integer.class);
datasourceInformation.setMaxIdle(maxIdle);
Long maxWait = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_MAX_WAIT, GenericObjectPool.DEFAULT_MAX_WAIT, Long.class);
datasourceInformation.setMaxWait(maxWait);
// Construct DriverAdapterCPDS reference
String suffix = DataSourceConstants.PROP_CPDS_ADAPTER + DataSourceConstants.DOT_STRING + DataSourceConstants.PROP_CLASS_NAME;
String className = MiscellaneousUtil.getProperty(properties, prefix + suffix, DataSourceConstants.PROP_CPDS_ADAPTER_DRIVER);
datasourceInformation.addParameter(suffix, className);
suffix = DataSourceConstants.PROP_CPDS_ADAPTER + DataSourceConstants.DOT_STRING + DataSourceConstants.PROP_FACTORY;
String factory = MiscellaneousUtil.getProperty(properties, prefix + suffix, DataSourceConstants.PROP_CPDS_ADAPTER_DRIVER);
datasourceInformation.addParameter(suffix, factory);
suffix = DataSourceConstants.PROP_CPDS_ADAPTER + DataSourceConstants.DOT_STRING + DataSourceConstants.PROP_NAME;
String name = MiscellaneousUtil.getProperty(properties, prefix + suffix, "cpds");
datasourceInformation.addParameter(suffix, name);
boolean defaultAutoCommit = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_DEFAULT_AUTO_COMMIT, true, Boolean.class);
boolean defaultReadOnly = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_DEFAULT_READ_ONLY, false, Boolean.class);
boolean testOnBorrow = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_TEST_ON_BORROW, true, Boolean.class);
boolean testOnReturn = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_TEST_ON_RETURN, false, Boolean.class);
long timeBetweenEvictionRunsMillis = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_TIME_BETWEEN_EVICTION_RUNS_MILLIS, GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, Long.class);
int numTestsPerEvictionRun = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_NUM_TESTS_PER_EVICTION_RUN, GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, Integer.class);
long minEvictableIdleTimeMillis = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_MIN_EVICTABLE_IDLE_TIME_MILLIS, GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, Long.class);
boolean testWhileIdle = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_TEST_WHILE_IDLE, false, Boolean.class);
String validationQuery = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_VALIDATION_QUERY, null);
int minIdle = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_MIN_IDLE, GenericObjectPool.DEFAULT_MIN_IDLE, Integer.class);
int initialSize = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_INITIAL_SIZE, 0, Integer.class);
int defaultTransactionIsolation = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_DEFAULT_TRANSACTION_ISOLATION, -1, Integer.class);
String defaultCatalog = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_DEFAULT_CATALOG, null);
boolean accessToUnderlyingConnectionAllowed = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_ACCESS_TO_UNDERLYING_CONNECTION_ALLOWED, false, Boolean.class);
boolean removeAbandoned = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_REMOVE_ABANDONED, false, Boolean.class);
int removeAbandonedTimeout = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_REMOVE_ABANDONED_TIMEOUT, 300, Integer.class);
boolean logAbandoned = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_LOG_ABANDONED, false, Boolean.class);
boolean poolPreparedStatements = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_POOL_PREPARED_STATEMENTS, false, Boolean.class);
int maxOpenPreparedStatements = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_MAX_OPEN_PREPARED_STATEMENTS, GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, Integer.class);
datasourceInformation.setDefaultAutoCommit(defaultAutoCommit);
datasourceInformation.setDefaultReadOnly(defaultReadOnly);
datasourceInformation.setTestOnBorrow(testOnBorrow);
datasourceInformation.setTestOnReturn(testOnReturn);
datasourceInformation.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
datasourceInformation.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
datasourceInformation.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasourceInformation.setTestWhileIdle(testWhileIdle);
datasourceInformation.setMinIdle(minIdle);
datasourceInformation.setDefaultTransactionIsolation(defaultTransactionIsolation);
datasourceInformation.setAccessToUnderlyingConnectionAllowed(accessToUnderlyingConnectionAllowed);
datasourceInformation.setRemoveAbandoned(removeAbandoned);
datasourceInformation.setRemoveAbandonedTimeout(removeAbandonedTimeout);
datasourceInformation.setLogAbandoned(logAbandoned);
datasourceInformation.setPoolPreparedStatements(poolPreparedStatements);
datasourceInformation.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
datasourceInformation.setInitialSize(initialSize);
if (validationQuery != null && !"".equals(validationQuery)) {
datasourceInformation.setValidationQuery(validationQuery);
}
if (defaultCatalog != null && !"".equals(defaultCatalog)) {
datasourceInformation.setDefaultCatalog(defaultCatalog);
}
datasourceInformation.addProperty(prefix + DataSourceConstants.PROP_IC_FACTORY, MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_IC_FACTORY, null));
// Provider URL
datasourceInformation.addProperty(prefix + DataSourceConstants.PROP_PROVIDER_URL, MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_PROVIDER_URL, null));
datasourceInformation.addProperty(prefix + DataSourceConstants.PROP_PROVIDER_PORT, MiscellaneousUtil.getProperty(properties, prefix + DataSourceConstants.PROP_PROVIDER_PORT, null));
String passwordPrompt = MiscellaneousUtil.getProperty(properties, prefix + SecurityConstants.PROP_PASSWORD_PROMPT, "Password for datasource " + dsName, String.class);
SecretInformation secretInformation = SecretInformationFactory.createSecretInformation(properties, prefix, passwordPrompt);
secretInformation.setToken(dsName + "." + SecurityConstants.PROP_PASSWORD);
datasourceInformation.setSecretInformation(secretInformation);
return datasourceInformation;
}
use of org.wso2.securevault.secret.SecretInformation in project wso2-synapse by wso2.
the class DataSourceInformationRepository method addDataSourceInformation.
/**
* Adding a DataSourceInformation instance
*
* @param dataSourceInformation <code>DataSourceInformation</code> instance
*/
public void addDataSourceInformation(DataSourceInformation dataSourceInformation) {
if (dataSourceInformation == null) {
throw new SynapseCommonsException("DataSource information is null", log);
}
// Sets the global secret resolver
SecretInformation secretInformation = dataSourceInformation.getSecretInformation();
if (secretInformation != null) {
secretInformation.setGlobalSecretResolver(secretResolver);
}
dataSourceInformationMap.put(dataSourceInformation.getAlias(), dataSourceInformation);
if (assertListerNotNull()) {
listener.addDataSourceInformation(dataSourceInformation);
}
}
use of org.wso2.securevault.secret.SecretInformation in project wso2-synapse by wso2.
the class JDBCConfiguration method readCustomDataSourceConfig.
/**
* Configure for custom datasource
*
* @param parameters - parameters given in configuration
*/
private void readCustomDataSourceConfig(Map<String, Object> parameters) {
DataSourceInformation dataSourceInformation = new DataSourceInformation();
dataSourceInformation.setDriver((String) parameters.get(JDBCMessageStoreConstants.JDBC_CONNECTION_DRIVER));
dataSourceInformation.setUrl((String) parameters.get(JDBCMessageStoreConstants.JDBC_CONNECTION_URL));
SecretInformation secretInformation = new SecretInformation();
secretInformation.setUser((String) parameters.get(JDBCMessageStoreConstants.JDBC_USERNAME));
secretInformation.setAliasSecret((String) parameters.get(JDBCMessageStoreConstants.JDBC_PASSWORD));
dataSourceInformation.setSecretInformation(secretInformation);
this.setDataSourceInformation(dataSourceInformation);
}
use of org.wso2.securevault.secret.SecretInformation in project wso2-synapse by wso2.
the class DataSourceInformationSerializerTest method testSerializeDataSourceInformation.
/**
* Test serializing DataSourceInformation list
*/
public void testSerializeDataSourceInformation() {
List<DataSourceInformation> dataSourceInformationList = new ArrayList<>();
DataSourceInformation dataSourceInformation1 = new DataSourceInformation();
dataSourceInformation1.setDriver("org.h2.Driver");
dataSourceInformation1.setUrl("jdbc:h2:repository/database/test_db1");
dataSourceInformation1.setAlias("dataSource1");
SecretInformation secretInformation = new SecretInformation();
secretInformation.setUser("user1");
secretInformation.setAliasSecret("user1password");
dataSourceInformation1.setSecretInformation(secretInformation);
dataSourceInformationList.add(dataSourceInformation1);
DataSourceInformation dataSourceInformation2 = new DataSourceInformation();
dataSourceInformation2.setDriver("org.h2.Driver");
dataSourceInformation2.setUrl("jdbc:h2:repository/database/test_db2");
dataSourceInformation2.setAlias("dataSource2");
dataSourceInformationList.add(dataSourceInformation2);
DataSourceInformation dataSourceInformation3 = new DataSourceInformation();
dataSourceInformation3.setDriver("org.h2.Driver");
dataSourceInformation3.setUrl("jdbc:h2:repository/database/test_db3");
dataSourceInformation3.setAlias("dataSource3");
dataSourceInformationList.add(dataSourceInformation3);
Properties properties = DataSourceInformationListSerializer.serialize(dataSourceInformationList);
String dataSources = properties.getProperty("synapse.datasources");
assertTrue("'dataSource1' cannot be found in datasource list ", dataSources.contains("dataSource1"));
assertTrue("'dataSource2' cannot be found in datasource list ", dataSources.contains("dataSource2"));
assertTrue("'dataSource3' cannot be found in datasource list ", dataSources.contains("dataSource3"));
}
use of org.wso2.securevault.secret.SecretInformation 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;
}
Aggregations