Shibboleth HTTP Dataconnector: Difference between revisions

From NIEF Wiki
Jump to navigation Jump to search
(Created page with "==About== This is a sample of the [https://wiki.shibboleth.net/confluence/display/IDP30/HTTPConnector Shibboleth HTTP DataConnector]. ==IIR Sample== The URL seen on line 6 is...")
 
 
(2 intermediate revisions by 2 users not shown)
Line 23: Line 23:
         <![CDATA[
         <![CDATA[
         var logger = Java.type("org.slf4j.LoggerFactory").getLogger("net.shibboleth.idp.attribute");
         var logger = Java.type("org.slf4j.LoggerFactory").getLogger("net.shibboleth.idp.attribute");
        logger.info("Query Response = " + body);


         var HashSet = Java.type("java.util.HashSet");
         var HashSet = Java.type("java.util.HashSet");
Line 33: Line 32:
         var body = HttpClientSupport.toString(response.getEntity(), "UTF-8", 65536);
         var body = HttpClientSupport.toString(response.getEntity(), "UTF-8", 65536);


         //logger.info("Query Response = " + body);
         logger.info("Query Response = " + body);


         var result = JSON.parse(body);
         var result = JSON.parse(body);
Line 52: Line 51:
     </ResponseMapping>
     </ResponseMapping>


     <ResultCache expireAfterWrite="PT5M"/>
     <ResultCache expireAfterWrite="PT45M"/>
   </DataConnector></nowiki>
   </DataConnector></nowiki>
'''shibboleth.NonCachingHttpClient''' triggers a deprecation warning, but currently it's unclear what should replace this client, so we have not updated these instructions at this time.

Latest revision as of 17:40, 10 May 2021

About

This is a sample of the Shibboleth HTTP DataConnector.

IIR Sample

The URL seen on line 6 is a test URL that always returns false. You will also need to contact IIR to get an authorization code to use the service.

<DataConnector id="myHTTP" xsi:type="HTTP"
      httpClientRef="shibboleth.NonCachingHttpClient">
    <InputAttributeDefinition ref="EmailAddress" />
    <URLTemplate>
        <![CDATA[
        https://tca.iir.com/api/LookupTestNotCompleted?code=[get code from IIR]
        ]]>
    </URLTemplate>

    <BodyTemplate MIMEType="application/json">
        <![CDATA[
        { 'email': '$EmailAddress.get(0)' }
        ]]>
    </BodyTemplate>

    <ResponseMapping>
        <Script>
        <![CDATA[
        var logger = Java.type("org.slf4j.LoggerFactory").getLogger("net.shibboleth.idp.attribute");

        var HashSet = Java.type("java.util.HashSet");
        var HttpClientSupport = Java.type("net.shibboleth.utilities.java.support.httpclient.HttpClientSupport");
        var IdPAttribute = Java.type("net.shibboleth.idp.attribute.IdPAttribute");
        var StringAttributeValue = Java.type("net.shibboleth.idp.attribute.StringAttributeValue");
   
        // Limits length to 64k
        var body = HttpClientSupport.toString(response.getEntity(), "UTF-8", 65536);

        logger.info("Query Response = " + body);

        var result = JSON.parse(body);
  
        //logger.info("Parsed JSON Completed = " + result.completed);

        var attr = new IdPAttribute("CFRCertified");
        var values = new HashSet();
        if (result.completed) {
           values.add(new StringAttributeValue("true"));
        } else {
           values.add(new StringAttributeValue("false"));
        }
        attr.setValues(values);
        connectorResults.add(attr);
        ]]>
        </Script>
    </ResponseMapping>

    <ResultCache expireAfterWrite="PT45M"/>
  </DataConnector>

shibboleth.NonCachingHttpClient triggers a deprecation warning, but currently it's unclear what should replace this client, so we have not updated these instructions at this time.