Dependency and RDBMS QueryTemplate

Tom Poage tfpoage at ucdavis.edu
Mon Jan 22 15:50:25 EST 2018


Update.

> On Jan 19, 2018, at 7:33 AM, Tom Poage <tfpoage at ucdavis.edu> wrote:
...
> 
> <QueryTemplate>
> ...
> WHERE #if(queryAttribute && queryAttribute.values().size() > 0)queryAttribute.get(0)#{else}-1#end
> </QueryTemplate>
> 
> Or start looking at scripting this.

I couldn't get variants of an #if/#else/#end Velocity template to work. It always evaluated .get(0) on the empty attribute (throwing an exception), even when the Data Connector was not invoked.

Using an intermediate attribute with an out-of-domain default value for SQL query clause did seem to work. This allows the SQL to be expanded (cf. $foo.get(0)), even if it's not executed. No doubt, there are several other ways to do the following.

1. Predicate on relying party (only)

 <bean id="aPredicate" parent="shibboleth.Conditions.RelyingPartyId" c:candidate="https://sp.example.com/shibboleth"/>

2. Static Attribute, with a default/dummy value outside the domain of interest (positive integers)

    <DataConnector xsi:type="Static" id="staticAttributes">
        <Attribute id="nvlAttribute">
            <Value>-1</Value>
        </Attribute>
    </DataConnector>

3. Intermediate attribute

    <AttributeDefinition xsi:type="ScriptedAttribute" id="nvlAttribute" dependencyOnly="true">
        <Dependency ref="staticAttributes" />
        <Dependency ref="ucdLDAP" />
        <Script><![CDATA[
            if (typeof sourceAttribute !== "undefined" && sourceAttribute.getValues().isEmpty() == false) {
                // single-valued, if it exists
                nvlAttribute.addValue(sourceAttribute.getValues().get(0));
                if (nvlAttribute.getValues().contains("-1")) {
                    nvlAttribute.getValues().remove("-1");
                }
            }
        ]]></Script>
    </AttributeDefinition>

4. Data Connector

   <DataConnector xsi:type="RelationalDatabase"
                  id="aConnector"
                  activationConditionRef="aPredicate">
       <BeanManagedConnection>aDataSource</BeanManagedConnection>
       <QueryTemplate>
          <![CDATA[
                SELECT TRACK_2
                FROM SCHEMA.TABLE
                WHERE IDXCOL1 = $nvlAttribute.get(0)
          ]]>
       </QueryTemplate>
       <Column columnName="TRACK_2" attributeID="Track2" />
       <Dependency ref="nvlAttribute"/>
   </DataConnector>





More information about the users mailing list