[java-identity-provider] branch main updated: IDP-1994 - Removal of joda-time from APIs and dependency set

Scott Cantor cantor.2 at osu.edu
Tue Aug 16 16:55:38 UTC 2022


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

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

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

The following commit(s) were added to refs/heads/main by this push:
     new 669b8d89c IDP-1994 - Removal of joda-time from APIs and dependency set
669b8d89c is described below

commit 669b8d89c127ffdc13fcb97929e09be63624cd3e
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Aug 16 12:55:35 2022 -0400

    IDP-1994 - Removal of joda-time from APIs and dependency set
    
    https://shibboleth.atlassian.net/browse/IDP-1994
---
 .../idp/admin/impl/DoStorageOperationTest.java     |  4 +-
 idp-authn-impl/pom.xml                             |  5 --
 .../idp/authn/impl/ExternalAuthenticationImpl.java | 10 +--
 idp-profile-api/pom.xml                            |  5 --
 .../idp/profile/logic/DateAttributePredicate.java  | 81 +++-------------------
 .../profile/logic/DateAttributePredicateTest.java  | 80 ---------------------
 6 files changed, 12 insertions(+), 173 deletions(-)

diff --git a/idp-admin-impl/src/test/java/net/shibboleth/idp/admin/impl/DoStorageOperationTest.java b/idp-admin-impl/src/test/java/net/shibboleth/idp/admin/impl/DoStorageOperationTest.java
index 68a89abcb..86075dbfb 100644
--- a/idp-admin-impl/src/test/java/net/shibboleth/idp/admin/impl/DoStorageOperationTest.java
+++ b/idp-admin-impl/src/test/java/net/shibboleth/idp/admin/impl/DoStorageOperationTest.java
@@ -20,6 +20,7 @@ package net.shibboleth.idp.admin.impl;
 import java.io.IOException;
 import java.text.ParseException;
 import java.time.Duration;
+import java.time.Instant;
 import java.util.Map;
 import java.util.function.Supplier;
 
@@ -27,7 +28,6 @@ import javax.annotation.Nonnull;
 import jakarta.servlet.http.HttpServletResponse;
 import jakarta.servlet.http.HttpServletRequest;
 
-import org.joda.time.Instant;
 import org.opensaml.storage.StorageRecord;
 import org.opensaml.storage.impl.MemoryStorageService;
 import org.springframework.mock.web.MockHttpServletRequest;
@@ -160,7 +160,7 @@ public class DoStorageOperationTest {
     @Test
     public void successGet() throws IOException, ParseException {
         
-        final long exp = Instant.now().getMillis() + Duration.ofMinutes(15).toMillis();
+        final long exp = Instant.now().plus(Duration.ofMinutes(15)).toEpochMilli();
         
         storageService.create(CONTEXT, KEY, VALUE, exp);
         
diff --git a/idp-authn-impl/pom.xml b/idp-authn-impl/pom.xml
index a5fa79154..e44549358 100644
--- a/idp-authn-impl/pom.xml
+++ b/idp-authn-impl/pom.xml
@@ -185,11 +185,6 @@
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>
-        <!-- DEPRECATED - remove in V5 -->
-        <dependency>
-            <groupId>joda-time</groupId>
-            <artifactId>joda-time</artifactId>
-        </dependency>
 
         <!-- Provided Dependencies -->
         <dependency>
diff --git a/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/ExternalAuthenticationImpl.java b/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/ExternalAuthenticationImpl.java
index 24946d17c..74bcbee33 100644
--- a/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/ExternalAuthenticationImpl.java
+++ b/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/ExternalAuthenticationImpl.java
@@ -26,7 +26,6 @@ import java.util.function.Function;
 import javax.annotation.Nonnull;
 import javax.security.auth.Subject;
 
-import org.joda.time.DateTime;
 import org.opensaml.messaging.context.navigate.ChildContextLookup;
 import org.opensaml.profile.context.ProfileRequestContext;
 
@@ -41,8 +40,6 @@ import net.shibboleth.idp.authn.context.ExternalAuthenticationContext;
 import net.shibboleth.idp.consent.context.ConsentManagementContext;
 import net.shibboleth.idp.profile.context.RelyingPartyContext;
 import net.shibboleth.utilities.java.support.logic.Constraint;
-import net.shibboleth.utilities.java.support.primitive.DeprecationSupport;
-import net.shibboleth.utilities.java.support.primitive.DeprecationSupport.ObjectType;
 
 /**
  * Implementation of the {@link ExternalAuthentication} API that handles moving information in and out
@@ -137,12 +134,7 @@ public class ExternalAuthenticationImpl extends ExternalAuthentication {
         }
         
         attr = request.getAttribute(AUTHENTICATION_INSTANT_KEY);
-        if (attr != null && attr instanceof DateTime) {
-            // This is a V4 deprecation, do not remove until V5.
-            DeprecationSupport.warn(ObjectType.CLASS, DateTime.class.getName(), "ExternalAuthentication",
-                    Instant.class.getName());
-            extContext.setAuthnInstant(Instant.ofEpochMilli(((DateTime) attr).getMillis()));
-        } else if (attr != null && attr instanceof Instant) {
+        if (attr != null && attr instanceof Instant) {
             extContext.setAuthnInstant((Instant) attr);
         }
         
diff --git a/idp-profile-api/pom.xml b/idp-profile-api/pom.xml
index 6f2b575cd..1010438f1 100644
--- a/idp-profile-api/pom.xml
+++ b/idp-profile-api/pom.xml
@@ -88,11 +88,6 @@
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>
-        <!-- DEPRECATED - remove in V5 -->
-        <dependency>
-            <groupId>joda-time</groupId>
-            <artifactId>joda-time</artifactId>
-        </dependency>
 
         <!-- Provided Dependencies -->
         <dependency>
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..72cee2e31 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
@@ -24,16 +24,14 @@ import net.shibboleth.utilities.java.support.annotation.ParameterName;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
 import net.shibboleth.utilities.java.support.logic.Constraint;
-import net.shibboleth.utilities.java.support.primitive.DeprecationSupport;
-import net.shibboleth.utilities.java.support.primitive.DeprecationSupport.ObjectType;
 
-import org.joda.time.format.ISODateTimeFormat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
 
+import java.time.DateTimeException;
+import java.time.Duration;
 import java.time.Instant;
 import java.time.format.DateTimeFormatter;
 import java.util.Map;
@@ -55,53 +53,14 @@ public class DateAttributePredicate extends AbstractAttributePredicate {
     @Nonnull @NotEmpty private final String attributeName;
 
     /** Formatter used to parse string-based date attribute values. */
-    @Nullable private DateTimeFormatter dateTimeFormatter;
-    
-    /** Legacy formatter used to parse string-based date attribute values. */
-    @Deprecated @Nullable private org.joda.time.format.DateTimeFormatter legacyFormatter;
+    @Nonnull private final DateTimeFormatter dateTimeFormatter;
 
     /** Offset from system time used for date comparisons. */
-    @Nonnull private java.time.Duration systemTimeOffset;
+    @Nonnull private Duration systemTimeOffset;
     
     /** Result of predicate if attribute is missing or has no values. */
     private boolean resultIfMissing;
 
-    /**
-     * 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.
-        this(attribute, ISODateTimeFormat.dateOptionalTimeParser());
-    }
-
-    /**
-     * Create a new instance that performs date comparisons against the given attribute
-     * using the given date parser.
-     * 
-     * <p>This is deprecated in favor of the Java 8 API version.</p>
-     *
-     * @param attribute Attribute name that provides candidate date values to test.
-     * @param formatter Date/time parser.
-     */
-    @Deprecated
-    public DateAttributePredicate(@Nonnull @NotEmpty @ParameterName(name="attribute") final String attribute,
-            @Nonnull @ParameterName(name="formatter") final org.joda.time.format.DateTimeFormatter formatter) {
-        // This is a V4 deprecation, don't remove until V5.
-        DeprecationSupport.warnOnce(ObjectType.METHOD, "Joda-Time-based constructor",
-                DateAttributePredicate.class.getName(), "(see Javadoc)");
-        
-        attributeName = Constraint.isNotNull(attribute, "Attribute cannot be null");
-        legacyFormatter = Constraint.isNotNull(formatter, "Formatter cannot be null");
-        systemTimeOffset = java.time.Duration.ZERO;
-    }
-
     /**
      * Create a new instance that performs date comparisons against the given attribute
      * using the given date parser.
@@ -131,22 +90,6 @@ public class DateAttributePredicate extends AbstractAttributePredicate {
                 Constraint.isNotNull(formatString, "Format string cannot be null"));
         systemTimeOffset = java.time.Duration.ZERO;
     }
-    
-    /**
-     * Set the system time offset, which affects the reference date for comparisons.
-     * By default all comparisons are against system time, i.e. zero offset.
-     *
-     * @param offset System time offset. A negative value decreases the target date (sooner);
-     *                         a positive value increases the target date (later).
-     */
-    @Deprecated
-    public void setSystemTimeOffset(@Nonnull final org.joda.time.Duration offset) {
-        // This is a V4 deprecation, don't remove until V5.
-        DeprecationSupport.warnOnce(ObjectType.METHOD, "Joda-Time-based setSystemTimeOffset",
-                DateAttributePredicate.class.getName(), "setOffset");
-        systemTimeOffset = java.time.Duration.ofMillis(
-                Constraint.isNotNull(offset, "Offset cannot be null").getMillis());
-    }
 
     /**
      * Set the system time offset, which affects the reference date for comparisons.
@@ -195,21 +138,15 @@ public class DateAttributePredicate extends AbstractAttributePredicate {
             if (value instanceof StringAttributeValue) {
                 dateString = ((StringAttributeValue) value).getValue();
                 try {
-                    if (dateTimeFormatter != null) {
-                        if (Instant.from(dateTimeFormatter.parse(dateString)).plus(systemTimeOffset).isAfter(now)) {
-                            return true;
-                        }
-                    } else {
-                        if (legacyFormatter.parseDateTime(dateString).plus(systemTimeOffset.toMillis()).isAfterNow()) {
-                            return true;
-                        }
+                    if (Instant.from(dateTimeFormatter.parse(dateString)).plus(systemTimeOffset).isAfter(now)) {
+                        return true;
                     }
-                } catch (final RuntimeException e) {
-                    log.warn("{} is not a valid date for the configured date parser", dateString, e);
+                } catch (final DateTimeException e) {
+                    log.warn("{} is not a valid date for the configured formatting string", dateString, e);
                 }
             }
         }
         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..847cc6ac0 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
@@ -22,10 +22,6 @@ import net.shibboleth.idp.attribute.IdPAttributeValue;
 import net.shibboleth.idp.attribute.StringAttributeValue;
 import net.shibboleth.idp.attribute.context.AttributeContext;
 import net.shibboleth.idp.profile.context.RelyingPartyContext;
-import org.joda.time.DateTime;
-import org.joda.time.Duration;
-import org.joda.time.format.DateTimeFormatter;
-import org.joda.time.format.ISODateTimeFormat;
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
@@ -41,55 +37,10 @@ import static org.testng.Assert.*;
  * Unit test for {@link DateAttributePredicate}.
  */
 public class DateAttributePredicateTest {
-
-    private final DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
     
     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() {
-        return new Object[][] {
-                // Future date matches
-                new Object[] {
-                        new DateAttributePredicate("expirationDate"),
-                        "expirationDate",
-                        jodaDateStrings(Duration.standardDays(1)),
-                        true,
-                },
-                // Current date does not match
-                new Object[] {
-                        new DateAttributePredicate("expirationDate"),
-                        "expirationDate",
-                        jodaDateStrings(Duration.ZERO),
-                        false,
-                },
-                // Past date does not match
-                new Object[] {
-                        new DateAttributePredicate("expirationDate"),
-                        "expirationDate",
-                        jodaDateStrings(Duration.standardDays(-1)),
-                        false,
-                },
-                // Increase target date by 90 days
-                new Object[] {
-                        newJodaPredicate("expirationDate", Duration.standardDays(90)),
-                        "expirationDate",
-                        jodaDateStrings(Duration.standardDays(91)),
-                        true,
-                },
-                // Decrease target date by 30 days
-                // e.g. expiration warning case
-                new Object[] {
-                        newJodaPredicate("expirationDate", Duration.standardDays(-30)),
-                        "expirationDate",
-                        jodaDateStrings(Duration.standardDays(29)),
-                        false,
-                },
-        };
-    }
-
     @DataProvider(name = "test-data-java")
     public Object[][] provideTestDataJava() {
         return new Object[][] {
@@ -133,15 +84,6 @@ public class DateAttributePredicateTest {
     }
 
 
-    @Test(dataProvider = "test-data-joda")
-    public void testJodaTime(
-            final DateAttributePredicate predicate,
-            final String attribute,
-            final String[] values,
-            final boolean expected) throws Exception {
-        assertEquals(predicate.test(createProfileRequestContext(attribute, values)), expected);
-    }
-
     @Test(dataProvider = "test-data-java")
     public void testJavaTime(
             final DateAttributePredicate predicate,
@@ -168,21 +110,6 @@ public class DateAttributePredicateTest {
         return prc;
     }
 
-    /**
-     * Produces an array of date strings that are offsets from current system time.
-     *
-     * @param offsets One or more durations that are added to the current system time.
-     *
-     * @return Array of date strings, one for each provided offset.
-     */
-    private String[] jodaDateStrings(final Duration ... offsets) {
-        final String[] dates = new String[offsets.length];
-        for (int i = 0; i < offsets.length; i++) {
-            dates[i] = formatter.print(DateTime.now().plus(offsets[i]));
-        }
-        return dates;
-    }
-
     /**
      * Produces an array of date strings that are offsets from current system time.
      *
@@ -198,13 +125,6 @@ public class DateAttributePredicateTest {
         return dates;
     }
     
-    @SuppressWarnings("deprecation")
-    private DateAttributePredicate newJodaPredicate(final String attribute, final Duration offset) {
-        final DateAttributePredicate p = new DateAttributePredicate(attribute);
-        p.setSystemTimeOffset(offset);
-        return p;
-    }
-
     private DateAttributePredicate newJavaPredicate(final String attribute, final java.time.Duration offset) {
         final DateAttributePredicate p = new DateAttributePredicate(attribute, javaformatter);
         p.setOffset(offset);

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


More information about the commits mailing list