diff --git a/services/src/main/java/org/keycloak/authentication/requiredactions/TermsAndConditions.java b/services/src/main/java/org/keycloak/authentication/requiredactions/TermsAndConditions.java index e48b437ddd..b34f040e31 100755 --- a/services/src/main/java/org/keycloak/authentication/requiredactions/TermsAndConditions.java +++ b/services/src/main/java/org/keycloak/authentication/requiredactions/TermsAndConditions.java @@ -8,6 +8,7 @@ import org.keycloak.Config; import org.keycloak.authentication.RequiredActionContext; import org.keycloak.authentication.RequiredActionFactory; import org.keycloak.authentication.RequiredActionProvider; +import org.keycloak.common.util.Time; import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSessionFactory; @@ -62,8 +63,7 @@ public class TermsAndConditions implements RequiredActionProvider, RequiredActio return; } - SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); - context.getUser().setAttribute(USER_ATTRIBUTE, Arrays.asList(dateTimeFormat.format(new Date()))); + context.getUser().setAttribute(USER_ATTRIBUTE, Arrays.asList(Integer.toString(Time.currentTime()))); context.success(); } diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/actions/TermsAndConditionsTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/actions/TermsAndConditionsTest.java index d8709238eb..b1cf9819cb 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/actions/TermsAndConditionsTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/actions/TermsAndConditionsTest.java @@ -110,8 +110,15 @@ public class TermsAndConditionsTest { List termsAndConditions = attributes.get(TermsAndConditions.USER_ATTRIBUTE); assertTrue("timestamp for terms acceptance was not stored in user attributes as " + TermsAndConditions.USER_ATTRIBUTE, termsAndConditions.size() == 1); + String timestamp = termsAndConditions.get(0); assertNotNull("expected non-null timestamp for terms acceptance in user attribute " - + TermsAndConditions.USER_ATTRIBUTE, termsAndConditions.get(0)); + + TermsAndConditions.USER_ATTRIBUTE, timestamp); + try { + Integer.parseInt(timestamp); + } + catch (NumberFormatException e) { + fail("timestamp for terms acceptance is not a valid integer: '" + timestamp + "'"); + } } @Test