[java-shib-attribute] branch main updated: IDP-1992 - Add a DateTimeAttributeValue type

Scott Cantor cantor.2 at osu.edu
Tue Aug 9 18:24:26 UTC 2022


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

scantor pushed a commit to branch main
in repository java-shib-attribute.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-attribute.git;a=commit;h=d701b304056deb60a2a8af3970ba1b0de3027607

The following commit(s) were added to refs/heads/main by this push:
     new d701b3040 IDP-1992 - Add a DateTimeAttributeValue type
d701b3040 is described below

commit d701b304056deb60a2a8af3970ba1b0de3027607
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Aug 9 14:24:23 2022 -0400

    IDP-1992 - Add a DateTimeAttributeValue type
    
    Port over changes to transcoder.
    Add encoder to schema/parser.
    Fix some stale tests.
---
 .../impl/SAML2DateTimeAttributeEncoderParser.java  | 45 ++++++++++++++
 .../impl/AttributeResolverNamespaceHandler.java    | 19 +++---
 .../schema/shibboleth-attribute-resolver.xsd       | 71 ++++++++++------------
 ...t.java => ScriptedDataConnectorParserTest.java} |  4 +-
 .../SAML2DateTimeAttributeEncoderParserTest.java   | 70 +++++++++++++++++++++
 .../idp/attribute/resolver/spring/customBean.xml   |  2 +
 .../spring/enc/resolver/saml1XmlObjectNoName.xml   |  6 +-
 .../spring/enc/resolver/saml2Base64NoName.xml      |  6 +-
 .../resolver/spring/enc/resolver/saml2DateTime.xml | 15 +++++
 .../spring/enc/resolver/saml2DateTimeDefault.xml   |  8 +++
 ...ml2StringNoName.xml => saml2DateTimeNoName.xml} |  2 +-
 .../spring/enc/resolver/saml2ScopedNoName.xml      |  2 +-
 .../spring/enc/resolver/saml2StringNoName.xml      |  2 +-
 .../spring/enc/resolver/saml2XmlObjectNoName.xml   |  6 +-
 .../impl/SAML2DateTimeAttributeTranscoder.java     | 16 ++++-
 .../impl/SAML2DateTimeAttributeTranscoderTest.java | 26 ++++++++
 16 files changed, 227 insertions(+), 73 deletions(-)

diff --git a/shib-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/enc/impl/SAML2DateTimeAttributeEncoderParser.java b/shib-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/enc/impl/SAML2DateTimeAttributeEncoderParser.java
new file mode 100644
index 000000000..60b9b4180
--- /dev/null
+++ b/shib-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/enc/impl/SAML2DateTimeAttributeEncoderParser.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.attribute.resolver.spring.enc.impl;
+
+import javax.annotation.Nonnull;
+import javax.xml.namespace.QName;
+
+import org.springframework.beans.factory.config.BeanReference;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+
+import net.shibboleth.idp.attribute.resolver.spring.enc.BaseSAML2AttributeEncoderParser;
+import net.shibboleth.idp.attribute.resolver.spring.impl.AttributeResolverNamespaceHandler;
+import net.shibboleth.idp.saml.attribute.transcoding.impl.SAML2DateTimeAttributeTranscoder;
+
+/**
+ * Spring Bean Definition Parser for {@link SAML2DateTimeAttributeTranscoder}.
+ */
+public class SAML2DateTimeAttributeEncoderParser extends BaseSAML2AttributeEncoderParser {
+
+    /** Schema type name.. */
+    @Nonnull public static final QName TYPE_NAME_RESOLVER = new QName(AttributeResolverNamespaceHandler.NAMESPACE, 
+            "SAML2DateTime");
+
+    /** {@inheritDoc} */
+    @Override
+    protected BeanReference buildTranscoder() {
+        return new RuntimeBeanReference("SAML2DateTimeTranscoder");
+    }
+
+}
\ No newline at end of file
diff --git a/shib-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/AttributeResolverNamespaceHandler.java b/shib-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/AttributeResolverNamespaceHandler.java
index 46352c942..95f14eb94 100644
--- a/shib-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/AttributeResolverNamespaceHandler.java
+++ b/shib-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/AttributeResolverNamespaceHandler.java
@@ -31,15 +31,14 @@ import net.shibboleth.idp.attribute.resolver.spring.ad.impl.SAML2NameIDAttribute
 import net.shibboleth.idp.attribute.resolver.spring.ad.impl.ScopedAttributeDefinitionParser;
 import net.shibboleth.idp.attribute.resolver.spring.ad.impl.ScriptedAttributeDefinitionParser;
 import net.shibboleth.idp.attribute.resolver.spring.ad.impl.SimpleAttributeDefinitionParser;
-import net.shibboleth.idp.attribute.resolver.spring.ad.impl.SubjectDerivedAttributeDefinitionParser;
 import net.shibboleth.idp.attribute.resolver.spring.ad.impl.DecryptedAttributeDefinitionParser;
+import net.shibboleth.idp.attribute.resolver.spring.ad.impl.SubjectDerivedAttributeDefinitionParser;
 import net.shibboleth.idp.attribute.resolver.spring.ad.impl.TemplateAttributeDefinitionParser;
 import net.shibboleth.idp.attribute.resolver.spring.ad.mapped.impl.MappedAttributeDefinitionParser;
 import net.shibboleth.idp.attribute.resolver.spring.ad.mapped.impl.SourceValueParser;
 import net.shibboleth.idp.attribute.resolver.spring.ad.mapped.impl.ValueMapParser;
 import net.shibboleth.idp.attribute.resolver.spring.dc.http.impl.HTTPDataConnectorParser;
 import net.shibboleth.idp.attribute.resolver.spring.dc.impl.ComputedIdDataConnectorParser;
-import net.shibboleth.idp.attribute.resolver.spring.dc.impl.ContextDerivedDataConnectorParser;
 import net.shibboleth.idp.attribute.resolver.spring.dc.impl.PairwiseIdDataConnectorParser;
 import net.shibboleth.idp.attribute.resolver.spring.dc.impl.ScriptedDataConnectorParser;
 import net.shibboleth.idp.attribute.resolver.spring.dc.impl.StaticDataConnectorParser;
@@ -53,6 +52,7 @@ import net.shibboleth.idp.attribute.resolver.spring.enc.impl.SAML1ScopedStringAt
 import net.shibboleth.idp.attribute.resolver.spring.enc.impl.SAML1StringAttributeEncoderParser;
 import net.shibboleth.idp.attribute.resolver.spring.enc.impl.SAML1XMLObjectAttributeEncoderParser;
 import net.shibboleth.idp.attribute.resolver.spring.enc.impl.SAML2Base64AttributeEncoderParser;
+import net.shibboleth.idp.attribute.resolver.spring.enc.impl.SAML2DateTimeAttributeEncoderParser;
 import net.shibboleth.idp.attribute.resolver.spring.enc.impl.SAML2ScopedStringAttributeEncoderParser;
 import net.shibboleth.idp.attribute.resolver.spring.enc.impl.SAML2StringAttributeEncoderParser;
 import net.shibboleth.idp.attribute.resolver.spring.enc.impl.SAML2XMLObjectAttributeEncoderParser;
@@ -64,14 +64,9 @@ public class AttributeResolverNamespaceHandler extends BaseSpringNamespaceHandle
     /** Namespace for this handler. */
     @Nonnull @NotEmpty public static final String NAMESPACE = "urn:mace:shibboleth:2.0:resolver";
 
-    /** Constructor. */
-    public AttributeResolverNamespaceHandler() {
-        super(NAMESPACE.replaceAll("\\:", "-"));
-    }
-    
     /** {@inheritDoc} */
     // Checkstyle: MethodLength OFF
-    @Override public void doInit() {
+    @Override public void init() {
         final BeanDefinitionParser parser = new AttributeResolverParser();
 
         registerBeanDefinitionParser(AttributeResolverParser.SCHEMA_TYPE, parser);
@@ -86,6 +81,7 @@ public class AttributeResolverNamespaceHandler extends BaseSpringNamespaceHandle
                 new PrincipalNameAttributeDefinitionParser());
         registerBeanDefinitionParser(RegexSplitAttributeDefinitionParser.TYPE_NAME_RESOLVER,
                 new RegexSplitAttributeDefinitionParser());
+
         registerBeanDefinitionParser(SubjectDerivedAttributeDefinitionParser.TYPE_NAME_RESOLVER,
                 new SubjectDerivedAttributeDefinitionParser());
         registerBeanDefinitionParser(ContextDerivedAttributeDefinitionParser.TYPE_NAME_RESOLVER,
@@ -120,8 +116,6 @@ public class AttributeResolverNamespaceHandler extends BaseSpringNamespaceHandle
         registerBeanDefinitionParser(ScriptedDataConnectorParser.TYPE_NAME_RESOLVER, new ScriptedDataConnectorParser());
         registerBeanDefinitionParser(StaticDataConnectorParser.TYPE_NAME_RESOLVER, new StaticDataConnectorParser());
         registerBeanDefinitionParser(StoredIdDataConnectorParser.TYPE_NAME_RESOLVER, new StoredIdDataConnectorParser());
-        registerBeanDefinitionParser(ContextDerivedDataConnectorParser.TYPE_NAME_RESOLVER,
-                new ContextDerivedDataConnectorParser());
         registerBeanDefinitionParser(SubjectDataConnectorParser.TYPE_NAME_RESOLVER, new SubjectDataConnectorParser());
         registerBeanDefinitionParser(StorageServiceDataConnectorParser.TYPE_NAME,
                 new StorageServiceDataConnectorParser());
@@ -148,7 +142,10 @@ public class AttributeResolverNamespaceHandler extends BaseSpringNamespaceHandle
         registerBeanDefinitionParser(SAML2StringAttributeEncoderParser.TYPE_NAME_RESOLVER,
                 new SAML2StringAttributeEncoderParser());
 
-         registerBeanDefinitionParser(SAML2XMLObjectAttributeEncoderParser.TYPE_NAME_RESOLVER,
+        registerBeanDefinitionParser(SAML2DateTimeAttributeEncoderParser.TYPE_NAME_RESOLVER,
+                new SAML2DateTimeAttributeEncoderParser());
+
+        registerBeanDefinitionParser(SAML2XMLObjectAttributeEncoderParser.TYPE_NAME_RESOLVER,
                 new SAML2XMLObjectAttributeEncoderParser());
     }
     // Checkstyle: MethodLength ON
diff --git a/shib-attribute-resolver-spring/src/main/resources/schema/shibboleth-attribute-resolver.xsd b/shib-attribute-resolver-spring/src/main/resources/schema/shibboleth-attribute-resolver.xsd
index 9e9ff8757..948e3bb3a 100644
--- a/shib-attribute-resolver-spring/src/main/resources/schema/shibboleth-attribute-resolver.xsd
+++ b/shib-attribute-resolver-spring/src/main/resources/schema/shibboleth-attribute-resolver.xsd
@@ -3,7 +3,7 @@
     xmlns:resolver="urn:mace:shibboleth:2.0:resolver"
     xmlns:sec="urn:mace:shibboleth:2.0:security"
     targetNamespace="urn:mace:shibboleth:2.0:resolver"
-    elementFormDefault="qualified" version="5.0">
+    elementFormDefault="qualified" version="4.3">
 
     <import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/>
     <import namespace="urn:mace:shibboleth:2.0:security" schemaLocation="http://shibboleth.net/schema/idp/shibboleth-security.xsd"/>
@@ -241,7 +241,7 @@
         <attribute name="profileContextStrategyRef" type="resolver:string">
             <annotation>
                 <documentation>
-                    DEPRECATED: A reference to a function to locate the profile context
+                    A reference to a function to locate the profile context
                 </documentation>
             </annotation>
         </attribute>
@@ -507,7 +507,7 @@
                         <documentation>The SAML 1 NameFormat of the NameID.</documentation>
                     </annotation>
                 </attribute>
-                <attribute name="nameIdQualifier" type="resolver:string" use="optional">
+                <attribute name="nameIdQualifier" type="resolver:string">
                     <annotation>
                         <documentation>The SAML 1 NameQualifier of the NameID.</documentation>
                     </annotation>
@@ -534,12 +534,12 @@
                         <documentation>The SAML 2 NameFormat of the NameID.</documentation>
                     </annotation>
                 </attribute>
-                <attribute name="nameIdQualifier" type="resolver:string" use="optional">
+                <attribute name="nameIdQualifier" type="resolver:string">
                     <annotation>
                         <documentation>The SAML 2 NameQualifier of the NameID.</documentation>
                     </annotation>
                 </attribute>
-                <attribute name="nameIdSPQualifier" type="resolver:string" use="optional">
+                <attribute name="nameIdSPQualifier" type="resolver:string">
                     <annotation>
                         <documentation>The SAML 2 SPNameQualifier of the NameID.</documentation>
                     </annotation>
@@ -1712,33 +1712,6 @@
         </complexContent>
     </complexType>
     
-    <complexType name="ContextDerived">
-        <annotation>
-            <documentation>A data connector to pull attributes from anywhere in the PRC tree</documentation>
-        </annotation>
-        <complexContent>
-            <extension base="resolver:BaseDataConnectorType">
-                <sequence>
-                    <element ref="resolver:FailoverDataConnector" minOccurs="0" maxOccurs="1"/>
-                </sequence>
-                <attribute name="noResultIsError" type="resolver:string">
-                    <annotation>
-                        <documentation>
-                            A boolean flag indicating whether an absence of any results will cause an error. If an error
-                            is raised and a failover dependency is defined for this connector the failover will be invoked.
-                            Default value is false.
-                        </documentation>
-                    </annotation>
-                </attribute>
-                <attribute name="attributesFunctionRef" type="resolver:string" use="required">
-                    <annotation>
-                        <documentation>The Function to generate the Attributes given a PRC</documentation>
-                    </annotation>
-                </attribute>
-            </extension>
-        </complexContent>
-    </complexType>
-    
     <complexType name="Subject">
         <annotation>
             <documentation>
@@ -2095,7 +2068,27 @@
                         <documentation>The SAML 2 NameFormat of the attribute.</documentation>
                     </annotation>
                 </attribute>
-                <attribute name="friendlyName" type="resolver:string" use="optional">
+                <attribute name="friendlyName" type="resolver:string">
+                    <annotation>
+                        <documentation>The SAML 2 FriendlyName of the attribute.</documentation>
+                    </annotation>
+                </attribute>
+            </extension>
+        </complexContent>
+    </complexType>
+
+    <complexType name="SAML2DateTime">
+        <annotation>
+            <documentation>Defines a SAML 2 date/time encoder for an attribute.</documentation>
+        </annotation>
+        <complexContent>
+            <extension base="resolver:BaseAttributeEncoderType">
+                <attribute name="nameFormat" type="resolver:string">
+                    <annotation>
+                        <documentation>The SAML 2 NameFormat of the attribute.</documentation>
+                    </annotation>
+                </attribute>
+                <attribute name="friendlyName" type="resolver:string">
                     <annotation>
                         <documentation>The SAML 2 FriendlyName of the attribute.</documentation>
                     </annotation>
@@ -2115,7 +2108,7 @@
                         <documentation>The SAML 2 NameFormat of the attribute.</documentation>
                     </annotation>
                 </attribute>
-                <attribute name="friendlyName" type="resolver:string" use="optional">
+                <attribute name="friendlyName" type="resolver:string">
                     <annotation>
                         <documentation>The SAML 2 FriendlyName of the attribute.</documentation>
                     </annotation>
@@ -2135,7 +2128,7 @@
                         <documentation>The SAML 2 NameFormat of the attribute.</documentation>
                     </annotation>
                 </attribute>
-                <attribute name="friendlyName" type="resolver:string" use="optional">
+                <attribute name="friendlyName" type="resolver:string">
                     <annotation>
                         <documentation>The SAML 2 FriendlyName of the attribute.</documentation>
                     </annotation>
@@ -2150,7 +2143,7 @@
         </annotation>
         <complexContent>
             <extension base="resolver:BaseAttributeEncoderType">
-                <attribute name="scopeType" type="resolver:string" use="optional">
+                <attribute name="scopeType" type="resolver:string">
                     <annotation>
                         <documentation>
                             The type of scoping to use for the encoded attribute. Valid values are "inline" or
@@ -2158,7 +2151,7 @@
                         </documentation>
                     </annotation>
                 </attribute>
-                <attribute name="scopeDelimiter" type="resolver:string" use="optional">
+                <attribute name="scopeDelimiter" type="resolver:string">
                     <annotation>
                         <documentation>
                             If scopeType is "inline", this is the delimeter used between the attribute value and
@@ -2166,7 +2159,7 @@
                         </documentation>
                     </annotation>
                 </attribute>
-                <attribute name="scopeAttribute" type="resolver:string" use="optional">
+                <attribute name="scopeAttribute" type="resolver:string">
                     <annotation>
                         <documentation>
                             If scopeType is "attribute", this is the name of the name of the attribute used to carry the
@@ -2204,7 +2197,7 @@
                         <documentation>The SAML 2 NameFormat of the attribute.</documentation>
                     </annotation>
                 </attribute>
-                <attribute name="friendlyName" type="resolver:string" use="optional">
+                <attribute name="friendlyName" type="resolver:string">
                     <annotation>
                         <documentation>The SAML 2 FriendlyName of the attribute.</documentation>
                     </annotation>
diff --git a/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/ScriptDataConnectorParserTest.java b/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/ScriptedDataConnectorParserTest.java
similarity index 97%
rename from shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/ScriptDataConnectorParserTest.java
rename to shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/ScriptedDataConnectorParserTest.java
index 4c4c53a58..28605d7a5 100644
--- a/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/ScriptDataConnectorParserTest.java
+++ b/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/dc/impl/ScriptedDataConnectorParserTest.java
@@ -37,10 +37,10 @@ import net.shibboleth.idp.attribute.resolver.testing.TestSources;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 
 /**
- * test for {@link ScriptedDataConnectorParser}
+ * Test for {@link ScriptedDataConnectorParser}
  */
 @SuppressWarnings("javadoc")
-public class ScriptDataConnectorParserTest extends BaseAttributeDefinitionParserTest {
+public class ScriptedDataConnectorParserTest extends BaseAttributeDefinitionParserTest {
 
     @Test public void resolver() throws ComponentInitializationException, ResolutionException {
 
diff --git a/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/enc/impl/SAML2DateTimeAttributeEncoderParserTest.java b/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/enc/impl/SAML2DateTimeAttributeEncoderParserTest.java
new file mode 100644
index 000000000..c498cb855
--- /dev/null
+++ b/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/enc/impl/SAML2DateTimeAttributeEncoderParserTest.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.attribute.resolver.spring.enc.impl;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Map;
+import java.util.function.Predicate;
+
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.testng.annotations.Test;
+
+import net.shibboleth.idp.attribute.resolver.spring.testing.BaseEncoderDefinitionParserTest;
+import net.shibboleth.idp.attribute.transcoding.AttributeTranscoderRegistry;
+import net.shibboleth.idp.saml.attribute.transcoding.SAML2AttributeTranscoder;
+import net.shibboleth.idp.saml.attribute.transcoding.impl.SAML2DateTimeAttributeTranscoder;
+
+/**
+ * Test for {@link SAML2DateTimeAttributeEncoderParser}.
+ */
+ at SuppressWarnings("javadoc")
+public class SAML2DateTimeAttributeEncoderParserTest extends BaseEncoderDefinitionParserTest {
+  
+    protected void testWithProperties(final boolean activation, final Boolean encodeType) {
+        
+        final Map<String,Object> rule =
+                getAttributeTranscoderRule("resolver/saml2DateTime.xml", activation, encodeType).getMap();
+
+        assertTrue(rule.get(AttributeTranscoderRegistry.PROP_TRANSCODER) instanceof SAML2DateTimeAttributeTranscoder);
+        assertEquals(rule.get(SAML2AttributeTranscoder.PROP_NAME), "Saml2DateTime_ATTRIBUTE_NAME");
+        assertEquals(rule.get(SAML2AttributeTranscoder.PROP_NAME_FORMAT), "Saml2DateTime_ATTRIBUTE_NAME_FORMAT");
+        assertEquals(rule.get(SAML2AttributeTranscoder.PROP_FRIENDLY_NAME), "Saml2DateTime_ATTRIBUTE_FRIENDLY_NAME");
+        assertEquals(activation, ((Predicate<?>) rule.get(AttributeTranscoderRegistry.PROP_CONDITION)).test(null));
+        checkEncodeType(rule, SAML2AttributeTranscoder.PROP_ENCODE_TYPE, encodeType!=null ? encodeType : false);
+    }
+    
+    @Test public void defaultCase() {
+        final Map<String,Object> rule = getAttributeTranscoderRule("resolver/saml2DateTimeDefault.xml").getMap();
+
+        assertTrue(rule.get(AttributeTranscoderRegistry.PROP_TRANSCODER) instanceof SAML2DateTimeAttributeTranscoder);
+        assertEquals(rule.get(SAML2AttributeTranscoder.PROP_NAME), "Saml2DateTimeName");
+        assertNull(rule.get(SAML2AttributeTranscoder.PROP_NAME_FORMAT));
+        assertNull(rule.get(SAML2AttributeTranscoder.PROP_FRIENDLY_NAME));
+        assertFalse(((Predicate<?>) rule.get(AttributeTranscoderRegistry.PROP_CONDITION)).test(null));
+        checkEncodeType(rule, SAML2AttributeTranscoder.PROP_ENCODE_TYPE, true);
+    }
+    
+    @Test(expectedExceptions={BeanDefinitionStoreException.class,})  public void noName() {
+        getAttributeTranscoderRule("resolver/saml2DateTimeNoName.xml");
+    }
+    
+}
\ No newline at end of file
diff --git a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/customBean.xml b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/customBean.xml
index dd6791596..4912f5f70 100644
--- a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/customBean.xml
+++ b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/customBean.xml
@@ -38,6 +38,8 @@
         class="net.shibboleth.idp.saml.attribute.transcoding.impl.SAML2ByteAttributeTranscoder" />
     <bean id="SAML2XMLObjectTranscoder"
         class="net.shibboleth.idp.saml.attribute.transcoding.impl.SAML2XMLObjectAttributeTranscoder" />
+    <bean id="SAML2DateTimeTranscoder"
+        class="net.shibboleth.idp.saml.attribute.transcoding.impl.SAML2DateTimeAttributeTranscoder" />
         
     <bean id="SAML1StringTranscoder"
         class="net.shibboleth.idp.saml.attribute.transcoding.impl.SAML1StringAttributeTranscoder" />
diff --git a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml1XmlObjectNoName.xml b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml1XmlObjectNoName.xml
index 20f41eec4..e8df11e6f 100644
--- a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml1XmlObjectNoName.xml
+++ b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml1XmlObjectNoName.xml
@@ -1,13 +1,9 @@
 <resolver:AttributeEncoder 
-    xsi:type="enc:SAML1XMLObject"
+    xsi:type="SAML1XMLObject"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 	xmlns:enc="urn:mace:shibboleth:2.0:attribute:encoder" 
 	xmlns:resolver="urn:mace:shibboleth:2.0:resolver"
 	xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd
-                        urn:mace:shibboleth:2.0:resolver:pc http://shibboleth.net/schema/idp/shibboleth-attribute-resolver-pc.xsd
-                        urn:mace:shibboleth:2.0:resolver:ad http://shibboleth.net/schema/idp/shibboleth-attribute-resolver-ad.xsd
-                        urn:mace:shibboleth:2.0:resolver:dc http://shibboleth.net/schema/idp/shibboleth-attribute-resolver-dc.xsd
-                        urn:mace:shibboleth:2.0:attribute:encoder http://shibboleth.net/schema/idp/shibboleth-attribute-encoder.xsd
                         urn:mace:shibboleth:2.0:security http://shibboleth.net/schema/idp/shibboleth-security.xsd"
 /> 
  
\ No newline at end of file
diff --git a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2Base64NoName.xml b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2Base64NoName.xml
index e877c3712..94b68a188 100644
--- a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2Base64NoName.xml
+++ b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2Base64NoName.xml
@@ -1,13 +1,9 @@
 <resolver:AttributeEncoder 
-    xsi:type="enc:SAML2Base64"
+    xsi:type="SAML2Base64"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 	xmlns:enc="urn:mace:shibboleth:2.0:attribute:encoder" 
 	xmlns:resolver="urn:mace:shibboleth:2.0:resolver"
 	xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd
-                        urn:mace:shibboleth:2.0:resolver:pc http://shibboleth.net/schema/idp/shibboleth-attribute-resolver-pc.xsd
-                        urn:mace:shibboleth:2.0:resolver:ad http://shibboleth.net/schema/idp/shibboleth-attribute-resolver-ad.xsd
-                        urn:mace:shibboleth:2.0:resolver:dc http://shibboleth.net/schema/idp/shibboleth-attribute-resolver-dc.xsd
-                        urn:mace:shibboleth:2.0:attribute:encoder http://shibboleth.net/schema/idp/shibboleth-attribute-encoder.xsd
                         urn:mace:shibboleth:2.0:security http://shibboleth.net/schema/idp/shibboleth-security.xsd"
  /> 
  
\ No newline at end of file
diff --git a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2DateTime.xml b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2DateTime.xml
new file mode 100644
index 000000000..ed9e57263
--- /dev/null
+++ b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2DateTime.xml
@@ -0,0 +1,15 @@
+<AttributeEncoder 
+    xsi:type="SAML2DateTime"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+	xmlns="urn:mace:shibboleth:2.0:resolver"
+	name="Saml2DateTime_ATTRIBUTE_NAME" 
+	nameFormat="Saml2DateTime_ATTRIBUTE_NAME_FORMAT"
+	friendlyName="Saml2DateTime_ATTRIBUTE_FRIENDLY_NAME"
+	encodeType="%{the.encodeType.property:false}"
+	xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd">
+
+    <ActivationConditionScript>
+        <Script>%{the.activation.property}</Script>
+    </ActivationConditionScript>
+    
+</AttributeEncoder>
\ No newline at end of file
diff --git a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2DateTimeDefault.xml b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2DateTimeDefault.xml
new file mode 100644
index 000000000..b722f8795
--- /dev/null
+++ b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2DateTimeDefault.xml
@@ -0,0 +1,8 @@
+<AttributeEncoder 
+    xsi:type="SAML2DateTime"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+	xmlns="urn:mace:shibboleth:2.0:resolver"
+	name="Saml2DateTimeName"
+	activationConditionRef="shibboleth.Predicate"
+	xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd" /> 
+ 
\ No newline at end of file
diff --git a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2StringNoName.xml b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2DateTimeNoName.xml
similarity index 96%
copy from shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2StringNoName.xml
copy to shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2DateTimeNoName.xml
index 2d6b5053e..8a58bdd61 100644
--- a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2StringNoName.xml
+++ b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2DateTimeNoName.xml
@@ -1,5 +1,5 @@
 <resolver:AttributeEncoder 
-    xsi:type="enc:SAML2String"
+    xsi:type="SAML2DateTime"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 	xmlns:enc="urn:mace:shibboleth:2.0:attribute:encoder" 
 	xmlns:resolver="urn:mace:shibboleth:2.0:resolver"
diff --git a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2ScopedNoName.xml b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2ScopedNoName.xml
index c6222ea51..afbc5c180 100644
--- a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2ScopedNoName.xml
+++ b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2ScopedNoName.xml
@@ -1,5 +1,5 @@
 <AttributeEncoder 
-    xsi:type="enc:SAML2ScopedString"
+    xsi:type="SAML2ScopedString"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="urn:mace:shibboleth:2.0:attribute:encoder" 
 	xmlns="urn:mace:shibboleth:2.0:resolver"
 	xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd
diff --git a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2StringNoName.xml b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2StringNoName.xml
index 2d6b5053e..d84184eed 100644
--- a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2StringNoName.xml
+++ b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2StringNoName.xml
@@ -1,5 +1,5 @@
 <resolver:AttributeEncoder 
-    xsi:type="enc:SAML2String"
+    xsi:type="SAML2String"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 	xmlns:enc="urn:mace:shibboleth:2.0:attribute:encoder" 
 	xmlns:resolver="urn:mace:shibboleth:2.0:resolver"
diff --git a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2XmlObjectNoName.xml b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2XmlObjectNoName.xml
index 5996a62f1..efdfc8017 100644
--- a/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2XmlObjectNoName.xml
+++ b/shib-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/enc/resolver/saml2XmlObjectNoName.xml
@@ -1,12 +1,8 @@
 <resolver:AttributeEncoder 
-    xsi:type="enc:SAML2XMLObject"
+    xsi:type="SAML2XMLObject"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 	xmlns:enc="urn:mace:shibboleth:2.0:attribute:encoder" 
 	xmlns:resolver="urn:mace:shibboleth:2.0:resolver"
 	xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd
-                        urn:mace:shibboleth:2.0:resolver:pc http://shibboleth.net/schema/idp/shibboleth-attribute-resolver-pc.xsd
-                        urn:mace:shibboleth:2.0:resolver:ad http://shibboleth.net/schema/idp/shibboleth-attribute-resolver-ad.xsd
-                        urn:mace:shibboleth:2.0:resolver:dc http://shibboleth.net/schema/idp/shibboleth-attribute-resolver-dc.xsd
-                        urn:mace:shibboleth:2.0:attribute:encoder http://shibboleth.net/schema/idp/shibboleth-attribute-encoder.xsd
                         urn:mace:shibboleth:2.0:security http://shibboleth.net/schema/idp/shibboleth-security.xsd" /> 
  
\ No newline at end of file
diff --git a/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2DateTimeAttributeTranscoder.java b/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2DateTimeAttributeTranscoder.java
index e645f6c53..66f6b1098 100644
--- a/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2DateTimeAttributeTranscoder.java
+++ b/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2DateTimeAttributeTranscoder.java
@@ -105,7 +105,7 @@ public class SAML2DateTimeAttributeTranscoder extends AbstractSAML2AttributeTran
             
             return getDateTimeValue(rule, ((XSString) object).getValue());
             
-        } else if (object instanceof XSInteger) {
+        } else if (object instanceof XSInteger && ((XSInteger) object).getValue() != null) {
 
             return getDateTimeValue(rule, ((XSInteger) object).getValue().longValue());
 
@@ -136,15 +136,25 @@ public class SAML2DateTimeAttributeTranscoder extends AbstractSAML2AttributeTran
      * @return converted result or null
      */
     @Nullable protected Instant getDateTimeValue(@Nonnull final TranscodingRule rule, @Nullable final String value) {
+        if (value == null) {
+            return null;
+        }
+        
         try {
             final Long longVal = Long.valueOf(value);
             if (longVal != null) {
                 return getDateTimeValue(rule, longVal);
             }
         } catch (final NumberFormatException e) {
+        }
+
+        try {
             return DOMTypeSupport.stringToInstant(value);
+        } catch (final IllegalArgumentException e) {
         }
-        
+
+        log.warn("{} rule unable to process string value as numeric or ISO format",
+                rule.getOrDefault(AttributeTranscoderRegistry.PROP_ID, String.class, "(none)"));
         return null;
     }
     
@@ -169,4 +179,4 @@ public class SAML2DateTimeAttributeTranscoder extends AbstractSAML2AttributeTran
         return null;
     }
 
-}
+}
\ No newline at end of file
diff --git a/shib-saml-attribute-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2DateTimeAttributeTranscoderTest.java b/shib-saml-attribute-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2DateTimeAttributeTranscoderTest.java
index da03a2b00..7afc95db2 100644
--- a/shib-saml-attribute-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2DateTimeAttributeTranscoderTest.java
+++ b/shib-saml-attribute-impl/src/test/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2DateTimeAttributeTranscoderTest.java
@@ -149,6 +149,32 @@ public class SAML2DateTimeAttributeTranscoderTest extends OpenSAMLInitBaseTestCa
         Assert.assertTrue(attr.getValues().isEmpty());
     }
 
+
+    @Test public void invalidDecode() throws Exception {
+        
+        final XSString stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
+        stringValue.setValue(STRING_INVALID);
+
+        final XSString stringValue2 = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
+        stringValue2.setValue(STRING_ISO);
+
+        final Attribute samlAttribute = attributeBuilder.buildObject();
+        samlAttribute.setName(ATTR_NAME);
+        samlAttribute.setNameFormat(ATTR_NAMEFORMAT);
+        samlAttribute.getAttributeValues().add(stringValue);
+        samlAttribute.getAttributeValues().add(stringValue2);
+
+        final Collection<TranscodingRule> rulesets = registry.getTranscodingRules(samlAttribute);
+        Assert.assertEquals(rulesets.size(), 1);
+        final TranscodingRule ruleset = rulesets.iterator().next();
+        
+        final IdPAttribute attr = TranscoderSupport.<Attribute>getTranscoder(ruleset).decode(null, samlAttribute, ruleset);
+        
+        Assert.assertNotNull(attr);
+        Assert.assertEquals(attr.getId(), ATTR_NAME);
+        Assert.assertEquals(attr.getValues().size(), 1);
+    }
+
     @Test public void emptyRequestedDecode() throws Exception {
         
         final RequestedAttribute samlAttribute = reqAttributeBuilder.buildObject();

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


More information about the commits mailing list