use of org.wso2.securevault.secret.SecretInformation in project wso2-synapse by wso2.
the class AbstractDBMediatorFactory method readCustomDataSourceConfig.
private void readCustomDataSourceConfig(OMElement pool, AbstractDBMediator mediator) {
DataSourceInformation dataSourceInformation = new DataSourceInformation();
String driver = getKey(pool, DRIVER_Q);
if (driver != null) {
mediator.setRegistryBasedDriverConfig(true);
} else {
driver = getValue(pool, DRIVER_Q);
}
dataSourceInformation.setDriver(driver);
mediator.addDataSourceProperty(DRIVER_Q, driver);
String url = getKey(pool, URL_Q);
if (url != null) {
mediator.setRegistryBasedUrlConfig(true);
} else {
url = getValue(pool, URL_Q);
}
dataSourceInformation.setUrl(url);
mediator.addDataSourceProperty(URL_Q, url);
SecretInformation secretInformation = new SecretInformation();
String user = getKey(pool, USER_Q);
if (user != null) {
mediator.setRegistryBasedUserConfig(true);
} else {
user = getValue(pool, USER_Q);
}
secretInformation.setUser(user);
mediator.addDataSourceProperty(USER_Q, user);
String password = getKey(pool, PASS_Q);
if (password != null) {
mediator.setRegistryBasedPassConfig(true);
} else {
password = getValue(pool, PASS_Q);
}
secretInformation.setAliasSecret(password);
mediator.addDataSourceProperty(PASS_Q, password);
dataSourceInformation.setSecretInformation(secretInformation);
Iterator poolPropIter = pool.getChildrenWithName(PROP_Q);
while (poolPropIter.hasNext()) {
OMElement poolProp = (OMElement) poolPropIter.next();
readPoolProperty(mediator, dataSourceInformation, poolProp);
}
mediator.setDataSourceInformation(dataSourceInformation);
}
use of org.wso2.securevault.secret.SecretInformation in project wso2-synapse by wso2.
the class JmxSecretAuthenticatorTest method createSecretAuthenticator.
/**
* Helper method to create a @{@link JmxSecretAuthenticator}
* @return
*/
private JmxSecretAuthenticator createSecretAuthenticator() {
Properties properties = new Properties();
properties.put("synapse.jmx.username", "user1");
properties.put("synapse.jmx.password", "password1");
JmxInformation jmxInformation = JmxInformationFactory.createJmxInformation(properties, "localhost");
SecretInformation secretInformation = jmxInformation.getSecretInformation();
return new JmxSecretAuthenticator(secretInformation);
}
use of org.wso2.securevault.secret.SecretInformation in project wso2-synapse by wso2.
the class DataSourceInformationSerializer method serialize.
/**
* Serialize a DataSourceInformation to a Properties
*
* @param information DataSourceInformation instance
* @return DataSource configuration properties
*/
public static Properties serialize(DataSourceInformation information) {
final Properties properties = new Properties();
String alias = information.getAlias();
StringBuffer buffer = new StringBuffer();
buffer.append(DataSourceConstants.PROP_SYNAPSE_PREFIX_DS);
buffer.append(DataSourceConstants.DOT_STRING);
buffer.append(alias);
buffer.append(DataSourceConstants.DOT_STRING);
// Prefix for getting particular data source's properties
String prefix = buffer.toString();
addProperty(properties, prefix + DataSourceConstants.PROP_DS_NAME, information.getDatasourceName());
SecretInformation secretInformation = information.getSecretInformation();
if (secretInformation != null) {
String user = secretInformation.getUser();
if (user != null && !"".equals(user)) {
addProperty(properties, prefix + SecurityConstants.PROP_USER_NAME, user);
}
String password = secretInformation.getAliasSecret();
if (password != null && !"".equals(password)) {
addProperty(properties, prefix + SecurityConstants.PROP_PASSWORD, password);
}
}
addProperty(properties, prefix + DataSourceConstants.PROP_MAX_ACTIVE, String.valueOf(information.getMaxActive()));
addProperty(properties, prefix + DataSourceConstants.PROP_MAX_IDLE, String.valueOf(information.getMaxIdle()));
addProperty(properties, prefix + DataSourceConstants.PROP_MAX_WAIT, String.valueOf(information.getMaxWait()));
addProperty(properties, prefix + DataSourceConstants.PROP_DRIVER_CLS_NAME, String.valueOf(information.getDriver()));
addProperty(properties, prefix + DataSourceConstants.PROP_URL, String.valueOf(information.getUrl()));
addProperty(properties, prefix + DataSourceConstants.PROP_TYPE, String.valueOf(information.getType()));
addProperty(properties, prefix + DataSourceConstants.PROP_DEFAULT_AUTO_COMMIT, String.valueOf(information.isDefaultAutoCommit()));
addProperty(properties, prefix + DataSourceConstants.PROP_DEFAULT_READ_ONLY, String.valueOf(information.isDefaultReadOnly()));
addProperty(properties, prefix + DataSourceConstants.PROP_TEST_ON_BORROW, String.valueOf(information.isTestOnBorrow()));
addProperty(properties, prefix + DataSourceConstants.PROP_TEST_ON_RETURN, String.valueOf(information.isTestOnReturn()));
addProperty(properties, prefix + DataSourceConstants.PROP_MIN_IDLE, String.valueOf(information.getMinIdle()));
addProperty(properties, prefix + DataSourceConstants.PROP_INITIAL_SIZE, String.valueOf(information.getInitialSize()));
addProperty(properties, prefix + DataSourceConstants.PROP_DEFAULT_TRANSACTION_ISOLATION, String.valueOf(information.getDefaultTransactionIsolation()));
String defaultCatalog = information.getDefaultCatalog();
if (defaultCatalog != null && !"".equals(defaultCatalog)) {
addProperty(properties, prefix + DataSourceConstants.PROP_DEFAULT_CATALOG, String.valueOf(defaultCatalog));
}
addProperty(properties, prefix + DataSourceConstants.PROP_ACCESS_TO_UNDERLYING_CONNECTION_ALLOWED, String.valueOf(information.isAccessToUnderlyingConnectionAllowed()));
addProperty(properties, prefix + DataSourceConstants.PROP_REMOVE_ABANDONED, String.valueOf(information.isRemoveAbandoned()));
addProperty(properties, prefix + DataSourceConstants.PROP_REMOVE_ABANDONED_TIMEOUT, String.valueOf(information.getRemoveAbandonedTimeout()));
addProperty(properties, prefix + DataSourceConstants.PROP_LOG_ABANDONED, String.valueOf(information.isLogAbandoned()));
addProperty(properties, prefix + DataSourceConstants.PROP_POOL_PREPARED_STATEMENTS, String.valueOf(information.isPoolPreparedStatements()));
addProperty(properties, prefix + DataSourceConstants.PROP_MAX_OPEN_PREPARED_STATEMENTS, String.valueOf(information.getMaxOpenPreparedStatements()));
addProperty(properties, prefix + DataSourceConstants.PROP_REGISTRY, String.valueOf(information.getRepositoryType()));
addProperty(properties, prefix + DataSourceConstants.PROP_TIME_BETWEEN_EVICTION_RUNS_MILLIS, String.valueOf(information.getTimeBetweenEvictionRunsMillis()));
addProperty(properties, prefix + DataSourceConstants.PROP_NUM_TESTS_PER_EVICTION_RUN, String.valueOf(information.getNumTestsPerEvictionRun()));
addProperty(properties, prefix + DataSourceConstants.PROP_MIN_EVICTABLE_IDLE_TIME_MILLIS, String.valueOf(information.getMinEvictableIdleTimeMillis()));
addProperty(properties, prefix + DataSourceConstants.PROP_TEST_WHILE_IDLE, String.valueOf(information.isTestWhileIdle()));
String validationQ = information.getValidationQuery();
if (validationQ != null && !"".equals(validationQ)) {
addProperty(properties, prefix + DataSourceConstants.PROP_VALIDATION_QUERY, String.valueOf(validationQ));
}
properties.putAll(information.getAllParameters());
properties.putAll(information.getProperties());
return properties;
}
use of org.wso2.securevault.secret.SecretInformation in project wso2-synapse by wso2.
the class JmxInformationFactory method createJmxInformation.
/**
* Factory method to create a JmxInformation instance based on given properties
*
* @param properties Properties to create and configure DataSource
* @param defaultHostName the default host name tobe used in case of a the host name is not set
* @return DataSourceInformation instance
*/
public static JmxInformation createJmxInformation(Properties properties, String defaultHostName) {
// Prefix for getting particular JMX properties
String prefix = JmxConfigurationConstants.PROP_SYNAPSE_PREFIX_JMX;
JmxInformation jmxInformation = new JmxInformation();
SecretInformation secretInformation = SecretInformationFactory.createSecretInformation(properties, prefix, null);
secretInformation.setToken(JmxConfigurationConstants.JMX_PROTECTED_TOKEN);
jmxInformation.setSecretInformation(secretInformation);
int jndiPort = MiscellaneousUtil.getProperty(properties, prefix + JmxConfigurationConstants.PROP_JNDI_PORT, -1, Integer.class);
jmxInformation.setJndiPort(jndiPort);
int rmiPort = MiscellaneousUtil.getProperty(properties, prefix + JmxConfigurationConstants.PROP_RMI_PORT, 0, Integer.class);
jmxInformation.setRmiPort(rmiPort);
String jmxHostName = MiscellaneousUtil.getProperty(properties, prefix + JmxConfigurationConstants.PROP_HOSTNAME, null);
if (jmxHostName == null || jmxHostName.trim().length() == 0) {
jmxHostName = defaultHostName;
}
jmxInformation.setHostName(jmxHostName);
// begin of special JMX security options
Properties managementProperties = readManagementProperties();
Boolean authenticate;
String value = getConfigProperty(managementProperties, "com.sun.management.jmxremote.authenticate");
if (value != null) {
authenticate = Boolean.valueOf(value);
} else {
if (secretInformation.getUser() == null) {
authenticate = Boolean.FALSE;
} else {
authenticate = Boolean.TRUE;
}
}
jmxInformation.setAuthenticate(authenticate);
value = getConfigProperty(managementProperties, "com.sun.management.jmxremote.access.file");
if (value == null || value.trim().length() == 0) {
value = MiscellaneousUtil.getProperty(properties, prefix + JmxConfigurationConstants.PROP_REMOTE_ACCESS_FILE, null);
}
if (value != null && value.trim().length() > 0) {
jmxInformation.setRemoteAccessFile(value);
}
value = getConfigProperty(managementProperties, "com.sun.management.jmxremote.password.file");
if (value != null && value.trim().length() > 0) {
jmxInformation.setRemotePasswordFile(value);
}
Boolean remoteSSL;
value = getConfigProperty(managementProperties, "com.sun.management.jmxremote.ssl");
if (value != null) {
remoteSSL = Boolean.valueOf(value);
} else {
remoteSSL = MiscellaneousUtil.getProperty(properties, prefix + JmxConfigurationConstants.PROP_REMOTE_SSL, Boolean.FALSE, Boolean.class);
}
jmxInformation.setRemoteSSL(remoteSSL);
return jmxInformation;
}
Aggregations