Example usage for org.springframework.boot.autoconfigure.security.oauth2.resource ResourceServerProperties getClientSecret

List of usage examples for org.springframework.boot.autoconfigure.security.oauth2.resource ResourceServerProperties getClientSecret

Introduction

In this page you can find the example usage for org.springframework.boot.autoconfigure.security.oauth2.resource ResourceServerProperties getClientSecret.

Prototype

public String getClientSecret() 

Source Link

Usage

From source file:com.netflix.genie.security.oauth2.pingfederate.PingFederateRemoteTokenServices.java

/**
 * Constructor./* w ww  .ja  v a2  s  .co m*/
 *
 * @param serverProperties The properties of the resource server (Genie)
 * @param converter        The access token converter to use
 * @param registry         The metrics registry to use
 */
public PingFederateRemoteTokenServices(@NotNull final ResourceServerProperties serverProperties,
        @NotNull final AccessTokenConverter converter, @NotNull final MeterRegistry registry) {
    super();
    this.authenticationTimer = registry.timer(AUTHENTICATION_TIMER_NAME);
    this.pingFederateAPITimer = registry.timer(API_TIMER_NAME);
    final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    factory.setConnectTimeout(2000);
    factory.setReadTimeout(10000);
    final RestTemplate restTemplate = new RestTemplate(factory);
    final List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
    interceptors
            .add((final HttpRequest request, final byte[] body, final ClientHttpRequestExecution execution) -> {
                final long start = System.nanoTime();
                try {
                    return execution.execute(request, body);
                } finally {
                    pingFederateAPITimer.record(System.nanoTime() - start, TimeUnit.NANOSECONDS);
                }
            });
    restTemplate.setInterceptors(interceptors);
    restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
        // Ignore 400
        @Override
        public void handleError(final ClientHttpResponse response) throws IOException {
            final int errorCode = response.getRawStatusCode();
            registry.counter(TOKEN_VALIDATION_ERROR_COUNTER_NAME,
                    Sets.newHashSet(Tag.of(MetricsConstants.TagKeys.STATUS, Integer.toString(errorCode))))
                    .increment();
            if (response.getRawStatusCode() != HttpStatus.BAD_REQUEST.value()) {
                super.handleError(response);
            }
        }
    });

    this.setRestTemplate(restTemplate);

    this.checkTokenEndpointUrl = serverProperties.getTokenInfoUri();
    this.clientId = serverProperties.getClientId();
    this.clientSecret = serverProperties.getClientSecret();

    Assert.state(StringUtils.isNotBlank(this.checkTokenEndpointUrl), "Check Endpoint URL is required");
    Assert.state(StringUtils.isNotBlank(this.clientId), "Client ID is required");
    Assert.state(StringUtils.isNotBlank(this.clientSecret), "Client secret is required");

    log.debug("checkTokenEndpointUrl = {}", this.checkTokenEndpointUrl);
    log.debug("clientId = {}", this.clientId);
    log.debug("clientSecret = {}", this.clientSecret);

    this.converter = converter;
}

From source file:com.netflix.genie.web.security.oauth2.pingfederate.PingFederateRemoteTokenServices.java

/**
 * Constructor./*  w w w . j a  v a  2s .c o m*/
 *
 * @param serverProperties The properties of the resource server (Genie)
 * @param converter        The access token converter to use
 * @param registry         The metrics registry to use
 */
public PingFederateRemoteTokenServices(@NotNull final ResourceServerProperties serverProperties,
        @NotNull final AccessTokenConverter converter, @NotNull final Registry registry) {
    super();
    this.tokenValidationError = registry
            .createId("genie.security.oauth2.pingFederate.tokenValidation.error.rate");
    this.authenticationTimer = registry.timer(AUTHENTICATION_TIMER_NAME);
    this.pingFederateAPITimer = registry.timer(API_TIMER_NAME);
    final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    factory.setConnectTimeout(2000);
    factory.setReadTimeout(10000);
    final RestTemplate restTemplate = new RestTemplate(factory);
    final List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
    interceptors
            .add((final HttpRequest request, final byte[] body, final ClientHttpRequestExecution execution) -> {
                final long start = System.nanoTime();
                try {
                    return execution.execute(request, body);
                } finally {
                    pingFederateAPITimer.record(System.nanoTime() - start, TimeUnit.NANOSECONDS);
                }
            });
    restTemplate.setInterceptors(interceptors);
    restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
        // Ignore 400
        @Override
        public void handleError(final ClientHttpResponse response) throws IOException {
            final int errorCode = response.getRawStatusCode();
            registry.counter(tokenValidationError.withTag("status", Integer.toString(errorCode))).increment();
            if (response.getRawStatusCode() != HttpStatus.BAD_REQUEST.value()) {
                super.handleError(response);
            }
        }
    });

    this.setRestTemplate(restTemplate);

    this.checkTokenEndpointUrl = serverProperties.getTokenInfoUri();
    this.clientId = serverProperties.getClientId();
    this.clientSecret = serverProperties.getClientSecret();

    Assert.state(StringUtils.isNotBlank(this.checkTokenEndpointUrl), "Check Endpoint URL is required");
    Assert.state(StringUtils.isNotBlank(this.clientId), "Client ID is required");
    Assert.state(StringUtils.isNotBlank(this.clientSecret), "Client secret is required");

    log.debug("checkTokenEndpointUrl = {}", this.checkTokenEndpointUrl);
    log.debug("clientId = {}", this.clientId);
    log.debug("clientSecret = {}", this.clientSecret);

    this.converter = converter;
}