From 6731c55429b7e1e8011d6234e42c7fa3fa0e5665 Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Tue, 14 Nov 2017 11:27:57 -0200 Subject: [PATCH] [KEYCLOAK-5824] - Wrong usage of SimpleDateFormat --- .../policy/provider/time/TimePolicyProvider.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/authz/policy/common/src/main/java/org/keycloak/authorization/policy/provider/time/TimePolicyProvider.java b/authz/policy/common/src/main/java/org/keycloak/authorization/policy/provider/time/TimePolicyProvider.java index 6a383e3ada..e21a1c5dc5 100644 --- a/authz/policy/common/src/main/java/org/keycloak/authorization/policy/provider/time/TimePolicyProvider.java +++ b/authz/policy/common/src/main/java/org/keycloak/authorization/policy/provider/time/TimePolicyProvider.java @@ -32,21 +32,16 @@ public class TimePolicyProvider implements PolicyProvider { static String DEFAULT_DATE_PATTERN = "yyyy-MM-dd hh:mm:ss"; - private final SimpleDateFormat dateFormat; - - public TimePolicyProvider() { - this.dateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN); - } - @Override public void evaluate(Evaluation evaluation) { Policy policy = evaluation.getPolicy(); + SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN); Date actualDate = new Date(); try { String notBefore = policy.getConfig().get("nbf"); if (notBefore != null && !"".equals(notBefore)) { - if (actualDate.before(this.dateFormat.parse(format(notBefore)))) { + if (actualDate.before(dateFormat.parse(format(notBefore)))) { evaluation.deny(); return; } @@ -54,7 +49,7 @@ public class TimePolicyProvider implements PolicyProvider { String notOnOrAfter = policy.getConfig().get("noa"); if (notOnOrAfter != null && !"".equals(notOnOrAfter)) { - if (actualDate.after(this.dateFormat.parse(format(notOnOrAfter)))) { + if (actualDate.after(dateFormat.parse(format(notOnOrAfter)))) { evaluation.deny(); return; }