Java Code Examples for org.keycloak.representations.idm.RealmRepresentation#setSsoSessionIdleTimeout()

The following examples show how to use org.keycloak.representations.idm.RealmRepresentation#setSsoSessionIdleTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DemoServletsAdapterTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoginSSOIdle() {
    // test login to customer-portal which does a bearer request to customer-db
    customerPortal.navigateTo();
    assertTrue(testRealmLoginPage.form().isUsernamePresent());
    assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
    testRealmLoginPage.form().login("[email protected]", "password");
    assertCurrentUrlEquals(customerPortal);
    assertLogged();

    RealmRepresentation demoRealmRep = testRealmResource().toRepresentation();
    int originalIdle = demoRealmRep.getSsoSessionIdleTimeout();
    try {
        demoRealmRep.setSsoSessionIdleTimeout(1);
        testRealmResource().update(demoRealmRep);

        // Needs to add some additional time due the tolerance allowed by IDLE_TIMEOUT_WINDOW_SECONDS
        setAdapterAndServerTimeOffset(2 + SessionTimeoutHelper.IDLE_TIMEOUT_WINDOW_SECONDS);

        productPortal.navigateTo();
        assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
    } finally {
        demoRealmRep.setSsoSessionIdleTimeout(originalIdle);
        testRealmResource().update(demoRealmRep);
    }
}
 
Example 2
Source File: DemoServletsAdapterTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoginSSOIdleRemoveExpiredUserSessions() {
    // test login to customer-portal which does a bearer request to customer-db
    customerPortal.navigateTo();
    log.info("Current url: " + driver.getCurrentUrl());
    assertTrue(testRealmLoginPage.form().isUsernamePresent());
    assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
    testRealmLoginPage.form().login("[email protected]", "password");
    log.info("Current url: " + driver.getCurrentUrl());
    assertCurrentUrlEquals(customerPortal);

    RealmRepresentation demoRealmRep = testRealmResource().toRepresentation();
    int originalIdle = demoRealmRep.getSsoSessionIdleTimeout();
    try {
        demoRealmRep.setSsoSessionIdleTimeout(1);
        testRealmResource().update(demoRealmRep);

        // Needs to add some additional time due the tolerance allowed by IDLE_TIMEOUT_WINDOW_SECONDS
        setAdapterAndServerTimeOffset(2 + SessionTimeoutHelper.IDLE_TIMEOUT_WINDOW_SECONDS);

        productPortal.navigateTo();
        assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
    } finally {
        // need to cleanup so other tests don't fail, so invalidate http sessions on remote clients.
        demoRealmRep.setSsoSessionIdleTimeout(originalIdle);
        testRealmResource().update(demoRealmRep);
        // note: sessions invalidated after each test, see: AbstractKeycloakTest.afterAbstractKeycloakTest()
    }
}
 
Example 3
Source File: SessionTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
    super.addTestRealms(testRealms);
    RealmRepresentation realm = testRealms.get(0);

    // in seconds
    realm.setSsoSessionIdleTimeout(1);
    realm.setAccessTokenLifespan(10);
}
 
Example 4
Source File: RealmTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Test
public void updateRealm() {
    // first change
    RealmRepresentation rep = realm.toRepresentation();
    rep.setSsoSessionIdleTimeout(123);
    rep.setSsoSessionMaxLifespan(12);
    rep.setSsoSessionIdleTimeoutRememberMe(33);
    rep.setSsoSessionMaxLifespanRememberMe(34);
    rep.setAccessCodeLifespanLogin(1234);
    rep.setActionTokenGeneratedByAdminLifespan(2345);
    rep.setActionTokenGeneratedByUserLifespan(3456);
    rep.setRegistrationAllowed(true);
    rep.setRegistrationEmailAsUsername(true);
    rep.setEditUsernameAllowed(true);
    rep.setUserManagedAccessAllowed(true);

    realm.update(rep);
    assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, Matchers.nullValue(String.class), rep, ResourceType.REALM);

    rep = realm.toRepresentation();

    assertEquals(123, rep.getSsoSessionIdleTimeout().intValue());
    assertEquals(12, rep.getSsoSessionMaxLifespan().intValue());
    assertEquals(33, rep.getSsoSessionIdleTimeoutRememberMe().intValue());
    assertEquals(34, rep.getSsoSessionMaxLifespanRememberMe().intValue());
    assertEquals(1234, rep.getAccessCodeLifespanLogin().intValue());
    assertEquals(2345, rep.getActionTokenGeneratedByAdminLifespan().intValue());
    assertEquals(3456, rep.getActionTokenGeneratedByUserLifespan().intValue());
    assertEquals(Boolean.TRUE, rep.isRegistrationAllowed());
    assertEquals(Boolean.TRUE, rep.isRegistrationEmailAsUsername());
    assertEquals(Boolean.TRUE, rep.isEditUsernameAllowed());
    assertEquals(Boolean.TRUE, rep.isUserManagedAccessAllowed());

    // second change
    rep.setRegistrationAllowed(false);
    rep.setRegistrationEmailAsUsername(false);
    rep.setEditUsernameAllowed(false);
    rep.setUserManagedAccessAllowed(false);

    realm.update(rep);
    assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, Matchers.nullValue(String.class), rep, ResourceType.REALM);

    rep = realm.toRepresentation();
    assertEquals(Boolean.FALSE, rep.isRegistrationAllowed());
    assertEquals(Boolean.FALSE, rep.isRegistrationEmailAsUsername());
    assertEquals(Boolean.FALSE, rep.isEditUsernameAllowed());
    assertEquals(Boolean.FALSE, rep.isUserManagedAccessAllowed());
}