org.cloudfoundry.reactor.TokenProvider Java Examples

The following examples show how to use org.cloudfoundry.reactor.TokenProvider. 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: AbstractCfTask.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
protected CloudFoundryOperations getCfOperations() {
    CfProperties cfAppProperties = this.cfPropertiesMapper.getProperties();

    ConnectionContext connectionContext = DefaultConnectionContext.builder()
        .apiHost(cfAppProperties.ccHost())
        .skipSslValidation(true)
        .proxyConfiguration(tryGetProxyConfiguration(cfAppProperties))
        .build();

    TokenProvider tokenProvider = getTokenProvider(cfAppProperties);

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

    DefaultCloudFoundryOperations cfOperations = DefaultCloudFoundryOperations.builder()
        .cloudFoundryClient(cfClient)
        .organization(cfAppProperties.org())
        .space(cfAppProperties.space())
        .build();

    return cfOperations;
}
 
Example #3
Source File: CloudFoundryTaskPlatformFactory.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Override
public Launcher createLauncher(String account) {
	ConnectionContext connectionContext = connectionContext(account);
	TokenProvider tokenProvider = tokenProvider(account);
	CloudFoundryClient cloudFoundryClient = cloudFoundryClient(account);
	CloudFoundryOperations cloudFoundryOperations = cloudFoundryOperations(cloudFoundryClient, account);
	CloudFoundryTaskLauncher taskLauncher = new CloudFoundryTaskLauncher(
			cloudFoundryClient,
			deploymentProperties(account),
			cloudFoundryOperations,
			runtimeEnvironmentInfo(cloudFoundryClient, account));
	Launcher launcher = new Launcher(account, CLOUDFOUNDRY_PLATFORM_TYPE, taskLauncher,
			scheduler(account, taskLauncher, cloudFoundryOperations));
	CloudFoundryConnectionProperties connectionProperties = connectionProperties(account);
	launcher.setDescription(String.format("org = [%s], space = [%s], url = [%s]",
			connectionProperties.getOrg(), connectionProperties.getSpace(),
			connectionProperties.getUrl()));
	return launcher;
}
 
Example #4
Source File: CloudFoundryTestSupport.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@Bean
public CloudFoundryOperations cloudFoundryOperations(CloudFoundryClient cloudFoundryClient,
													 ConnectionContext connectionContext,
													 TokenProvider tokenProvider,
													 CloudFoundryConnectionProperties properties) {
	ReactorDopplerClient.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();

	ReactorUaaClient.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();

	return DefaultCloudFoundryOperations.builder()
		.cloudFoundryClient(cloudFoundryClient)
		.organization(properties.getOrg())
		.space(properties.getSpace())
		.build();
}
 
Example #5
Source File: OAuthClientWithLoginHint.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
@Override
public TokenProvider getTokenProvider() {
    if (tokenProvider == null) {
        tokenProvider = createTokenProvider();
    }
    return tokenProvider;
}
 
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: ResourceMetadataService.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Autowired
public ResourceMetadataService(
    WebClient webClient,
    DefaultConnectionContext connectionContext,
    TokenProvider tokenProvider,
    PasSettings settings) {
    this.webClient = webClient;
    this.connectionContext = connectionContext;
    this.tokenProvider = tokenProvider;
    this.settings = settings;
}
 
Example #8
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 #9
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 #10
Source File: CloudFoundryDeployerAutoConfiguration.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public CloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
	return ReactorCloudFoundryClient.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();
}
 
Example #11
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 #12
Source File: SpringCloudSchedulerIntegrationTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public ReactorSchedulerClient reactorSchedulerClient(ConnectionContext context,
		TokenProvider passwordGrantTokenProvider,
		CloudFoundrySchedulerProperties properties) {
	return ReactorSchedulerClient.builder()
			.connectionContext(context)
			.tokenProvider(passwordGrantTokenProvider)
			.root(Mono.just(properties.getSchedulerUrl()))
			.build();
}
 
Example #13
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 #14
Source File: CloudFoundryTestSupport.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
public CloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext,
											 TokenProvider tokenProvider) {
	return ReactorCloudFoundryClient.builder()
			.connectionContext(connectionContext)
			.tokenProvider(tokenProvider)
			.build();
}
 
Example #15
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 #16
Source File: CloudFoundryTaskPlatformFactoryTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private void setupSinglePlatform() {
	CloudFoundryProperties cloudFoundryProperties = new CloudFoundryProperties();
	cloudFoundryProperties.setDeployment(new CloudFoundryDeploymentProperties());
	cloudFoundryProperties.setConnection(this.defaultConnectionProperties);
	this.cloudFoundryPlatformProperties.setAccounts(Collections.singletonMap("default", cloudFoundryProperties));

	this.connectionContextProvider = new CloudFoundryPlatformConnectionContextProvider(this.cloudFoundryPlatformProperties);
	this.platformTokenProvider = mock(CloudFoundryPlatformTokenProvider.class);
	when(this.platformTokenProvider.tokenProvider(anyString())).thenReturn(mock(TokenProvider.class));
}
 
Example #17
Source File: CloudFoundryTaskPlatformFactoryTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private void setupMultiPlatform() throws Exception{
	this.anotherOrgSpaceConnectionProperties = new CloudFoundryConnectionProperties();
	this.anotherOrgSpaceConnectionProperties.setOrg("another-org");
	this.anotherOrgSpaceConnectionProperties.setSpace("another-space");
	this.anotherOrgSpaceConnectionProperties.setUrl(new URL("https://localhost:9999"));


	CloudFoundryProperties cloudFoundryProperties = new CloudFoundryProperties();
	CloudFoundrySchedulerProperties cloudFoundrySchedulerProperties = new CloudFoundrySchedulerProperties();
	cloudFoundrySchedulerProperties.setSchedulerUrl("https://localhost:9999");
	cloudFoundryProperties.setSchedulerProperties(cloudFoundrySchedulerProperties);
	cloudFoundryProperties.setDeployment(new CloudFoundryDeploymentProperties());
	cloudFoundryProperties.setConnection(this.defaultConnectionProperties);
	Map<String, CloudFoundryProperties> platformMap = new HashMap<>();
	platformMap.put("default", cloudFoundryProperties);
	cloudFoundryProperties = new CloudFoundryProperties();
	cloudFoundryProperties.setDeployment(new CloudFoundryDeploymentProperties());
	cloudFoundryProperties.setConnection(this.anotherOrgSpaceConnectionProperties);
	cloudFoundryProperties.setSchedulerProperties(cloudFoundrySchedulerProperties);


	platformMap.put("anotherOrgSpace", cloudFoundryProperties);

	this.cloudFoundryPlatformProperties.setAccounts(platformMap);

	this.connectionContextProvider = new CloudFoundryPlatformConnectionContextProvider(this.cloudFoundryPlatformProperties);
	this.platformTokenProvider = mock(CloudFoundryPlatformTokenProvider.class);
	when(this.platformTokenProvider.tokenProvider(anyString())).thenReturn(mock(TokenProvider.class));
}
 
Example #18
Source File: CloudFoundrySchedulerConfiguration.java    From spring-cloud-dataflow-server-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public ReactorSchedulerClient reactorSchedulerClient(ConnectionContext context,
		TokenProvider passwordGrantTokenProvider,
		CloudFoundrySchedulerProperties properties) {
	return ReactorSchedulerClient.builder()
			.connectionContext(context)
			.tokenProvider(passwordGrantTokenProvider)
			.root(Mono.just(properties.getSchedulerUrl()))
			.build();
}
 
Example #19
Source File: CloudFoundryClientAutoConfiguration.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@Lazy
@ConditionalOnMissingBean
public ReactorCloudFoundryClient cloudFoundryClient(
		ConnectionContext connectionContext, TokenProvider tokenProvider) {
	return ReactorCloudFoundryClient.builder().connectionContext(connectionContext)
			.tokenProvider(tokenProvider).build();
}
 
Example #20
Source File: CloudFoundryClientAutoConfiguration.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@Lazy
@ConditionalOnMissingBean
public DopplerClient dopplerClient(ConnectionContext connectionContext,
		TokenProvider tokenProvider) {
	return ReactorDopplerClient.builder().connectionContext(connectionContext)
			.tokenProvider(tokenProvider).build();
}
 
Example #21
Source File: CloudFoundryClientAutoConfiguration.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@Lazy
@ConditionalOnMissingBean
public RoutingClient routingClient(ConnectionContext connectionContext,
		TokenProvider tokenProvider) {
	return ReactorRoutingClient.builder().connectionContext(connectionContext)
			.tokenProvider(tokenProvider).build();
}
 
Example #22
Source File: CloudFoundryClientAutoConfiguration.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@Lazy
@ConditionalOnMissingBean
public ReactorUaaClient uaaClient(ConnectionContext connectionContext,
		TokenProvider tokenProvider) {
	return ReactorUaaClient.builder().connectionContext(connectionContext)
			.tokenProvider(tokenProvider).build();
}
 
Example #23
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 #24
Source File: UsageService.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Autowired
public UsageService(
    OrganizationService orgService,
    WebClient webClient,
    DefaultConnectionContext connectionContext,
    TokenProvider tokenProvider,
    PasSettings settings,
    UsageCache cache) {
    this.orgService = orgService;
    this.webClient = webClient;
    this.connectionContext = connectionContext;
    this.tokenProvider = tokenProvider;
    this.settings = settings;
}
 
Example #25
Source File: EventsService.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Autowired
public EventsService(
    WebClient webClient,
    DefaultConnectionContext connectionContext,
    TokenProvider tokenProvider,
    PasSettings settings) {
    this.webClient = webClient;
    this.connectionContext = connectionContext;
    this.tokenProvider = tokenProvider;
    this.settings = settings;
}
 
Example #26
Source File: ButlerConfig.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Bean
    public ReactorCloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
        return ReactorCloudFoundryClient
                .builder()
                    .connectionContext(connectionContext)
                    .tokenProvider(tokenProvider)
                    .build();
}
 
Example #27
Source File: ButlerConfig.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Bean
public ReactorDopplerClient dopplerClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
    return ReactorDopplerClient
            .builder()
                .connectionContext(connectionContext)
                .tokenProvider(tokenProvider)
                .build();
}
 
Example #28
Source File: ButlerConfig.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Bean
public ReactorUaaClient uaaClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
    return ReactorUaaClient
            .builder()
                .connectionContext(connectionContext)
                .tokenProvider(tokenProvider)
                .build();
}
 
Example #29
Source File: CloudFoundryClientConfiguration.java    From bootiful-testing-online-training with Apache License 2.0 5 votes vote down vote up
@Bean
ReactorCloudFoundryClient cloudFoundryClient(
	ConnectionContext connectionContext,
	TokenProvider tokenProvider) {
	return ReactorCloudFoundryClient
		.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider).build();
}
 
Example #30
Source File: CloudFoundryClientConfiguration.java    From bootiful-testing-online-training with Apache License 2.0 5 votes vote down vote up
@Bean
ReactorDopplerClient dopplerClient(ConnectionContext connectionContext,
																																			TokenProvider tokenProvider) {
	return ReactorDopplerClient
		.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();
}