Package org.keycloak.models

Examples of org.keycloak.models.KeycloakSession


            session.close();
        }
    }

    public void update(KeycloakRule.KeycloakSetup configurer, String realmId) {
        KeycloakSession session = server.getSessionFactory().create();
        session.getTransaction().begin();

        try {
            RealmManager manager = new RealmManager(session);

            RealmModel adminstrationRealm = manager.getRealm(Config.getAdminRealm());
            RealmModel appRealm = manager.getRealm(realmId);

            configurer.session = session;
            configurer.config(manager, adminstrationRealm, appRealm);

            session.getTransaction().commit();
        } finally {
            session.close();
        }
    }
View Full Code Here


        removeTestRealms();
        stopServer();
    }

    protected void removeTestRealms() {
        KeycloakSession session = server.getSessionFactory().create();
        try {
            session.getTransaction().begin();
            RealmManager realmManager = new RealmManager(session);
            for (String realmName : getTestRealms()) {
                RealmModel realm = realmManager.getRealmByName(realmName);
                if (realm != null) {
                    realmManager.removeRealm(realm);
                }
            }
            session.getTransaction().commit();
        } finally {
            session.close();
        }
    }
View Full Code Here

        byte[] bytes = os.toByteArray();
        return JsonSerialization.readValue(bytes, RealmRepresentation.class);
    }

    public KeycloakSession startSession() {
        KeycloakSession session = server.getSessionFactory().create();
        session.getTransaction().begin();
        return session;
    }
View Full Code Here

    @ClassRule
    public static KeycloakRule kc = new KeycloakRule();

    @Test
    public void testTransactionActive() {
        KeycloakSession session = kc.startSession();

        Assert.assertTrue(session.getTransaction().isActive());
        session.getTransaction().commit();
        Assert.assertFalse(session.getTransaction().isActive());

        session.getTransaction().begin();
        Assert.assertTrue(session.getTransaction().isActive());
        session.getTransaction().rollback();
        Assert.assertFalse(session.getTransaction().isActive());

        session.close();
    }
View Full Code Here

        Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/bad-realm-sales-post-sig/");
        Assert.assertTrue(driver.getPageSource().contains("null"));
    }

    private static String createToken() {
        KeycloakSession session = keycloakRule.startSession();
        try {
            RealmManager manager = new RealmManager(session);

            RealmModel adminRealm = manager.getRealm(Config.getAdminRealm());
            ApplicationModel adminConsole = adminRealm.getApplicationByName(Constants.ADMIN_CONSOLE_APPLICATION);
            TokenManager tm = new TokenManager();
            UserModel admin = session.users().getUserByUsername("admin", adminRealm);
            UserSessionModel userSession = session.sessions().createUserSession(adminRealm, admin, "admin", null, "form", false);
            AccessToken token = tm.createClientAccessToken(tm.getAccess(null, adminConsole, admin), adminRealm, adminConsole, admin, userSession);
            return tm.encodeToken(adminRealm, token);
        } finally {
            keycloakRule.stopSession(session, true);
        }
View Full Code Here

    protected void importRealm() {
        server.importRealm(getClass().getResourceAsStream("/testrealm.json"));
    }

    public void configure(KeycloakSetup configurer) {
        KeycloakSession session = server.getSessionFactory().create();
        session.getTransaction().begin();

        try {
            RealmManager manager = new RealmManager(session);

            RealmModel adminstrationRealm = manager.getRealm(Config.getAdminRealm());
            RealmModel appRealm = manager.getRealm("test");

            configurer.session = session;
            configurer.config(manager, adminstrationRealm, appRealm);

            session.getTransaction().commit();
        } finally {
            session.close();
        }
    }
View Full Code Here

        protected void configure(KeycloakSession session, RealmManager manager, RealmModel adminRealm) {
        }
    };

    private static String createToken() {
        KeycloakSession session = keycloakRule.startSession();
        try {
            RealmManager manager = new RealmManager(session);

            RealmModel adminRealm = manager.getRealm(Config.getAdminRealm());
            ApplicationModel adminConsole = adminRealm.getApplicationByName(Constants.ADMIN_CONSOLE_APPLICATION);
            TokenManager tm = new TokenManager();
            UserModel admin = session.users().getUserByUsername("admin", adminRealm);
            UserSessionModel userSession = session.sessions().createUserSession(adminRealm, admin, "admin", null, "form", false);
            AccessToken token = tm.createClientAccessToken(tm.getAccess(null, adminConsole, admin), adminRealm, adminConsole, admin, userSession);
            return tm.encodeToken(adminRealm, token);
        } finally {
            keycloakRule.stopSession(session, true);
        }
View Full Code Here

        update(configurer, "test");
    }


    public void removeUserSession(String sessionId) {
        KeycloakSession session = startSession();
        RealmModel realm = session.realms().getRealm("test");
        UserSessionModel userSession = session.sessions().getUserSession(realm, sessionId);
        assertNotNull(userSession);
        session.sessions().removeUserSession(realm, userSession);
        stopSession(session, true);
    }
View Full Code Here

        session.sessions().removeUserSession(realm, userSession);
        stopSession(session, true);
    }

    public ClientSessionCode verifyCode(String code) {
        KeycloakSession session = startSession();
        try {
            RealmModel realm = session.realms().getRealm("test");
            try {
                ClientSessionCode accessCode = ClientSessionCode.parse(code, session, realm);
                if (accessCode == null) {
                    Assert.fail("Invalid code");
                }
View Full Code Here

TOP

Related Classes of org.keycloak.models.KeycloakSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.