Search in sources :

Example 1 with PasswordManager

use of org.apache.gobblin.password.PasswordManager in project incubator-gobblin by apache.

the class EncryptionConfigParser method getConfigForBranch.

private static Map<String, Object> getConfigForBranch(State taskState, String prefix, String branchSuffix) {
    Map<String, Object> properties = extractPropertiesForBranch(taskState.getProperties(), prefix, branchSuffix);
    if (properties.isEmpty()) {
        return null;
    }
    if (getEncryptionType(properties) == null) {
        log.warn("Encryption algorithm not specified; ignoring other encryption settings");
        return null;
    }
    PasswordManager passwordManager = PasswordManager.getInstance(taskState);
    if (properties.containsKey(ENCRYPTION_KEYSTORE_PASSWORD_KEY)) {
        properties.put(ENCRYPTION_KEYSTORE_PASSWORD_KEY, passwordManager.readPassword((String) properties.get(ENCRYPTION_KEYSTORE_PASSWORD_KEY)));
    }
    return properties;
}
Also used : PasswordManager(org.apache.gobblin.password.PasswordManager)

Example 2 with PasswordManager

use of org.apache.gobblin.password.PasswordManager in project incubator-gobblin by apache.

the class SSLContextFactory method createInstance.

/**
 * Create a {@link SSLContext} from a {@link Config}
 *
 * <p>
 *   A sample configuration is:
 *   <br> keyStoreFilePath=/path/to/key/store
 *   <br> keyStorePassword=password
 *   <br> keyStoreType=PKCS12
 *   <br> trustStoreFilePath=/path/to/trust/store
 *   <br> trustStorePassword=password
 * </p>
 *
 * @param srcConfig configuration
 * @return an instance of {@link SSLContext}
 */
public static SSLContext createInstance(Config srcConfig) {
    // srcConfig.getString() will throw ConfigException if any key is missing
    String keyStoreFilePath = srcConfig.getString(KEY_STORE_FILE_PATH);
    String trustStoreFilePath = srcConfig.getString(TRUST_STORE_FILE_PATH);
    PasswordManager passwdMgr = PasswordManager.getInstance(ConfigUtils.configToState(srcConfig));
    String keyStorePassword = passwdMgr.readPassword(srcConfig.getString(KEY_STORE_PASSWORD));
    String trustStorePassword = passwdMgr.readPassword(srcConfig.getString(TRUST_STORE_PASSWORD));
    return createInstance(new File(keyStoreFilePath), keyStorePassword, srcConfig.getString(KEY_STORE_TYPE), new File(trustStoreFilePath), trustStorePassword);
}
Also used : PasswordManager(org.apache.gobblin.password.PasswordManager) File(java.io.File)

Example 3 with PasswordManager

use of org.apache.gobblin.password.PasswordManager in project incubator-gobblin by apache.

the class SalesforceConnector method getAuthentication.

@Override
public HttpEntity getAuthentication() throws RestApiConnectionException {
    log.debug("Authenticating salesforce");
    String clientId = this.state.getProp(ConfigurationKeys.SOURCE_CONN_CLIENT_ID);
    String clientSecret = this.state.getProp(ConfigurationKeys.SOURCE_CONN_CLIENT_SECRET);
    if (this.state.getPropAsBoolean(ConfigurationKeys.SOURCE_CONN_DECRYPT_CLIENT_SECRET, false)) {
        PasswordManager passwordManager = PasswordManager.getInstance(this.state);
        clientId = passwordManager.readPassword(clientId);
        clientSecret = passwordManager.readPassword(clientSecret);
    }
    String host = this.state.getProp(ConfigurationKeys.SOURCE_CONN_HOST_NAME);
    List<NameValuePair> formParams = Lists.newArrayList();
    formParams.add(new BasicNameValuePair("client_id", clientId));
    formParams.add(new BasicNameValuePair("client_secret", clientSecret));
    if (refreshToken == null) {
        log.info("Authenticating salesforce with username/password");
        String userName = this.state.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME);
        String password = PasswordManager.getInstance(this.state).readPassword(this.state.getProp(ConfigurationKeys.SOURCE_CONN_PASSWORD));
        String securityToken = PasswordManager.getInstance(this.state).readPassword(this.state.getProp(ConfigurationKeys.SOURCE_CONN_SECURITY_TOKEN));
        formParams.add(new BasicNameValuePair("grant_type", "password"));
        formParams.add(new BasicNameValuePair("username", userName));
        formParams.add(new BasicNameValuePair("password", password + securityToken));
    } else {
        log.info("Authenticating salesforce with refresh_token");
        formParams.add(new BasicNameValuePair("grant_type", "refresh_token"));
        formParams.add(new BasicNameValuePair("refresh_token", refreshToken));
    }
    try {
        HttpPost post = new HttpPost(host + DEFAULT_AUTH_TOKEN_PATH);
        post.setEntity(new UrlEncodedFormEntity(formParams));
        HttpResponse httpResponse = getHttpClient().execute(post);
        if (httpResponse instanceof CloseableHttpResponse) {
            this.closer.register((CloseableHttpResponse) httpResponse);
        }
        return httpResponse.getEntity();
    } catch (Exception e) {
        throw new RestApiConnectionException("Failed to authenticate salesforce host:" + host + "; error-" + e.getMessage(), e);
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) PasswordManager(org.apache.gobblin.password.PasswordManager) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) RestApiConnectionException(org.apache.gobblin.source.extractor.exception.RestApiConnectionException) RestApiConnectionException(org.apache.gobblin.source.extractor.exception.RestApiConnectionException)

Example 4 with PasswordManager

use of org.apache.gobblin.password.PasswordManager in project incubator-gobblin by apache.

the class ConfigUtils method resolveEncrypted.

/**
 * Resolves encrypted config value(s) by considering on the path with "encConfigPath" as encrypted.
 * (If encConfigPath is absent or encConfigPath does not exist in config, config will be just returned untouched.)
 * It will use Password manager via given config. Thus, convention of PasswordManager need to be followed in order to be decrypted.
 * Note that "encConfigPath" path will be removed from the config key, leaving child path on the config key.
 * e.g:
 *  encConfigPath = enc.conf
 *  - Before : { enc.conf.secret_key : ENC(rOF43721f0pZqAXg#63a) }
 *  - After  : { secret_key : decrypted_val }
 *
 * @param config
 * @param encConfigPath
 * @return
 */
public static Config resolveEncrypted(Config config, Optional<String> encConfigPath) {
    if (!encConfigPath.isPresent() || !config.hasPath(encConfigPath.get())) {
        return config;
    }
    Config encryptedConfig = config.getConfig(encConfigPath.get());
    PasswordManager passwordManager = PasswordManager.getInstance(configToProperties(config));
    Map<String, String> tmpMap = Maps.newHashMapWithExpectedSize(encryptedConfig.entrySet().size());
    for (Map.Entry<String, ConfigValue> entry : encryptedConfig.entrySet()) {
        String val = entry.getValue().unwrapped().toString();
        val = passwordManager.readPassword(val);
        tmpMap.put(entry.getKey(), val);
    }
    return ConfigFactory.parseMap(tmpMap).withFallback(config);
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) Config(com.typesafe.config.Config) PasswordManager(org.apache.gobblin.password.PasswordManager) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with PasswordManager

use of org.apache.gobblin.password.PasswordManager in project incubator-gobblin by apache.

the class MysqlStateStore method newDataSource.

/**
 * creates a new {@link BasicDataSource}
 * @param config the properties used for datasource instantiation
 * @return
 */
public static BasicDataSource newDataSource(Config config) {
    BasicDataSource basicDataSource = new BasicDataSource();
    PasswordManager passwordManager = PasswordManager.getInstance(ConfigUtils.configToProperties(config));
    basicDataSource.setDriverClassName(ConfigUtils.getString(config, ConfigurationKeys.STATE_STORE_DB_JDBC_DRIVER_KEY, ConfigurationKeys.DEFAULT_STATE_STORE_DB_JDBC_DRIVER));
    // MySQL server can timeout a connection so need to validate connections before use
    basicDataSource.setValidationQuery(MysqlDataSourceUtils.QUERY_CONNECTION_IS_VALID_AND_NOT_READONLY);
    basicDataSource.setTestOnBorrow(true);
    basicDataSource.setDefaultAutoCommit(false);
    basicDataSource.setTimeBetweenEvictionRunsMillis(60000);
    basicDataSource.setUrl(config.getString(ConfigurationKeys.STATE_STORE_DB_URL_KEY));
    basicDataSource.setUsername(passwordManager.readPassword(config.getString(ConfigurationKeys.STATE_STORE_DB_USER_KEY)));
    basicDataSource.setPassword(passwordManager.readPassword(config.getString(ConfigurationKeys.STATE_STORE_DB_PASSWORD_KEY)));
    basicDataSource.setMinEvictableIdleTimeMillis(ConfigUtils.getLong(config, ConfigurationKeys.STATE_STORE_DB_CONN_MIN_EVICTABLE_IDLE_TIME_KEY, ConfigurationKeys.DEFAULT_STATE_STORE_DB_CONN_MIN_EVICTABLE_IDLE_TIME));
    return basicDataSource;
}
Also used : PasswordManager(org.apache.gobblin.password.PasswordManager) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Aggregations

PasswordManager (org.apache.gobblin.password.PasswordManager)5 ImmutableMap (com.google.common.collect.ImmutableMap)1 Config (com.typesafe.config.Config)1 ConfigValue (com.typesafe.config.ConfigValue)1 File (java.io.File)1 Map (java.util.Map)1 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)1 RestApiConnectionException (org.apache.gobblin.source.extractor.exception.RestApiConnectionException)1 HttpResponse (org.apache.http.HttpResponse)1 NameValuePair (org.apache.http.NameValuePair)1 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1