org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider Java Examples

The following examples show how to use org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider. 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: ButlerConfig.java    From cf-butler with Apache License 2.0 6 votes vote down vote up
@Bean
public TokenProvider tokenProvider(PasSettings settings) {
    if (settings.getTokenProvider().equalsIgnoreCase("userpass")) {
        return PasswordGrantTokenProvider
                .builder()
                    .username(settings.getUsername())
                    .password(settings.getPassword())
                    .build();
    } else if (settings.getTokenProvider().equalsIgnoreCase("sso")) {
        return RefreshTokenGrantTokenProvider
                .builder()
                    .token(settings.getRefreshToken())
                    .build();
    } else {
        throw new IllegalStateException("Unknown TokenProvider");
    }
}
 
Example #2
Source File: CloudFoundryClientConfiguration.java    From bootiful-testing-online-training with Apache License 2.0 5 votes vote down vote up
@Bean
public PasswordGrantTokenProvider tokenProvider(
	@Value("${cf.user}") String username, @Value("${cf.password}") String password) {
	return PasswordGrantTokenProvider
		.builder()
		.password(password)
		.username(username)
		.build();
}
 
Example #3
Source File: CloudFoundryAppDeployerAutoConfiguration.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
/**
 * Provide a {@link TokenProvider} bean
 *
 * @param properties the CloudFoundryTargetProperties bean
 * @return the bean
 */
@TokenQualifier
@Bean
public TokenProvider uaaTokenProvider(CloudFoundryTargetProperties properties) {
	boolean isClientIdAndSecretSet = Stream.of(properties.getClientId(), properties.getClientSecret())
		.allMatch(StringUtils::hasText);
	boolean isUsernameAndPasswordSet = Stream.of(properties.getUsername(), properties.getPassword())
		.allMatch(StringUtils::hasText);
	if (isClientIdAndSecretSet && isUsernameAndPasswordSet) {
		throw new IllegalStateException(
			String.format("(%1$s.client_id / %1$s.client_secret) must not be set when\n" +
				"(%1$s.username / %1$s.password) are also set", PROPERTY_PREFIX));
	}
	else if (isClientIdAndSecretSet) {
		return ClientCredentialsGrantTokenProvider.builder()
			.clientId(properties.getClientId())
			.clientSecret(properties.getClientSecret())
			.identityZoneSubdomain(properties.getIdentityZoneSubdomain())
			.build();
	}
	else if (isUsernameAndPasswordSet) {
		return PasswordGrantTokenProvider.builder()
			.password(properties.getPassword())
			.username(properties.getUsername())
			.build();
	}
	else {
		throw new IllegalStateException(
			String.format("Either (%1$s.client_id and %1$s.client_secret) or\n" +
				"(%1$s.username and %1$s.password) properties must be set", PROPERTY_PREFIX));
	}
}
 
Example #4
Source File: CloudFoundryClientConfiguration.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Bean
@Qualifier("userCredentials")
@ConditionalOnProperty({
	CloudFoundryProperties.PROPERTY_PREFIX + ".username",
	CloudFoundryProperties.PROPERTY_PREFIX + ".password"
})
protected PasswordGrantTokenProvider passwordTokenProvider(CloudFoundryProperties properties) {
	return PasswordGrantTokenProvider.builder()
		.password(properties.getPassword())
		.username(properties.getUsername())
		.build();
}
 
Example #5
Source File: PlatformCloudFoundryOperations.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
private CloudFoundryOperations buildCloudFoundryOperations(String platformName) {
	CloudFoundryPlatformProperties.CloudFoundryProperties cloudFoundryProperties = this.cloudFoundryPlatformProperties
			.getAccounts()
			.get(platformName);
	CloudFoundryConnectionProperties connectionProperties = cloudFoundryProperties.getConnection();
	ConnectionContext connectionContext = DefaultConnectionContext.builder()
			.apiHost(connectionProperties.getUrl().getHost())
			.skipSslValidation(connectionProperties.isSkipSslValidation())
			.build();
	Builder tokenProviderBuilder = PasswordGrantTokenProvider.builder()
			.username(connectionProperties.getUsername())
			.password(connectionProperties.getPassword())
			.loginHint(connectionProperties.getLoginHint());
	if (StringUtils.hasText(connectionProperties.getClientId())) {
		tokenProviderBuilder.clientId(connectionProperties.getClientId());
	}
	if (StringUtils.hasText(connectionProperties.getClientSecret())) {
		tokenProviderBuilder.clientSecret(connectionProperties.getClientSecret());
	}
	TokenProvider tokenProvider = tokenProviderBuilder.build();
	CloudFoundryClient cloudFoundryClient = ReactorCloudFoundryClient.builder()
			.connectionContext(connectionContext)
			.tokenProvider(tokenProvider)
			.build();
	return DefaultCloudFoundryOperations
			.builder().cloudFoundryClient(cloudFoundryClient)
			.organization(connectionProperties.getOrg())
			.space(connectionProperties.getSpace()).build();
}
 
Example #6
Source File: OAuthClientWithLoginHint.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private TokenProvider createTokenProvider() {
    String loginHintAsJson = JsonUtil.convertToJson(loginHintMap);
    return PasswordGrantTokenProvider.builder()
                                     .clientId(credentials.getClientId())
                                     .clientSecret(credentials.getClientSecret())
                                     .username(credentials.getEmail())
                                     .password(credentials.getPassword())
                                     .loginHint(loginHintAsJson)
                                     .build();
}
 
Example #7
Source File: AbstractCfTask.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
protected TokenProvider getTokenProvider(CfProperties cfAppProperties) {
    if (cfAppProperties.ccToken() == null &&
        (cfAppProperties.ccUser() == null && cfAppProperties.ccPassword() == null)) {
        throw new IllegalStateException("One of token or user/password should be provided");
    }

    if (cfAppProperties.ccToken() != null) {
        return new StaticTokenProvider(cfAppProperties.ccToken());
    } else {
        return PasswordGrantTokenProvider.builder()
            .password(cfAppProperties.ccPassword())
            .username(cfAppProperties.ccUser())
            .build();
    }
}
 
Example #8
Source File: PcfDevIntegrationTests.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
    public void getAppDetailTests() {
        ConnectionContext connectionContext = DefaultConnectionContext.builder()
            .apiHost("api.local.pcfdev.io")
            .skipSslValidation(true)
            .build();

        TokenProvider tokenProvider = PasswordGrantTokenProvider.builder()
            .password("admin")
            .username("admin")
            .build();

        CloudFoundryClient cfClient = ReactorCloudFoundryClient.builder()
            .connectionContext(connectionContext)
            .tokenProvider(tokenProvider)
            .build();

        CloudFoundryOperations cfOperations = DefaultCloudFoundryOperations.builder()
            .cloudFoundryClient(cfClient)
            .organization("pcfdev-org")
            .space("pcfdev-space")
            .build();

        CfAppDetailsDelegate appDetailsTaskDelegate = new CfAppDetailsDelegate();
        CfProperties cfAppProps = envDetails();
        Mono<Optional<ApplicationDetail>> applicationDetailMono = appDetailsTaskDelegate
            .getAppDetails(cfOperations, cfAppProps);


//		Mono<Void> resp = applicationDetailMono.then(applicationDetail -> Mono.fromSupplier(() -> {
//			return 1;
//		})).then();
//
//		resp.block();
//		ApplicationDetail applicationDetail = applicationDetailMono.block(Duration.ofMillis(5000));
//		System.out.println("applicationDetail = " + applicationDetail);
    }
 
Example #9
Source File: CloudFoundryDeployerAutoConfiguration.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public TokenProvider tokenProvider(CloudFoundryConnectionProperties properties) {
	Builder tokenProviderBuilder = PasswordGrantTokenProvider.builder()
			.username(properties.getUsername())
			.password(properties.getPassword())
			.loginHint(properties.getLoginHint());
	if (StringUtils.hasText(properties.getClientId())) {
		tokenProviderBuilder.clientId(properties.getClientId());
	}
	if (StringUtils.hasText(properties.getClientSecret())) {
		tokenProviderBuilder.clientSecret(properties.getClientSecret());
	}
	return tokenProviderBuilder.build();
}
 
Example #10
Source File: CloudFoundryTestSupport.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
public TokenProvider tokenProvider(CloudFoundryConnectionProperties properties) {
	return PasswordGrantTokenProvider.builder()
			.username(properties.getUsername())
			.password(properties.getPassword())
			.loginHint(properties.getLoginHint())
			.build();
}
 
Example #11
Source File: CloudFoundryPlatformTokenProvider.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
public TokenProvider tokenProvider(String account) {
	CloudFoundryConnectionProperties connectionProperties = platformProperties.accountProperties(account)
			.getConnection();
	Builder tokenProviderBuilder = PasswordGrantTokenProvider.builder()
			.username(connectionProperties.getUsername())
			.password(connectionProperties.getPassword())
			.loginHint(connectionProperties.getLoginHint());
	if (StringUtils.hasText(connectionProperties.getClientId())) {
		tokenProviderBuilder.clientId(connectionProperties.getClientId());
	}
	if (StringUtils.hasText(connectionProperties.getClientSecret())) {
		tokenProviderBuilder.clientSecret(connectionProperties.getClientSecret());
	}
	return tokenProviderBuilder.build();
}
 
Example #12
Source File: CloudFoundryClientAutoConfiguration.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@Lazy
@ConditionalOnMissingBean
public PasswordGrantTokenProvider tokenProvider() {
	String username = this.cloudFoundryProperties.getUsername();
	String password = this.cloudFoundryProperties.getPassword();
	return PasswordGrantTokenProvider.builder().password(password).username(username)
			.build();
}
 
Example #13
Source File: CloudFoundryClientAutoConfigurationTest.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private void assertCloudFoundryClientBeansPresent(
		AssertableApplicationContext context) {
	assertThat(context).hasSingleBean(ReactorCloudFoundryClient.class);
	assertThat(context).hasSingleBean(DefaultCloudFoundryOperations.class);
	assertThat(context).hasSingleBean(DefaultConnectionContext.class);
	assertThat(context).hasSingleBean(DopplerClient.class);
	assertThat(context).hasSingleBean(RoutingClient.class);
	assertThat(context).hasSingleBean(PasswordGrantTokenProvider.class);
	assertThat(context).hasSingleBean(ReactorUaaClient.class);
}
 
Example #14
Source File: CloudFoundryAppDeployerAutoConfigurationTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void clientIsCreatedWithPasswordGrantConfiguration() {
	this.contextRunner
		.withPropertyValues(
			"spring.cloud.appbroker.deployer.cloudfoundry.api-host=api.example.local",
			"spring.cloud.appbroker.deployer.cloudfoundry.api-port=443",
			"spring.cloud.appbroker.deployer.cloudfoundry.default-org=example-org",
			"spring.cloud.appbroker.deployer.cloudfoundry.default-space=example-space",
			"spring.cloud.appbroker.deployer.cloudfoundry.username=user",
			"spring.cloud.appbroker.deployer.cloudfoundry.password=secret",
			"spring.cloud.appbroker.deployer.cloudfoundry.properties.memory=2G",
			"spring.cloud.appbroker.deployer.cloudfoundry.properties.count=3",
			"spring.cloud.appbroker.deployer.cloudfoundry.properties.buildpack=example-buildpack",
			"spring.cloud.appbroker.deployer.cloudfoundry.properties.domain=example.local"
		)
		.run((context) -> {
			assertThat(context).hasSingleBean(CloudFoundryTargetProperties.class);
			CloudFoundryTargetProperties targetProperties = context.getBean(CloudFoundryTargetProperties.class);
			assertThat(targetProperties.getApiHost()).isEqualTo("api.example.local");
			assertThat(targetProperties.getApiPort()).isEqualTo(443);
			assertThat(targetProperties.getDefaultOrg()).isEqualTo("example-org");
			assertThat(targetProperties.getDefaultSpace()).isEqualTo("example-space");
			assertThat(targetProperties.getUsername()).isEqualTo("user");
			assertThat(targetProperties.getPassword()).isEqualTo("secret");

			assertThat(context).hasSingleBean(CloudFoundryDeploymentProperties.class);
			CloudFoundryDeploymentProperties deploymentProperties = context
				.getBean(CloudFoundryDeploymentProperties.class);
			assertThat(deploymentProperties.getMemory()).isEqualTo("2G");
			assertThat(deploymentProperties.getCount()).isEqualTo(3);
			assertThat(deploymentProperties.getBuildpack()).isEqualTo("example-buildpack");
			assertThat(deploymentProperties.getDomain()).isEqualTo("example.local");

			assertThat(context).hasSingleBean(AppDeployer.class);
			assertThat(context).hasSingleBean(AppManager.class);
			assertThat(context).hasSingleBean(OAuth2Client.class);

			assertThat(context).hasSingleBean(ReactorCloudFoundryClient.class);
			assertThat(context).hasSingleBean(ReactorDopplerClient.class);
			assertThat(context).hasSingleBean(ReactorUaaClient.class);
			assertThat(context).hasSingleBean(CloudFoundryOperations.class);
			assertThat(context).hasSingleBean(CloudFoundryOperationsUtils.class);
			assertThat(context).hasSingleBean(DefaultConnectionContext.class);
			assertThat(context).hasSingleBean(PasswordGrantTokenProvider.class);
		});
}
 
Example #15
Source File: ReactiveCFAccessorImpl.java    From promregator with Apache License 2.0 4 votes vote down vote up
private PasswordGrantTokenProvider tokenProvider() {
	return PasswordGrantTokenProvider.builder().password(this.password).username(this.username).build();
}
 
Example #16
Source File: CfConfiguration.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
@Bean
PasswordGrantTokenProvider tokenProvider(@Value("${cf.username}") String username,
		@Value("${cf.password}") String password) {
	return PasswordGrantTokenProvider.builder().password(password).username(username)
			.build();
}