use of org.keycloak.adapters.HttpClientBuilder in project keycloak by keycloak.
the class LoginPageTest method realmLocalizationMessagesAreNotCachedWithinTheTheme.
// KEYCLOAK-18590
@Test
public void realmLocalizationMessagesAreNotCachedWithinTheTheme() throws IOException {
final String locale = Locale.ENGLISH.toLanguageTag();
final String realmLocalizationMessageKey = "loginAccountTitle";
final String realmLocalizationMessageValue = "Localization Test";
try (CloseableHttpClient httpClient = (CloseableHttpClient) new HttpClientBuilder().build()) {
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
testRealm().localization().saveRealmLocalizationText(locale, realmLocalizationMessageKey, realmLocalizationMessageValue);
ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
loginPage.open();
try (Response responseWithLocalization = client.target(driver.getCurrentUrl()).request().acceptLanguage(locale).get()) {
assertThat(responseWithLocalization.readEntity(String.class), Matchers.containsString(realmLocalizationMessageValue));
testRealm().localization().deleteRealmLocalizationText(locale, realmLocalizationMessageKey);
loginPage.open();
try (Response responseWithoutLocalization = client.target(driver.getCurrentUrl()).request().acceptLanguage(locale).get()) {
assertThat(responseWithoutLocalization.readEntity(String.class), Matchers.not(Matchers.containsString(realmLocalizationMessageValue)));
}
}
client.close();
}
}
use of org.keycloak.adapters.HttpClientBuilder in project alfresco-repository by Alfresco.
the class AuthenticatorAuthzClientFactoryBean method getObject.
@Override
public AuthzClient getObject() throws Exception {
// for instance when Keycloak is configured for 'bearer only' authentication or Direct Access Grants are disabled.
if (!enabled) {
return null;
}
// Build default http client using the keycloak client builder.
int conTimeout = identityServiceConfig.getClientConnectionTimeout();
int socTimeout = identityServiceConfig.getClientSocketTimeout();
HttpClient client = new HttpClientBuilder().establishConnectionTimeout(conTimeout, TimeUnit.MILLISECONDS).socketTimeout(socTimeout, TimeUnit.MILLISECONDS).build(this.identityServiceConfig);
// Add secret to credentials if needed.
// AuthzClient configuration needs credentials with a secret even if the client in Keycloak is configured as public.
Map<String, Object> credentials = identityServiceConfig.getCredentials();
if (credentials == null || !credentials.containsKey("secret")) {
credentials = credentials == null ? new HashMap<>() : new HashMap<>(credentials);
credentials.put("secret", "");
}
// Create default AuthzClient for authenticating users against keycloak
String authServerUrl = identityServiceConfig.getAuthServerUrl();
String realm = identityServiceConfig.getRealm();
String resource = identityServiceConfig.getResource();
Configuration authzConfig = new Configuration(authServerUrl, realm, resource, credentials, client);
AuthzClient authzClient = AuthzClient.create(authzConfig);
if (logger.isDebugEnabled()) {
logger.debug(" Created Keycloak AuthzClient");
logger.debug(" Keycloak AuthzClient server URL: " + authzClient.getConfiguration().getAuthServerUrl());
logger.debug(" Keycloak AuthzClient realm: " + authzClient.getConfiguration().getRealm());
logger.debug(" Keycloak AuthzClient resource: " + authzClient.getConfiguration().getResource());
}
return authzClient;
}
use of org.keycloak.adapters.HttpClientBuilder in project alfresco-repository by Alfresco.
the class IdentityServiceDeploymentFactoryBean method getObject.
@Override
public KeycloakDeployment getObject() throws Exception {
KeycloakDeployment deployment = KeycloakDeploymentBuilder.build(this.identityServiceConfig);
// This can be removed if the future versions of Keycloak accept timeout values through the config.
if (deployment.getClient() != null) {
int connectionTimeout = identityServiceConfig.getClientConnectionTimeout();
int socketTimeout = identityServiceConfig.getClientSocketTimeout();
HttpClient client = new HttpClientBuilder().establishConnectionTimeout(connectionTimeout, TimeUnit.MILLISECONDS).socketTimeout(socketTimeout, TimeUnit.MILLISECONDS).build(this.identityServiceConfig);
deployment.setClient(client);
if (logger.isDebugEnabled()) {
logger.debug("Created HttpClient for Keycloak deployment with connection timeout: " + connectionTimeout + " ms, socket timeout: " + socketTimeout + " ms.");
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("HttpClient for Keycloak deployment was not set.");
}
}
if (logger.isInfoEnabled()) {
logger.info("Keycloak JWKS URL: " + deployment.getJwksUrl());
logger.info("Keycloak Realm: " + deployment.getRealm());
logger.info("Keycloak Client ID: " + deployment.getResourceName());
}
return deployment;
}
Aggregations