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

The following examples show how to use org.keycloak.representations.idm.RealmRepresentation#setSsoSessionMaxLifespanRememberMe() . 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: LoginTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void setRememberMe(boolean enabled, Integer idleTimeout, Integer maxLifespan) {
    RealmRepresentation rep = adminClient.realm("test").toRepresentation();
    rep.setRememberMe(enabled);
    rep.setSsoSessionIdleTimeoutRememberMe(idleTimeout);
    rep.setSsoSessionMaxLifespanRememberMe(maxLifespan);
    adminClient.realm("test").update(rep);
}
 
Example 2
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());
}
 
Example 3
Source File: RefreshTokenTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
/**
 * KEYCLOAK-1267
 * @throws Exception
 */
@Test
public void refreshTokenUserSessionMaxLifespanWithRememberMe() throws Exception {

    RealmResource testRealm = adminClient.realm("test");
    RealmRepresentation testRealmRep = testRealm.toRepresentation();
    Boolean previousRememberMe = testRealmRep.isRememberMe();
    int previousSsoMaxLifespanRememberMe = testRealmRep.getSsoSessionMaxLifespanRememberMe();

    try {
        testRealmRep.setRememberMe(true);
        testRealm.update(testRealmRep);

        oauth.doRememberMeLogin("test-user@localhost", "password");

        EventRepresentation loginEvent = events.expectLogin().assertEvent();

        String sessionId = loginEvent.getSessionId();

        String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
        OAuthClient.AccessTokenResponse tokenResponse = oauth.doAccessTokenRequest(code, "password");

        events.poll();

        String refreshId = oauth.parseRefreshToken(tokenResponse.getRefreshToken()).getId();

        testRealmRep.setSsoSessionMaxLifespanRememberMe(1);
        testRealm.update(testRealmRep);

        setTimeOffset(2);

        tokenResponse = oauth.doRefreshTokenRequest(tokenResponse.getRefreshToken(), "password");

        assertEquals(400, tokenResponse.getStatusCode());
        assertNull(tokenResponse.getAccessToken());
        assertNull(tokenResponse.getRefreshToken());

        events.expectRefresh(refreshId, sessionId).error(Errors.INVALID_TOKEN);
        events.clear();

    } finally {
        testRealmRep.setSsoSessionMaxLifespanRememberMe(previousSsoMaxLifespanRememberMe);
        testRealmRep.setRememberMe(previousRememberMe);
        testRealm.update(testRealmRep);
        setTimeOffset(0);
    }
}