Like other timestamps attribute value is now seconds since 1970.

This commit is contained in:
Thomas Raehalme 2016-01-08 14:21:43 +02:00
parent bca3893070
commit c4544e8caf
2 changed files with 10 additions and 3 deletions

View file

@ -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();
}

View file

@ -110,8 +110,15 @@ public class TermsAndConditionsTest {
List<String> 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