use of org.keycloak.models.KeycloakSession in project keycloak by keycloak.
the class AbstractRequestFilter method filter.
protected void filter(ClientConnection clientConnection, Consumer<KeycloakSession> next) {
KeycloakSessionFactory sessionFactory = getSessionFactory();
KeycloakSession session = sessionFactory.create();
KeycloakTransactionManager tx = session.getTransactionManager();
tx.begin();
try {
Resteasy.pushContext(ClientConnection.class, clientConnection);
Resteasy.pushContext(KeycloakSession.class, session);
next.accept(session);
} catch (Exception e) {
tx.setRollbackOnly();
throw new RuntimeException(e);
} finally {
if (isAutoClose()) {
close(session);
}
}
}
use of org.keycloak.models.KeycloakSession in project keycloak by keycloak.
the class ClientRegistrationPolicyManager method triggerPolicies.
private static void triggerPolicies(KeycloakSession session, ClientRegistrationProvider provider, RegistrationAuth authType, String opDescription, ClientRegOperation op) throws ClientRegistrationPolicyException {
RealmModel realm = session.getContext().getRealm();
String policyTypeKey = getComponentTypeKey(authType);
realm.getComponentsStream(realm.getId(), ClientRegistrationPolicy.class.getName()).filter(componentModel -> Objects.equals(componentModel.getSubType(), policyTypeKey)).forEach(policyModel -> runPolicy(policyModel, session, provider, opDescription, op));
}
use of org.keycloak.models.KeycloakSession in project keycloak by keycloak.
the class OpenshiftV4IdentityProviderTest method testExtractingConfigProperties.
@Test
public void testExtractingConfigProperties() {
// given
OpenshiftV4IdentityProviderConfig config = new OpenshiftV4IdentityProviderConfig(new IdentityProviderModel());
// when
new OpenshiftV4IdentityProvider(null, config) {
@Override
InputStream getOauthMetadataInputStream(KeycloakSession session, String baseUrl) {
return new ByteArrayInputStream(authMetadata.getBytes());
}
};
// then
Assert.assertEquals(OpenshiftV4IdentityProvider.BASE_URL + OpenshiftV4IdentityProvider.PROFILE_RESOURCE, config.getUserInfoUrl());
Assert.assertEquals(oauthMetadataMap.get("token_endpoint"), config.getTokenUrl());
Assert.assertEquals(oauthMetadataMap.get("authorization_endpoint"), config.getAuthorizationUrl());
}
use of org.keycloak.models.KeycloakSession in project keycloak by keycloak.
the class OpenshiftV4IdentityProviderTest method testHttpClientErrors.
@Test
public void testHttpClientErrors() {
// given
OpenshiftV4IdentityProviderConfig config = new OpenshiftV4IdentityProviderConfig(new IdentityProviderModel());
// when
try {
new OpenshiftV4IdentityProvider(null, config) {
@Override
InputStream getOauthMetadataInputStream(KeycloakSession session, String baseUrl) {
throw new RuntimeException("Failed : HTTP error code : 500");
}
};
Assert.fail();
} catch (IdentityBrokerException e) {
// then
// OK
}
}
use of org.keycloak.models.KeycloakSession in project keycloak by keycloak.
the class PlainTextVaultProviderFactoryTest method shouldInitializeVaultCorrectly.
@Test
public void shouldInitializeVaultCorrectly() {
// given
VaultConfig config = new VaultConfig(Scenario.EXISTING.getAbsolutePathAsString());
KeycloakSession session = new DefaultKeycloakSession(new DefaultKeycloakSessionFactory());
FilesPlainTextVaultProviderFactory factory = new FilesPlainTextVaultProviderFactory() {
@Override
protected String getRealmName(KeycloakSession session) {
return "test";
}
};
// when
factory.init(config);
VaultProvider provider = factory.create(session);
// then
assertNotNull(provider);
}
Aggregations