diff --git a/services/src/main/java/org/keycloak/broker/oidc/AbstractOAuth2IdentityProvider.java b/services/src/main/java/org/keycloak/broker/oidc/AbstractOAuth2IdentityProvider.java index 765f233136..0bb485447a 100755 --- a/services/src/main/java/org/keycloak/broker/oidc/AbstractOAuth2IdentityProvider.java +++ b/services/src/main/java/org/keycloak/broker/oidc/AbstractOAuth2IdentityProvider.java @@ -331,11 +331,6 @@ public abstract class AbstractOAuth2IdentityProvider config = idp.getConfig(); applyDefaultConfiguration(config, syncMode); config.put(IdentityProviderModel.LOGIN_HINT, "false"); - config.put(IdentityProviderModel.PASS_MAX_AGE, "true"); + config.remove(OAuth2Constants.PROMPT); return idp; } @@ -92,4 +94,49 @@ public class KcOidcBrokerPassMaxAgeTest extends AbstractBrokerTest { testSingleLogout(); } + + @Test + public void testEnforceReAuthenticationWhenMaxAgeIsSet() { + // login as brokered user user, perform profile update on first broker login and logout user + loginUser(); + testSingleLogout(); + + driver.navigate().to(getAccountUrl(getConsumerRoot(), bc.consumerRealmName())); + loginPage.clickSocial(bc.getIDPAlias()); + waitForPage(driver, "sign in to", true); + Assert.assertTrue("Driver should be on the provider realm page right now", + driver.getCurrentUrl().contains("/auth/realms/" + bc.providerRealmName() + "/")); + + loginPage.login(bc.getUserLogin(), bc.getUserPassword()); + accountUpdateProfilePage.assertCurrent(); + + IdentityProviderResource idpResource = realmsResouce().realm(bc.consumerRealmName()).identityProviders() + .get(bc.getIDPAlias()); + IdentityProviderRepresentation idpRep = idpResource.toRepresentation(); + + TestKeycloakOidcIdentityProviderFactory.setIgnoreMaxAgeParam(idpRep); + + idpResource.update(idpRep); + + setTimeOffset(2); + + // trigger re-auth with max_age while we are still authenticated + String loginUrlWithMaxAge = getLoginUrl(getConsumerRoot(), bc.consumerRealmName(), "account") + "&max_age=1"; + driver.navigate().to(loginUrlWithMaxAge); + + // we should now see the login page of the consumer + waitForPage(driver, "sign in to", true); + loginPage.assertCurrent(bc.consumerRealmName()); + Assert.assertTrue("Driver should be on the consumer realm page right now", + driver.getCurrentUrl().contains("/auth/realms/" + bc.consumerRealmName() + "/protocol/openid-connect/auth")); + + loginPage.clickSocial(bc.getIDPAlias()); + // we should see the login page of the provider, since the max_age was propagated + waitForPage(driver, "sign in to", true); + loginPage.getError(); + Assert.assertEquals("Unexpected error when authenticating with identity provider", + loginPage.getInstruction()); + + testSingleLogout(); + } }