[java-identity-provider] branch master updated: Switch over a minor use of long as Duration.

Scott Cantor cantor.2 at osu.edu
Wed Mar 20 15:13:16 EDT 2019


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

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

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

The following commit(s) were added to refs/heads/master by this push:
       new  8662428   Switch over a minor use of long as Duration.
8662428 is described below

commit 86624289c2f2f7d5529db513da52cff1a9a59385
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Mar 20 15:13:10 2019 -0400

    Switch over a minor use of long as Duration.
---
 .../resolver/spring/dc/impl/CacheConfigParser.java  | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/CacheConfigParser.java b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/CacheConfigParser.java
index 7447e84..51aba3f 100644
--- a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/CacheConfigParser.java
+++ b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/CacheConfigParser.java
@@ -17,6 +17,7 @@
 
 package net.shibboleth.idp.attribute.resolver.spring.dc.impl;
 
+import java.time.Duration;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
@@ -25,12 +26,12 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.xml.namespace.QName;
 
+import net.shibboleth.ext.spring.config.StringToDurationConverter;
 import net.shibboleth.idp.attribute.IdPAttribute;
 import net.shibboleth.idp.attribute.resolver.spring.impl.AttributeResolverNamespaceHandler;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 import net.shibboleth.utilities.java.support.xml.AttributeSupport;
-import net.shibboleth.utilities.java.support.xml.DOMTypeSupport;
 import net.shibboleth.utilities.java.support.xml.ElementSupport;
 
 import org.slf4j.Logger;
@@ -58,9 +59,11 @@ public class CacheConfigParser {
      * we do not own the implemented class */
     private static final long DEFAULT_CACHE_ENTRIES = 500;
 
-    /** Documented cache lifetime (4 hours).  Unfortunately it has to be here since
-     * we do not own the implemented class */
-    private static final long DEFAULT_TTL_MS = 4 * 60 * 60 * 1000;
+    /**
+     * Documented cache lifetime (4 hours).  Unfortunately it has to be here since
+     * we do not own the implemented class.
+     */
+    @Nonnull private static final Duration DEFAULT_TTL_MS = Duration.ofHours(4);
     
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(CacheConfigParser.class);
@@ -136,11 +139,11 @@ public class CacheConfigParser {
      * @param timeToLive duration string
      * @return the input as a long, or DEFAULT_TTL_MS
      */
-    private static long getTimeToLiveMs(@Nullable final String timeToLive) {
+    @Nonnull private static Duration getTimeToLive(@Nullable final String timeToLive) {
         if (timeToLive != null) {
-            return DOMTypeSupport.durationToLong(timeToLive);
+            return new StringToDurationConverter().convert(timeToLive);
         }  else {
-            return  DEFAULT_TTL_MS;   
+            return DEFAULT_TTL_MS;   
         }
     }
     
@@ -160,7 +163,7 @@ public class CacheConfigParser {
         
         return CacheBuilder.newBuilder()
                     .maximumSize(getMaxSize(maximumSize))
-                    .expireAfterAccess(getTimeToLiveMs(timeToLive), TimeUnit.MILLISECONDS)
+                    .expireAfterAccess(getTimeToLive(timeToLive).toMillis(), TimeUnit.MILLISECONDS)
                     .build();
     }
     
@@ -180,7 +183,7 @@ public class CacheConfigParser {
         
         return CacheBuilder.newBuilder()
                     .maximumSize(getMaxSize(maximumSize))
-                    .expireAfterWrite(getTimeToLiveMs(timeToLive), TimeUnit.MILLISECONDS)
+                    .expireAfterWrite(getTimeToLive(timeToLive).toMillis(), TimeUnit.MILLISECONDS)
                     .build();
     }
     

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


More information about the commits mailing list