Java源码示例:org.cloudfoundry.reactor.TokenProvider

示例1
@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");
    }
}
 
示例2
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;
}
 
示例3
@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();
}
 
示例4
@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;
}
 
示例5
@Autowired
public ResourceMetadataService(
    WebClient webClient,
    DefaultConnectionContext connectionContext,
    TokenProvider tokenProvider,
    PasSettings settings) {
    this.webClient = webClient;
    this.connectionContext = connectionContext;
    this.tokenProvider = tokenProvider;
    this.settings = settings;
}
 
示例6
@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;
}
 
示例7
@Autowired
public EventsService(
    WebClient webClient,
    DefaultConnectionContext connectionContext,
    TokenProvider tokenProvider,
    PasSettings settings) {
    this.webClient = webClient;
    this.connectionContext = connectionContext;
    this.tokenProvider = tokenProvider;
    this.settings = settings;
}
 
示例8
@Bean
    public ReactorCloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
        return ReactorCloudFoundryClient
                .builder()
                    .connectionContext(connectionContext)
                    .tokenProvider(tokenProvider)
                    .build();
}
 
示例9
@Bean
public ReactorDopplerClient dopplerClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
    return ReactorDopplerClient
            .builder()
                .connectionContext(connectionContext)
                .tokenProvider(tokenProvider)
                .build();
}
 
示例10
@Bean
public ReactorUaaClient uaaClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
    return ReactorUaaClient
            .builder()
                .connectionContext(connectionContext)
                .tokenProvider(tokenProvider)
                .build();
}
 
示例11
@Bean
ReactorCloudFoundryClient cloudFoundryClient(
	ConnectionContext connectionContext,
	TokenProvider tokenProvider) {
	return ReactorCloudFoundryClient
		.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider).build();
}
 
示例12
@Bean
ReactorDopplerClient dopplerClient(ConnectionContext connectionContext,
																																			TokenProvider tokenProvider) {
	return ReactorDopplerClient
		.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();
}
 
示例13
@Bean
ReactorUaaClient uaaClient(ConnectionContext ctx, TokenProvider tokenProvider) {
	return ReactorUaaClient
		.builder()
		.connectionContext(ctx)
		.tokenProvider(tokenProvider)
		.build();
}
 
示例14
/**
 * Provide a {@link ReactorCloudFoundryClient} bean
 *
 * @param connectionContext the ConnectionContext bean
 * @param tokenProvider the TokenProvider bean
 * @return the bean
 */
@Bean
public ReactorCloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext,
	@TokenQualifier TokenProvider tokenProvider) {
	return ReactorCloudFoundryClient.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();
}
 
示例15
/**
 * Provide a {@link ReactorDopplerClient} bean
 *
 * @param connectionContext the ConnectionContext bean
 * @param tokenProvider the TokenProvider bean
 * @return the bean
 */
@Bean
public ReactorDopplerClient dopplerClient(ConnectionContext connectionContext,
	@TokenQualifier TokenProvider tokenProvider) {
	return ReactorDopplerClient.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();
}
 
示例16
/**
 * 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));
	}
}
 
示例17
/**
 * Provide a {@link ReactorUaaClient} bean
 *
 * @param connectionContext the ConnectionContext bean
 * @param tokenProvider the TokenProvider bean
 * @return the bean
 */
@UaaClientQualifier
@Bean
public ReactorUaaClient uaaClient(ConnectionContext connectionContext,
	@TokenQualifier TokenProvider tokenProvider) {
	return ReactorUaaClient.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();
}
 
示例18
@Test
void configureCloudFoundryClientWithClientCredentials() {
	this.contextRunner
		.withPropertyValues("spring.cloud.appbroker.deployer.cloudfoundry.api-host=https://api.example.local",
			"spring.cloud.appbroker.deployer.cloudfoundry.client_id=user",
			"spring.cloud.appbroker.deployer.cloudfoundry.client_secret=secret")
		.run(context -> {
			assertThat(context).hasSingleBean(TokenProvider.class);
			assertThat(context).hasSingleBean(ReactorCloudFoundryClient.class);
		});
}
 
示例19
@Test
void clientIsNotCreatedWithoutConfiguration() {
	this.contextRunner
		.run((context) -> {
			assertThat(context).doesNotHaveBean(CloudFoundryTargetProperties.class);
			assertThat(context).doesNotHaveBean(CloudFoundryDeploymentProperties.class);
			assertThat(context).doesNotHaveBean(ReactorCloudFoundryClient.class);
			assertThat(context).doesNotHaveBean(ReactorDopplerClient.class);
			assertThat(context).doesNotHaveBean(ReactorUaaClient.class);
			assertThat(context).doesNotHaveBean(CloudFoundryOperations.class);
			assertThat(context).doesNotHaveBean(CloudFoundryOperationsUtils.class);
			assertThat(context).doesNotHaveBean(ConnectionContext.class);
			assertThat(context).doesNotHaveBean(TokenProvider.class);
		});
}
 
示例20
@Bean
protected CloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext,
	@Qualifier("userCredentials") TokenProvider tokenProvider) {
	return ReactorCloudFoundryClient.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();
}
 
示例21
@Bean
protected DopplerClient dopplerClient(ConnectionContext connectionContext,
	@Qualifier("userCredentials") TokenProvider tokenProvider) {
	return ReactorDopplerClient.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();
}
 
示例22
@Bean
protected UaaClient uaaClient(ConnectionContext connectionContext,
	@Qualifier("clientCredentials") TokenProvider tokenProvider) {
	return ReactorUaaClient.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();
}
 
示例23
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();
}
 
示例24
@Override
public TokenProvider getTokenProvider() {
    if (tokenProvider == null) {
        tokenProvider = createTokenProvider();
    }
    return tokenProvider;
}
 
示例25
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();
}
 
示例26
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();
    }
}
 
示例27
@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);
    }
 
示例28
@Bean
@ConditionalOnMissingBean
public CloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
	return ReactorCloudFoundryClient.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();
}
 
示例29
@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();
}
 
示例30
@Bean
@ConditionalOnMissingBean
public ReactorSchedulerClient reactorSchedulerClient(ConnectionContext context,
		TokenProvider passwordGrantTokenProvider,
		CloudFoundrySchedulerProperties properties) {
	return ReactorSchedulerClient.builder()
			.connectionContext(context)
			.tokenProvider(passwordGrantTokenProvider)
			.root(Mono.just(properties.getSchedulerUrl()))
			.build();
}