Search in sources :

Example 16 with KeycloakSession

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);
        }
    }
}
Also used : KeycloakTransactionManager(org.keycloak.models.KeycloakTransactionManager) KeycloakSession(org.keycloak.models.KeycloakSession) KeycloakSessionFactory(org.keycloak.models.KeycloakSessionFactory)

Example 17 with KeycloakSession

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));
}
Also used : RealmModel(org.keycloak.models.RealmModel) Objects(java.util.Objects) ClientModel(org.keycloak.models.ClientModel) ClientRegistrationProvider(org.keycloak.services.clientregistration.ClientRegistrationProvider) RealmModel(org.keycloak.models.RealmModel) Details(org.keycloak.events.Details) ClientRegistrationContext(org.keycloak.services.clientregistration.ClientRegistrationContext) Logger(org.jboss.logging.Logger) ComponentModel(org.keycloak.component.ComponentModel) KeycloakSession(org.keycloak.models.KeycloakSession) ServicesLogger(org.keycloak.services.ServicesLogger)

Example 18 with KeycloakSession

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) KeycloakSession(org.keycloak.models.KeycloakSession) IdentityProviderModel(org.keycloak.models.IdentityProviderModel) Test(org.junit.Test)

Example 19 with KeycloakSession

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
    }
}
Also used : KeycloakSession(org.keycloak.models.KeycloakSession) IdentityBrokerException(org.keycloak.broker.provider.IdentityBrokerException) IdentityProviderModel(org.keycloak.models.IdentityProviderModel) Test(org.junit.Test)

Example 20 with KeycloakSession

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);
}
Also used : DefaultKeycloakSessionFactory(org.keycloak.services.DefaultKeycloakSessionFactory) DefaultKeycloakSession(org.keycloak.services.DefaultKeycloakSession) KeycloakSession(org.keycloak.models.KeycloakSession) DefaultKeycloakSession(org.keycloak.services.DefaultKeycloakSession) Test(org.junit.Test)

Aggregations

KeycloakSession (org.keycloak.models.KeycloakSession)189 RealmModel (org.keycloak.models.RealmModel)136 UserModel (org.keycloak.models.UserModel)78 Test (org.junit.Test)76 ModelTest (org.keycloak.testsuite.arquillian.annotation.ModelTest)61 ClientModel (org.keycloak.models.ClientModel)58 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)53 List (java.util.List)34 AtomicReference (java.util.concurrent.atomic.AtomicReference)22 Collectors (java.util.stream.Collectors)21 IOException (java.io.IOException)20 Map (java.util.Map)19 UserSessionModel (org.keycloak.models.UserSessionModel)19 ArrayList (java.util.ArrayList)18 ClientScopeModel (org.keycloak.models.ClientScopeModel)18 RoleModel (org.keycloak.models.RoleModel)18 Set (java.util.Set)16 RealmManager (org.keycloak.services.managers.RealmManager)16 HashMap (java.util.HashMap)14 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)14