[java-identity-provider] branch main updated: IDP-1995 - Add support for DateTimeAttributeValue to supporting classes
Scott Cantor
cantor.2 at osu.edu
Tue Aug 16 19:42:27 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=07019274a0ea579448288ca6fd4a5d3642fb0bcb
The following commit(s) were added to refs/heads/main by this push:
new 07019274a IDP-1995 - Add support for DateTimeAttributeValue to supporting classes
07019274a is described below
commit 07019274a0ea579448288ca6fd4a5d3642fb0bcb
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 | 27 ++++++++++++++++++-
.../profile/logic/DateAttributePredicateTest.java | 31 +++++++++++++++++++---
2 files changed, 53 insertions(+), 5 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 72cee2e31..7360c18c0 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;
@@ -63,6 +64,21 @@ public class DateAttributePredicate extends AbstractAttributePredicate {
/**
* Create a new instance that performs date comparisons against the given attribute
+<<<<<<< HEAD
+=======
+ * using ISO date/time format parser by default.
+ *
+ * @param attribute Attribute name that provides candidate date values to test.
+ */
+ public DateAttributePredicate(@Nonnull @NotEmpty @ParameterName(name="attribute") final String attribute) {
+ attributeName = Constraint.isNotNull(attribute, "Attribute cannot be null");
+ dateTimeFormatter = null;
+ systemTimeOffset = java.time.Duration.ZERO;
+ }
+
+ /**
+ * Create a new instance that performs date comparisons against the given attribute
+>>>>>>> 2f5e2a606 (IDP-1995 - Add support for DateTimeAttributeValue to supporting classes)
* using the given date parser.
*
* @param attribute Attribute name that provides candidate date values to test.
@@ -135,7 +151,14 @@ 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) {
+ if (dateTimeFormatter == null) {
+ log.warn("No DateTimeFormatter configured, ignoring string value");
+ continue;
+ }
dateString = ((StringAttributeValue) value).getValue();
try {
if (Instant.from(dateTimeFormatter.parse(dateString)).plus(systemTimeOffset).isAfter(now)) {
@@ -144,6 +167,8 @@ public class DateAttributePredicate extends AbstractAttributePredicate {
} catch (final DateTimeException e) {
log.warn("{} is not a valid date for the configured formatting string", dateString, e);
}
+ } else {
+ log.warn("Ignoring unsupported value type: {}", value.getClass().getName());
}
}
return false;
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 847cc6ac0..ba86b8baf 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;
@@ -26,6 +27,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;
@@ -90,16 +92,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