make HttpClient configurable, closes #1071
parent
f45a6ef56a
commit
c3d0c18af5
|
@ -73,10 +73,15 @@ public class IntrospectingTokenService implements ResourceServerTokenServices {
|
|||
private boolean cacheNonExpiringTokens = false;
|
||||
private boolean cacheTokens = true;
|
||||
|
||||
private HttpClient httpClient = HttpClientBuilder.create()
|
||||
.useSystemProperties()
|
||||
.build();
|
||||
private HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
private HttpComponentsClientHttpRequestFactory factory;
|
||||
|
||||
public IntrospectingTokenService() {
|
||||
this(HttpClientBuilder.create().useSystemProperties().build());
|
||||
}
|
||||
|
||||
public IntrospectingTokenService(HttpClient httpClient) {
|
||||
this.factory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
}
|
||||
|
||||
// Inner class to store in the hash map
|
||||
private class TokenCacheObject {
|
||||
|
|
|
@ -119,6 +119,8 @@ public class OIDCAuthenticationFilter extends AbstractAuthenticationProcessingFi
|
|||
@Autowired(required=false)
|
||||
private JWTSigningAndValidationService authenticationSignerService;
|
||||
|
||||
@Autowired(required=false)
|
||||
private HttpClient httpClient;
|
||||
|
||||
/*
|
||||
* Modular services to build out client filter.
|
||||
|
@ -341,14 +343,14 @@ public class OIDCAuthenticationFilter extends AbstractAuthenticationProcessingFi
|
|||
|
||||
// Handle Token Endpoint interaction
|
||||
|
||||
HttpClient httpClient = HttpClientBuilder.create()
|
||||
.useSystemProperties()
|
||||
.setDefaultRequestConfig(
|
||||
RequestConfig.custom()
|
||||
.setSocketTimeout(httpSocketTimeout)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
if(httpClient == null) {
|
||||
httpClient = HttpClientBuilder.create()
|
||||
.useSystemProperties()
|
||||
.setDefaultRequestConfig(RequestConfig.custom()
|
||||
.setSocketTimeout(httpSocketTimeout)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
|
||||
|
|
|
@ -61,10 +61,14 @@ public class UserInfoFetcher {
|
|||
private LoadingCache<PendingOIDCAuthenticationToken, UserInfo> cache;
|
||||
|
||||
public UserInfoFetcher() {
|
||||
this(HttpClientBuilder.create().useSystemProperties().build());
|
||||
}
|
||||
|
||||
public UserInfoFetcher(HttpClient httpClient) {
|
||||
cache = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(1, TimeUnit.HOURS) // expires 1 hour after fetch
|
||||
.maximumSize(100)
|
||||
.build(new UserInfoLoader());
|
||||
.build(new UserInfoLoader(httpClient));
|
||||
}
|
||||
|
||||
public UserInfo loadUserInfo(final PendingOIDCAuthenticationToken token) {
|
||||
|
@ -79,11 +83,12 @@ public class UserInfoFetcher {
|
|||
|
||||
|
||||
private class UserInfoLoader extends CacheLoader<PendingOIDCAuthenticationToken, UserInfo> {
|
||||
private HttpClient httpClient = HttpClientBuilder.create()
|
||||
.useSystemProperties()
|
||||
.build();
|
||||
private HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
|
||||
private HttpComponentsClientHttpRequestFactory factory;
|
||||
|
||||
UserInfoLoader(HttpClient httpClient) {
|
||||
this.factory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
}
|
||||
|
||||
public UserInfo load(final PendingOIDCAuthenticationToken token) {
|
||||
|
||||
ServerConfiguration serverConfiguration = token.getServerConfiguration();
|
||||
|
|
|
@ -72,7 +72,11 @@ public class DynamicRegistrationClientConfigurationService implements ClientConf
|
|||
private Set<String> blacklist = new HashSet<>();
|
||||
|
||||
public DynamicRegistrationClientConfigurationService() {
|
||||
clients = CacheBuilder.newBuilder().build(new DynamicClientRegistrationLoader());
|
||||
this(HttpClientBuilder.create().useSystemProperties().build());
|
||||
}
|
||||
|
||||
public DynamicRegistrationClientConfigurationService(HttpClient httpClient) {
|
||||
clients = CacheBuilder.newBuilder().build(new DynamicClientRegistrationLoader(httpClient));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -168,13 +172,17 @@ public class DynamicRegistrationClientConfigurationService implements ClientConf
|
|||
*
|
||||
*/
|
||||
public class DynamicClientRegistrationLoader extends CacheLoader<ServerConfiguration, RegisteredClient> {
|
||||
private HttpClient httpClient = HttpClientBuilder.create()
|
||||
.useSystemProperties()
|
||||
.build();
|
||||
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory;
|
||||
private Gson gson = new Gson(); // note that this doesn't serialize nulls by default
|
||||
|
||||
public DynamicClientRegistrationLoader() {
|
||||
this(HttpClientBuilder.create().useSystemProperties().build());
|
||||
}
|
||||
|
||||
public DynamicClientRegistrationLoader(HttpClient httpClient) {
|
||||
this.httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegisteredClient load(ServerConfiguration serverConfig) throws Exception {
|
||||
RestTemplate restTemplate = new RestTemplate(httpFactory);
|
||||
|
|
|
@ -69,8 +69,12 @@ public class DynamicServerConfigurationService implements ServerConfigurationSer
|
|||
private Set<String> blacklist = new HashSet<>();
|
||||
|
||||
public DynamicServerConfigurationService() {
|
||||
this(HttpClientBuilder.create().useSystemProperties().build());
|
||||
}
|
||||
|
||||
public DynamicServerConfigurationService(HttpClient httpClient) {
|
||||
// initialize the cache
|
||||
servers = CacheBuilder.newBuilder().build(new OpenIDConnectServiceConfigurationFetcher());
|
||||
servers = CacheBuilder.newBuilder().build(new OpenIDConnectServiceConfigurationFetcher(httpClient));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,12 +130,13 @@ public class DynamicServerConfigurationService implements ServerConfigurationSer
|
|||
*
|
||||
*/
|
||||
private class OpenIDConnectServiceConfigurationFetcher extends CacheLoader<String, ServerConfiguration> {
|
||||
private HttpClient httpClient = HttpClientBuilder.create()
|
||||
.useSystemProperties()
|
||||
.build();
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory;
|
||||
private JsonParser parser = new JsonParser();
|
||||
|
||||
OpenIDConnectServiceConfigurationFetcher(HttpClient httpClient) {
|
||||
this.httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerConfiguration load(String issuer) throws Exception {
|
||||
RestTemplate restTemplate = new RestTemplate(httpFactory);
|
||||
|
|
|
@ -94,7 +94,11 @@ public class WebfingerIssuerService implements IssuerService {
|
|||
private boolean forceHttps = true;
|
||||
|
||||
public WebfingerIssuerService() {
|
||||
issuers = CacheBuilder.newBuilder().build(new WebfingerIssuerFetcher());
|
||||
this(HttpClientBuilder.create().useSystemProperties().build());
|
||||
}
|
||||
|
||||
public WebfingerIssuerService(HttpClient httpClient) {
|
||||
issuers = CacheBuilder.newBuilder().build(new WebfingerIssuerFetcher(httpClient));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -203,12 +207,13 @@ public class WebfingerIssuerService implements IssuerService {
|
|||
*
|
||||
*/
|
||||
private class WebfingerIssuerFetcher extends CacheLoader<String, LoadingResult> {
|
||||
private HttpClient httpClient = HttpClientBuilder.create()
|
||||
.useSystemProperties()
|
||||
.build();
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory;
|
||||
private JsonParser parser = new JsonParser();
|
||||
|
||||
WebfingerIssuerFetcher(HttpClient httpClient) {
|
||||
this.httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadingResult load(String identifier) throws Exception {
|
||||
|
||||
|
|
|
@ -68,11 +68,11 @@ public class JWKSetCacheService {
|
|||
this.validators = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(1, TimeUnit.HOURS) // expires 1 hour after fetch
|
||||
.maximumSize(100)
|
||||
.build(new JWKSetVerifierFetcher());
|
||||
.build(new JWKSetVerifierFetcher(HttpClientBuilder.create().useSystemProperties().build()));
|
||||
this.encrypters = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(1, TimeUnit.HOURS) // expires 1 hour after fetch
|
||||
.maximumSize(100)
|
||||
.build(new JWKSetEncryptorFetcher());
|
||||
.build(new JWKSetEncryptorFetcher(HttpClientBuilder.create().useSystemProperties().build()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,9 +104,13 @@ public class JWKSetCacheService {
|
|||
*
|
||||
*/
|
||||
private class JWKSetVerifierFetcher extends CacheLoader<String, JWTSigningAndValidationService> {
|
||||
private HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build();
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
private RestTemplate restTemplate = new RestTemplate(httpFactory);
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory;
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
JWKSetVerifierFetcher(HttpClient httpClient) {
|
||||
this.httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
this.restTemplate = new RestTemplate(httpFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the JWK Set and build the appropriate signing service.
|
||||
|
@ -130,9 +134,14 @@ public class JWKSetCacheService {
|
|||
*
|
||||
*/
|
||||
private class JWKSetEncryptorFetcher extends CacheLoader<String, JWTEncryptionAndDecryptionService> {
|
||||
private HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build();
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
private RestTemplate restTemplate = new RestTemplate(httpFactory);
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory;
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
public JWKSetEncryptorFetcher(HttpClient httpClient) {
|
||||
this.httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
this.restTemplate = new RestTemplate(httpFactory);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.common.cache.CacheLoader#load(java.lang.Object)
|
||||
*/
|
||||
|
|
|
@ -103,7 +103,7 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
|
|||
private LoadingCache<String, List<String>> sectorRedirects = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
||||
.maximumSize(100)
|
||||
.build(new SectorIdentifierLoader());
|
||||
.build(new SectorIdentifierLoader(HttpClientBuilder.create().useSystemProperties().build()));
|
||||
|
||||
@Override
|
||||
public ClientDetailsEntity saveNewClient(ClientDetailsEntity client) {
|
||||
|
@ -465,11 +465,15 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
|
|||
*
|
||||
*/
|
||||
private class SectorIdentifierLoader extends CacheLoader<String, List<String>> {
|
||||
private HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build();
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
private RestTemplate restTemplate = new RestTemplate(httpFactory);
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory;
|
||||
private RestTemplate restTemplate;
|
||||
private JsonParser parser = new JsonParser();
|
||||
|
||||
SectorIdentifierLoader(HttpClient httpClient) {
|
||||
this.httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
this.restTemplate = new RestTemplate(httpFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> load(String key) throws Exception {
|
||||
|
||||
|
|
|
@ -48,17 +48,20 @@ import com.google.common.util.concurrent.UncheckedExecutionException;
|
|||
public class InMemoryClientLogoLoadingService implements ClientLogoLoadingService {
|
||||
|
||||
private LoadingCache<ClientDetailsEntity, CachedImage> cache;
|
||||
|
||||
|
||||
|
||||
public InMemoryClientLogoLoadingService() {
|
||||
this(HttpClientBuilder.create().useSystemProperties().build());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public InMemoryClientLogoLoadingService() {
|
||||
public InMemoryClientLogoLoadingService(HttpClient httpClient) {
|
||||
|
||||
cache = CacheBuilder.newBuilder()
|
||||
.maximumSize(100)
|
||||
.expireAfterAccess(14, TimeUnit.DAYS)
|
||||
.build(new ClientLogoFetcher());
|
||||
.build(new ClientLogoFetcher(httpClient));
|
||||
|
||||
}
|
||||
|
||||
|
@ -84,8 +87,15 @@ public class InMemoryClientLogoLoadingService implements ClientLogoLoadingServic
|
|||
*
|
||||
*/
|
||||
public class ClientLogoFetcher extends CacheLoader<ClientDetailsEntity, CachedImage> {
|
||||
private HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build();
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
private HttpClient httpClient;
|
||||
|
||||
public ClientLogoFetcher() {
|
||||
this(HttpClientBuilder.create().useSystemProperties().build());
|
||||
}
|
||||
|
||||
public ClientLogoFetcher(HttpClient httpClient) {
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.common.cache.CacheLoader#load(java.lang.Object)
|
||||
|
|
Loading…
Reference in New Issue