io.pivotal.cfenv.core.CfCredentials Java Examples
The following examples show how to use
io.pivotal.cfenv.core.CfCredentials.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmqpCfEnvProcessor.java From java-cfenv with Apache License 2.0 | 6 votes |
@Override public void process(CfCredentials cfCredentials, Map<String, Object> properties) { String uri = cfCredentials.getUri(amqpSchemes); if (uri == null) { properties.put("spring.rabbitmq.host", cfCredentials.getHost()); properties.put("spring.rabbitmq.password", cfCredentials.getPassword()); properties.put("spring.rabbitmq.username", cfCredentials.getUsername()); } else { UriInfo uriInfo = new UriInfo(uri); properties.put("spring.rabbitmq.host", uriInfo.getHost()); properties.put("spring.rabbitmq.password", uriInfo.getPassword()); properties.put("spring.rabbitmq.username", cfCredentials.getUsername()); if (uriInfo.getScheme().equals("amqps")) { properties.put("spring.rabbitmq.ssl.enabled", "true"); properties.put("spring.rabbitmq.port", "5671"); } else { populateAddress(cfCredentials, properties, uri); } } if (cfCredentials.getMap().get("vhost") != null) { properties.put("spring.rabbitmq.virtualHost", cfCredentials.getMap().get("vhost")); } }
Example #2
Source File: CfSingleSignOnProcessor.java From java-cfenv with Apache License 2.0 | 6 votes |
@Override public void process(CfCredentials cfCredentials, Map<String, Object> properties) { String clientId = cfCredentials.getString("client_id"); String clientSecret = cfCredentials.getString("client_secret"); String authDomain = cfCredentials.getString("auth_domain"); String issuer = fromAuthDomain(authDomain); properties.put(SSO_SERVICE, authDomain); properties.put(SPRING_SECURITY_CLIENT + ".provider." + PROVIDER_ID + ".issuer-uri", issuer + "/oauth/token"); properties.put(SPRING_SECURITY_CLIENT + ".provider." + PROVIDER_ID + ".authorization-uri", authDomain + "/oauth/authorize"); ArrayList<String> grantTypes = (ArrayList<String>) cfCredentials.getMap().get("grant_types"); if (grantTypes != null && isAuthCodeAndClientCreds(grantTypes)) { mapBasicClientProperties(properties, AUTHCODE_CLIENT_REGISTRATION_ID, clientId, clientSecret); properties.put(SPRING_SECURITY_CLIENT + ".registration." + AUTHCODE_CLIENT_REGISTRATION_ID + ".authorization-grant-type", AUTHORIZATION_CODE); mapBasicClientProperties(properties, CLIENTCRED_CLIENT_REGISTRATION_ID, clientId, clientSecret); properties.put(SPRING_SECURITY_CLIENT + ".registration." + CLIENTCRED_CLIENT_REGISTRATION_ID + ".authorization-grant-type", CLIENT_CREDENTIALS); } else if (grantTypes != null && grantTypes.size() == 1) { // if one grant type mapBasicClientProperties(properties, BASE_CLIENT_REGISTRATION_ID, clientId, clientSecret); String grantType = grantTypes.get(0); properties.put(SPRING_SECURITY_CLIENT + ".registration." + BASE_CLIENT_REGISTRATION_ID + ".authorization-grant-type", grantType); } else { // if grant type is empty, invalid combo, or more than 2 grant types mapBasicClientProperties(properties, BASE_CLIENT_REGISTRATION_ID, clientId, clientSecret); } }
Example #3
Source File: CfSingleSignOnLegacyProcessor.java From java-cfenv with Apache License 2.0 | 6 votes |
@Override public void process(CfCredentials cfCredentials, Map<String, Object> properties) { String clientId = cfCredentials.getString("client_id"); String clientSecret = cfCredentials.getString("client_secret"); String authDomain = cfCredentials.getString("auth_domain"); properties.put("security.oauth2.client.clientId", clientId); properties.put("security.oauth2.client.clientSecret", clientSecret); properties.put("security.oauth2.client.accessTokenUri", authDomain + "/oauth/token"); properties.put("security.oauth2.client.userAuthorizationUri", authDomain + "/oauth/authorize"); properties.put("ssoServiceUrl", authDomain); properties.put("security.oauth2.resource.userInfoUri", authDomain + "/userinfo"); properties.put("security.oauth2.resource.tokenInfoUri", authDomain + "/check_token"); properties.put("security.oauth2.resource.jwk.key-set-uri", authDomain + "/token_keys"); }
Example #4
Source File: DB2JdbcTests.java From java-cfenv with Apache License 2.0 | 6 votes |
@Test public void db2ServiceCreationWithNoUri() { mockVcapServices(getServicesPayload( getUserProvidedServicePayloadWithNoUri(SERVICE_NAME, hostname, port, username, password, INSTANCE_NAME) )); CfJdbcEnv cfJdbcEnv = new CfJdbcEnv(); // Connector library returns a ServiceInfo via CloudFoundryFallbackServiceInfoCreator of type BaseServiceInfo. // In this case we would need to fall back to using the standard CfEnv APIs to access the information. assertThatThrownBy(() -> { cfJdbcEnv.findJdbcServiceByName(SERVICE_NAME); }).isInstanceOf(IllegalArgumentException.class).hasMessage( "No database service with name [db2-ups] was found."); CfCredentials cfCredentials = cfJdbcEnv.findCredentialsByName(SERVICE_NAME); assertThat(cfCredentials.getHost()).isEqualTo(hostname); }
Example #5
Source File: OracleJdbcTests.java From java-cfenv with Apache License 2.0 | 6 votes |
@Test public void oracleServiceCreationWithNoUri() { mockVcapServices(getServicesPayload( getUserProvidedServicePayloadWithNoUri(SERVICE_NAME, hostname, port, username, password, INSTANCE_NAME) )); CfJdbcEnv cfJdbcEnv = new CfJdbcEnv(); // Connector library returns a ServiceInfo via CloudFoundryFallbackServiceInfoCreator of type BaseServiceInfo. // In this case we would need to fall back to using the standard CfEnv APIs to access the information. assertThatThrownBy(() -> { cfJdbcEnv.findJdbcServiceByName(SERVICE_NAME); }).isInstanceOf(IllegalArgumentException.class).hasMessage( "No database service with name [oracle-ups] was found."); CfCredentials cfCredentials = cfJdbcEnv.findCredentialsByName(SERVICE_NAME); assertThat(cfCredentials.getHost()).isEqualTo(hostname); }
Example #6
Source File: SqlServerJdbcUrlCreator.java From java-cfenv with Apache License 2.0 | 6 votes |
@Override public String buildJdbcUrlFromUriField(CfCredentials cfCredentials) { UriInfo uriInfo = cfCredentials.getUriInfo(SQLSERVER_SCHEME); Map<String, String> uriParameters = parseSqlServerUriParameters(uriInfo.getUriString()); String databaseName = getDatabaseName(uriParameters); try { URI uri = new URI(uriInfo.getUriString().substring(0, uriInfo.getUriString().indexOf(";"))); return String.format("jdbc:%s://%s:%d%s%s%s%s", SQLSERVER_SCHEME, uri.getHost(), uri.getPort(), uri.getPath() != null && !uri.getPath().isEmpty() ? "/" + uri.getPath() : "", databaseName != null ? ";database=" + UriInfo.urlEncode(databaseName) : "", uriParameters.containsKey("user") ? ";user=" + UriInfo.urlEncode(uriParameters.get("user")) : "", uriParameters.containsKey("password") ? ";password=" + UriInfo.urlEncode(uriParameters.get("password")) : "" ); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
Example #7
Source File: GcpCloudFoundryEnvironmentPostProcessor.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static Properties retrieveCfProperties(CfEnv cfEnv, String gcpServiceName, String cfServiceName, Map<String, String> fieldsToMap) { Properties properties = new Properties(); try { List<CfService> serviceBindings = cfEnv.findServicesByLabel(cfServiceName); // If finding by label fails, attempt to find the service by tag. if (serviceBindings.isEmpty()) { serviceBindings = cfEnv.findServicesByTag(cfServiceName); } if (serviceBindings.size() != 1) { if (serviceBindings.size() > 1) { LOGGER.warn("The service " + cfServiceName + " has to be bound to a " + "Cloud Foundry application once and only once."); } return properties; } CfService cfService = serviceBindings.get(0); CfCredentials credentials = cfService.getCredentials(); String prefix = SPRING_CLOUD_GCP_PROPERTY_PREFIX + gcpServiceName + "."; fieldsToMap.forEach( (cfPropKey, gcpPropKey) -> properties.put( prefix + gcpPropKey, credentials.getMap().get(cfPropKey))); } catch (ClassCastException ex) { LOGGER.warn("Unexpected format of CF (VCAP) properties", ex); } return properties; }
Example #8
Source File: DataSourceEnvironmentExtractor.java From multiapps-controller with Apache License 2.0 | 5 votes |
private PGSimpleDataSource extractDataSource(CfCredentials databaseServiceCredentials) { PGSimpleDataSource dataSource = new PGSimpleDataSource(); dataSource.setServerName(databaseServiceCredentials.getHost()); dataSource.setUser(databaseServiceCredentials.getUsername()); dataSource.setPassword(databaseServiceCredentials.getPassword()); dataSource.setDatabaseName(databaseServiceCredentials.getString("dbname")); dataSource.setPortNumber(getPort(databaseServiceCredentials)); dataSource.setSsl(false); return dataSource; }
Example #9
Source File: AmqpCfEnvProcessor.java From java-cfenv with Apache License 2.0 | 5 votes |
public void populateAddress(CfCredentials cfCredentials, Map<String, Object> properties, String uri) { if (cfCredentials.getMap().get("uris") != null) { properties.put("spring.rabbitmq.addresses", StringUtils.collectionToCommaDelimitedString( (List<String>) cfCredentials.getMap().get("uris"))); } else if (uri != null) { properties.put("spring.rabbitmq.addresses", uri); } }
Example #10
Source File: CassandraCfEnvProcessor.java From java-cfenv with Apache License 2.0 | 5 votes |
@Override public void process(CfCredentials cfCredentials, Map<String, Object> properties) { properties.put("spring.data.cassandra.username", cfCredentials.getUsername()); properties.put("spring.data.cassandra.password", cfCredentials.getPassword()); properties.put("spring.data.cassandra.port", cfCredentials.getMap().get("cqlsh_port")); ArrayList<String> contactPoints = (ArrayList<String>) cfCredentials.getMap().get("node_ips"); properties.put("spring.data.cassandra.contact-points", StringUtils.collectionToCommaDelimitedString(contactPoints)); }
Example #11
Source File: RedisCfEnvProcessor.java From java-cfenv with Apache License 2.0 | 5 votes |
@Override public void process(CfCredentials cfCredentials, Map<String, Object> properties) { String uri = cfCredentials.getUri(redisSchemes); if (uri == null) { properties.put("spring.redis.host", cfCredentials.getHost()); properties.put("spring.redis.password", cfCredentials.getPassword()); Optional<String> tlsPort = Optional.ofNullable(cfCredentials.getString("tls_port")); if (tlsPort.isPresent()) { properties.put("spring.redis.port", tlsPort.get()); properties.put("spring.redis.ssl", "true"); } else { properties.put("spring.redis.port", cfCredentials.getPort()); } } else { UriInfo uriInfo = new UriInfo(uri); properties.put("spring.redis.host", uriInfo.getHost()); properties.put("spring.redis.port", uriInfo.getPort()); properties.put("spring.redis.password", uriInfo.getPassword()); if (uriInfo.getScheme().equals("rediss")) { properties.put("spring.redis.ssl", "true"); } } }
Example #12
Source File: CredHubCfEnvProcessor.java From java-cfenv with Apache License 2.0 | 5 votes |
@Override public void process(CfCredentials cfCredentials, Map<String, Object> properties) { Map<String, Object> allCredentials = cfCredentials.getMap(); for (Map.Entry<String, Object> entry : allCredentials.entrySet()) { properties.put(entry.getKey(), entry.getValue()); } }
Example #13
Source File: MySqlJdbcUrlCreator.java From java-cfenv with Apache License 2.0 | 5 votes |
@Override public String buildJdbcUrlFromUriField(CfCredentials cfCredentials) { UriInfo uriInfo = cfCredentials.getUriInfo(MYSQL_SCHEME); return String.format("%s%s://%s%s/%s%s%s", JDBC_PREFIX, MYSQL_SCHEME, uriInfo.getHost(), uriInfo.formatPort(), uriInfo.getPath(), uriInfo.formatUserNameAndPasswordQuery(), uriInfo.formatQuery()); }
Example #14
Source File: AbstractJdbcUrlCreator.java From java-cfenv with Apache License 2.0 | 5 votes |
@Override public String createJdbcUrl(CfService cfService) { CfCredentials cfCredentials = cfService.getCredentials(); String jdbcUrl = (String) cfCredentials.getMap().get("jdbcUrl"); if (jdbcUrl != null) { return jdbcUrl; } else { return buildJdbcUrlFromUriField(cfCredentials); } }
Example #15
Source File: AbstractJdbcUrlCreator.java From java-cfenv with Apache License 2.0 | 5 votes |
protected boolean jdbcUrlMatchesScheme(CfService cfService, String... uriSchemes) { CfCredentials cfCredentials = cfService.getCredentials(); String jdbcUrl = (String) cfCredentials.getMap().get("jdbcUrl"); if (jdbcUrl != null) { for (String uriScheme : uriSchemes) { if (jdbcUrl.startsWith(JDBC_PREFIX + uriScheme + ":")) { return true; } } } return false; }
Example #16
Source File: PostgresqlJdbcUrlCreator.java From java-cfenv with Apache License 2.0 | 5 votes |
@Override public String buildJdbcUrlFromUriField(CfCredentials cfCredentials) { UriInfo uriInfo = cfCredentials.getUriInfo(POSTGRES_JDBC_SCHEME); return String.format("%s%s://%s%s/%s%s%s", JDBC_PREFIX, POSTGRES_JDBC_SCHEME, uriInfo.getHost(), uriInfo.formatPort(), uriInfo.getPath(), uriInfo.formatUserNameAndPasswordQuery(), uriInfo.formatQuery()); }
Example #17
Source File: DB2JdbcUrlCreator.java From java-cfenv with Apache License 2.0 | 5 votes |
@Override public String buildJdbcUrlFromUriField(CfCredentials cfCredentials) { UriInfo uriInfo = cfCredentials.getUriInfo(DB2_SCHEME); return String.format("jdbc:%s://%s:%d/%s:user=%s;password=%s;", DB2_SCHEME, uriInfo.getHost(), uriInfo.getPort(), uriInfo.getPath(), UriInfo.urlEncode(uriInfo.getUsername()), UriInfo.urlEncode(uriInfo.getPassword())); }
Example #18
Source File: OracleJdbcUrlCreator.java From java-cfenv with Apache License 2.0 | 5 votes |
@Override public String buildJdbcUrlFromUriField(CfCredentials cfCredentials) { UriInfo uriInfo = cfCredentials.getUriInfo(ORACLE_SCHEME); return String.format("jdbc:%s:thin:%s/%s@%s:%d/%s", ORACLE_SCHEME, uriInfo.getUsername(), uriInfo.getPassword(), uriInfo.getHost(), uriInfo.getPort(), uriInfo.getPath()); }
Example #19
Source File: CfEurekaClientProcessor.java From java-cfenv with Apache License 2.0 | 5 votes |
@Override public void process(CfCredentials cfCredentials, Map<String, Object> properties) { String uri = cfCredentials.getUri(); String clientId = cfCredentials.getString("client_id"); String clientSecret = cfCredentials.getString("client_secret"); String accessTokenUri = cfCredentials.getString("access_token_uri"); properties.put("eureka.client.serviceUrl.defaultZone", uri + "/eureka/"); properties.put("eureka.client.region", "default"); properties.put("eureka.client.oauth2.client-id", clientId); properties.put("eureka.client.oauth2.client-secret", clientSecret); properties.put("eureka.client.oauth2.access-token-uri", accessTokenUri); }
Example #20
Source File: CfSpringCloudConfigClientProcessor.java From java-cfenv with Apache License 2.0 | 5 votes |
@Override public void process(CfCredentials cfCredentials, Map<String, Object> properties) { String uri = cfCredentials.getUri(); String clientId = cfCredentials.getString("client_id"); String clientSecret = cfCredentials.getString("client_secret"); String accessTokenUri = cfCredentials.getString("access_token_uri"); properties.put("spring.cloud.config.uri", uri); properties.put("spring.cloud.config.client.oauth2.clientId", clientId); properties.put("spring.cloud.config.client.oauth2.clientSecret", clientSecret); properties.put("spring.cloud.config.client.oauth2.accessTokenUri", accessTokenUri); }
Example #21
Source File: MongoCfEnvProcessor.java From java-cfenv with Apache License 2.0 | 4 votes |
@Override public void process(CfCredentials cfCredentials, Map<String, Object> properties) { properties.put("spring.data.mongodb.uri", cfCredentials.getUri(mongoScheme)); }
Example #22
Source File: DataSourceEnvironmentExtractor.java From multiapps-controller with Apache License 2.0 | 4 votes |
public DataSource extractDataSource(String serviceName) { LOGGER.info("Extracting datasource for service {}...", serviceName ); CfCredentials databaseServiceCredentials = extractDatabaseServiceCredentials(serviceName); return extractDataSource(databaseServiceCredentials); }
Example #23
Source File: DataSourceEnvironmentExtractor.java From multiapps-controller with Apache License 2.0 | 4 votes |
private CfCredentials extractDatabaseServiceCredentials(String serviceName) { CfEnv cfEnv = new CfEnv(); CfService sourceService = cfEnv.findServiceByName(serviceName); return sourceService.getCredentials(); }
Example #24
Source File: ButlerCfEnvProcessor.java From cf-butler with Apache License 2.0 | 4 votes |
private static void addOrUpdatePropertyValue(String propertyName, String credentialName, CfCredentials cfCredentials, Map<String, Object> properties) { Object credential = cfCredentials.getMap().get(credentialName); if (credential != null) { properties.put(propertyName, credential); } }
Example #25
Source File: DataSourceEnvironmentExtractor.java From multiapps-controller with Apache License 2.0 | 4 votes |
private int getPort(CfCredentials databaseServiceCredentials) { return Integer.valueOf(databaseServiceCredentials.getPort()); }
Example #26
Source File: ButlerCfEnvProcessor.java From cf-butler with Apache License 2.0 | 4 votes |
@Override public void process(CfCredentials cfCredentials, Map<String, Object> properties) { addPropertyValue("credhub.url", "https://credhub.service.cf.internal:8844", properties); addOrUpdatePropertyValue("spring.mail.host", "MAIL_HOST", cfCredentials, properties); addOrUpdatePropertyValue("spring.mail.host", "MAIL_PORT", cfCredentials, properties); addOrUpdatePropertyValue("spring.mail.username", "MAIL_USERNAME", cfCredentials, properties); addOrUpdatePropertyValue("spring.mail.password", "MAIL_PASSWORD", cfCredentials, properties); addOrUpdatePropertyValue("spring.mail.properties.mail.smtp.auth", "MAIL_SMTP_AUTH_ENABLED", cfCredentials, properties); addOrUpdatePropertyValue("spring.mail.properties.mail.smtp.starttls.enable", "MAIL_SMTP_STARTTLS_ENABLED", cfCredentials, properties); addOrUpdatePropertyValue("spring.sendgrid.api-key", "SENDGRID_API-KEY", cfCredentials, properties); addOrUpdatePropertyValue("spring.r2dbc.url", "R2DBC_URL", cfCredentials, properties); addOrUpdatePropertyValue("spring.r2dbc.url", "R2DBC_USERNAME", cfCredentials, properties); addOrUpdatePropertyValue("spring.r2dbc.password", "R2DBC_PASSWORD", cfCredentials, properties); addOrUpdatePropertyValue("notification.engine", "NOTIFICATION_ENGINE", cfCredentials, properties); addOrUpdatePropertyValue("cf.apiHost", "CF_API-HOST", cfCredentials, properties); addOrUpdatePropertyValue("cf.username", "CF_USERNAME", cfCredentials, properties); addOrUpdatePropertyValue("cf.password", "CF_PASSWORD", cfCredentials, properties); addOrUpdatePropertyValue("cf.sslValidationSkipped", "CF_SKIP_SSL_VALIDATION", cfCredentials, properties); addOrUpdatePropertyValue("cf.connectionPoolSize", "CF_CONNECTION_POOLSIZE", cfCredentials, properties); addOrUpdatePropertyValue("cf.connectionTimeout", "CF_CONNECTION_TIMEOUT", cfCredentials, properties); addOrUpdatePropertyValue("cf.tokenProvider", "CF_TOKEN-PROVIDER", cfCredentials, properties); addOrUpdatePropertyValue("cf.refreshToken", "CF_REFRESH-TOKEN", cfCredentials, properties); addOrUpdatePropertyValue("cf.organizationBlackList", "CF_ORGANIZATION-BLACK-LIST", cfCredentials, properties); addOrUpdatePropertyValue("cf.accountRegex", "CF_ACCOUNT-REGEX", cfCredentials, properties); addOrUpdatePropertyValue("cf.policies.git.uri", "CF_POLICIES_GIT_URI", cfCredentials, properties); addOrUpdatePropertyValue("cf.policies.git.username", "CF_POLICIES_GIT_USERNAME", cfCredentials, properties); addOrUpdatePropertyValue("cf.policies.git.password", "CF_POLICIES_GIT_PASSWORD", cfCredentials, properties); addOrUpdatePropertyValue("cf.policies.git.commit", "CF_POLICIES_GIT_COMMIT", cfCredentials, properties); addOrUpdatePropertyValue("cf.policies.git.filePaths", "CF_POLICIES_GIT_FILE-PATHS", cfCredentials, properties); addOrUpdatePropertyValue("cf.buildpacks", "CF_BUILDPACKS", cfCredentials, properties); addOrUpdatePropertyValue("om.apiHost", "OM_API-HOST", cfCredentials, properties); addOrUpdatePropertyValue("om.clientId", "OM_CLIENT-ID", cfCredentials, properties); addOrUpdatePropertyValue("om.username", "OM_USERNAME", cfCredentials, properties); addOrUpdatePropertyValue("om.password", "OM_PASSWORD", cfCredentials, properties); addOrUpdatePropertyValue("om.enabled", "OM_ENABLED", cfCredentials, properties); addOrUpdatePropertyValue("pivnet.apiToken", "PIVNET_API-TOKEN", cfCredentials, properties); addOrUpdatePropertyValue("pivnet.enabled", "PIVNET_ENABLED", cfCredentials, properties); addOrUpdatePropertyValue("cron.collection", "CRON_COLLECTION", cfCredentials, properties); addOrUpdatePropertyValue("cron.collection", "CRON_EXECUTION", cfCredentials, properties); addOrUpdatePropertyValue("management.endpoints.web.exposure.include", "EXPOSED_ACTUATOR_ENDPOINTS", cfCredentials, properties); }
Example #27
Source File: CfEnvProcessor.java From java-cfenv with Apache License 2.0 | 2 votes |
/** * Given the credentials of the single matching service, set the property values that will be used to * create the MapPropertySource. * * @param cfCredentials Credentials of the single matching service * @param properties map to set Spring Boot properties */ void process(CfCredentials cfCredentials, Map<String, Object> properties);
Example #28
Source File: AbstractJdbcUrlCreator.java From java-cfenv with Apache License 2.0 | votes |
public abstract String buildJdbcUrlFromUriField(CfCredentials cfCredentials);