Like other timestamps attribute value is now seconds since 1970.
This commit is contained in:
parent
bca3893070
commit
c4544e8caf
2 changed files with 10 additions and 3 deletions
|
@ -8,6 +8,7 @@ import org.keycloak.Config;
|
||||||
import org.keycloak.authentication.RequiredActionContext;
|
import org.keycloak.authentication.RequiredActionContext;
|
||||||
import org.keycloak.authentication.RequiredActionFactory;
|
import org.keycloak.authentication.RequiredActionFactory;
|
||||||
import org.keycloak.authentication.RequiredActionProvider;
|
import org.keycloak.authentication.RequiredActionProvider;
|
||||||
|
import org.keycloak.common.util.Time;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.KeycloakSessionFactory;
|
import org.keycloak.models.KeycloakSessionFactory;
|
||||||
|
|
||||||
|
@ -62,8 +63,7 @@ public class TermsAndConditions implements RequiredActionProvider, RequiredActio
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
|
context.getUser().setAttribute(USER_ATTRIBUTE, Arrays.asList(Integer.toString(Time.currentTime())));
|
||||||
context.getUser().setAttribute(USER_ATTRIBUTE, Arrays.asList(dateTimeFormat.format(new Date())));
|
|
||||||
|
|
||||||
context.success();
|
context.success();
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,8 +110,15 @@ public class TermsAndConditionsTest {
|
||||||
List<String> termsAndConditions = attributes.get(TermsAndConditions.USER_ATTRIBUTE);
|
List<String> termsAndConditions = attributes.get(TermsAndConditions.USER_ATTRIBUTE);
|
||||||
assertTrue("timestamp for terms acceptance was not stored in user attributes as "
|
assertTrue("timestamp for terms acceptance was not stored in user attributes as "
|
||||||
+ TermsAndConditions.USER_ATTRIBUTE, termsAndConditions.size() == 1);
|
+ TermsAndConditions.USER_ATTRIBUTE, termsAndConditions.size() == 1);
|
||||||
|
String timestamp = termsAndConditions.get(0);
|
||||||
assertNotNull("expected non-null timestamp for terms acceptance in user attribute "
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue