[java-identity-provider] branch maint-4 updated: IDP-1995 - Add support for DateTimeAttributeValue to supporting classes

Scott Cantor cantor.2 at osu.edu
Tue Aug 16 18:32:26 UTC 2022


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch maint-4
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=2f5e2a6066a59acc3cb7b95f8631b127a5248813

The following commit(s) were added to refs/heads/maint-4 by this push:
     new 2f5e2a606 IDP-1995 - Add support for DateTimeAttributeValue to supporting classes
2f5e2a606 is described below

commit 2f5e2a6066a59acc3cb7b95f8631b127a5248813
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Aug 16 14:32:23 2022 -0400

    IDP-1995 - Add support for DateTimeAttributeValue to supporting classes
    
    https://shibboleth.atlassian.net/browse/IDP-1995
    
    Enhance DateAttributePredicate.
---
 .../idp/profile/logic/DateAttributePredicate.java  | 14 +++++----
 .../profile/logic/DateAttributePredicateTest.java  | 35 ++++++++++++++++++----
 2 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/idp-profile-api/src/main/java/net/shibboleth/idp/profile/logic/DateAttributePredicate.java b/idp-profile-api/src/main/java/net/shibboleth/idp/profile/logic/DateAttributePredicate.java
index 568989935..1b3cf1539 100644
--- a/idp-profile-api/src/main/java/net/shibboleth/idp/profile/logic/DateAttributePredicate.java
+++ b/idp-profile-api/src/main/java/net/shibboleth/idp/profile/logic/DateAttributePredicate.java
@@ -17,6 +17,7 @@
 
 package net.shibboleth.idp.profile.logic;
 
+import net.shibboleth.idp.attribute.DateTimeAttributeValue;
 import net.shibboleth.idp.attribute.IdPAttribute;
 import net.shibboleth.idp.attribute.IdPAttributeValue;
 import net.shibboleth.idp.attribute.StringAttributeValue;
@@ -69,15 +70,13 @@ public class DateAttributePredicate extends AbstractAttributePredicate {
     /**
      * Create a new instance that performs date comparisons against the given attribute
      * using ISO date/time format parser by default.
-     * 
-     * <p>This is deprecated in favor of the Java 8 API version.</p>
      *
      * @param attribute Attribute name that provides candidate date values to test.
      */
-    @Deprecated
     public DateAttributePredicate(@Nonnull @NotEmpty @ParameterName(name="attribute") final String attribute) {
         // This isn't easily reproducible with Java 8's API, so I'm just going to
-        // deprecate the "no formatter supplied" scenario.
+        // deprecate the "no formatter supplied" scenario. In V5, this will stay, but
+        // null out the formatter so that only DateTime values are supported.
         this(attribute, ISODateTimeFormat.dateOptionalTimeParser());
     }
 
@@ -192,7 +191,10 @@ public class DateAttributePredicate extends AbstractAttributePredicate {
         
         String dateString;
         for (final IdPAttributeValue value : attribute.getValues()) {
-            if (value instanceof StringAttributeValue) {
+            if (value instanceof DateTimeAttributeValue &&
+                    ((DateTimeAttributeValue) value).getValue().plus(systemTimeOffset).isAfter(now)) {
+                    return true;
+            } else if (value instanceof StringAttributeValue) {
                 dateString = ((StringAttributeValue) value).getValue();
                 try {
                     if (dateTimeFormatter != null) {
@@ -212,4 +214,4 @@ public class DateAttributePredicate extends AbstractAttributePredicate {
         return false;
     }
     
-}
+}
\ No newline at end of file
diff --git a/idp-profile-api/src/test/java/net/shibboleth/idp/profile/logic/DateAttributePredicateTest.java b/idp-profile-api/src/test/java/net/shibboleth/idp/profile/logic/DateAttributePredicateTest.java
index 9a7d771d5..d26a299ad 100644
--- a/idp-profile-api/src/test/java/net/shibboleth/idp/profile/logic/DateAttributePredicateTest.java
+++ b/idp-profile-api/src/test/java/net/shibboleth/idp/profile/logic/DateAttributePredicateTest.java
@@ -17,6 +17,7 @@
 
 package net.shibboleth.idp.profile.logic;
 
+import net.shibboleth.idp.attribute.DateTimeAttributeValue;
 import net.shibboleth.idp.attribute.IdPAttribute;
 import net.shibboleth.idp.attribute.IdPAttributeValue;
 import net.shibboleth.idp.attribute.StringAttributeValue;
@@ -30,6 +31,7 @@ import org.opensaml.profile.context.ProfileRequestContext;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
+import java.time.Instant;
 import java.time.ZonedDateTime;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -46,7 +48,7 @@ public class DateAttributePredicateTest {
     
     private final java.time.format.DateTimeFormatter javaformatter =
             java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME;
-
+    
     @SuppressWarnings("deprecation")
     @DataProvider(name = "test-data-joda")
     public Object[][] provideTestDataJoda() {
@@ -139,7 +141,7 @@ public class DateAttributePredicateTest {
             final String attribute,
             final String[] values,
             final boolean expected) throws Exception {
-        assertEquals(predicate.test(createProfileRequestContext(attribute, values)), expected);
+        assertEquals(predicate.test(createProfileRequestContext(attribute, values, null)), expected);
     }
 
     @Test(dataProvider = "test-data-java")
@@ -148,16 +150,37 @@ public class DateAttributePredicateTest {
             final String attribute,
             final String[] values,
             final boolean expected) throws Exception {
-        assertEquals(predicate.test(createProfileRequestContext(attribute, values)), expected);
+        assertEquals(predicate.test(createProfileRequestContext(attribute, values, null)), expected);
     }
 
-    private ProfileRequestContext createProfileRequestContext(final String name, final String[] values) {
+    @Test
+    public void testDateTimeValues() {
+        final DateAttributePredicate predicate = new DateAttributePredicate("test");
+        
+        assertTrue(predicate.test(createProfileRequestContext("test", null,
+                new Instant[] {Instant.now().plus(java.time.Duration.ofMinutes(5))})));
+        
+        predicate.setOffset(java.time.Duration.ofMinutes(-10));
+        
+        assertFalse(predicate.test(createProfileRequestContext("test", null,
+                new Instant[] {Instant.now().plus(java.time.Duration.ofMinutes(5))})));
+    }
+    
+    
+    private ProfileRequestContext createProfileRequestContext(final String name, final String[] values, final Instant[] dtvalues) {
         final ProfileRequestContext prc = new ProfileRequestContext();
         final RelyingPartyContext rpc = new RelyingPartyContext();
         final IdPAttribute attribute = new IdPAttribute(name);
         final List<IdPAttributeValue> attributeValues = new ArrayList<>();
-        for (String value : values) {
-            attributeValues.add(new StringAttributeValue(value));
+        if (values != null) {
+            for (String value : values) {
+                attributeValues.add(new StringAttributeValue(value));
+            }
+        }
+        if (dtvalues != null) {
+            for (Instant value : dtvalues) {
+                attributeValues.add(new DateTimeAttributeValue(value));
+            }
         }
         attribute.setValues(attributeValues);
         final AttributeContext ac = new AttributeContext();

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list