From c4544e8cafcd4d5484f880cf69b75b3770610295 Mon Sep 17 00:00:00 2001 From: Thomas Raehalme Date: Fri, 8 Jan 2016 14:21:43 +0200 Subject: [PATCH] Like other timestamps attribute value is now seconds since 1970. --- .../requiredactions/TermsAndConditions.java | 4 ++-- .../testsuite/actions/TermsAndConditionsTest.java | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) 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