Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagexml
titleHTTP connector for a JSON-based web service
collapsetrue
 <DataConnector id="myHTTP" xsi:type="HTTP"
		httpClientRef="WebServiceHttpClient"
		httpClientSecurityParametersRef="ExampleOrgWSSecurity">
	<URLTemplate>
		<![CDATA[
		https://webservice.example.org/api/subject/$pathEscaper.escape($requestContext$resolutionContext.principal)/groups
		]]>
	</URLTemplate>

	<ResponseMapping>
		<Script>
		<![CDATA[
		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);
		var result = JSON.parse(body);
 
		var attr = new IdPAttribute("group");
		var values = new HashSet();
		if (result.groups != null) {
			for (var i=0; i<result.groups.length; i++) {
				values.add(new StringAttributeValue(result.groups[i].name));
			}
		}
		attr.setValues(values);
		connectorResults.add(attr);
		]]>
		</Script>
	</ResponseMapping>

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

...