Skip to content

Instantly share code, notes, and snippets.

@trscavo
Last active January 19, 2017 14:00
Show Gist options
  • Save trscavo/eda65f36af3317252c7e to your computer and use it in GitHub Desktop.
Save trscavo/eda65f36af3317252c7e to your computer and use it in GitHub Desktop.
An XSL transform that takes a SAML V2.0 metadata file and produces a list of all entity attributes in plain text.
<?xml version="1.0" encoding="UTF-8"?>
<!--
extract_entity_attributes.xsl
An XSL transform that takes a SAML V2.0 metadata file and
produces a list of all entity attributes in plain text.
Usage:
$ MD_PATH=/path/to/saml/metadata.xml
$ SOURCE_LIB=/path/to/source/lib/dir
$ cat $MD_PATH | xsltproc $SOURCE_LIB/extract_entity_attributes.xsl -
The output is a text file with four space-separated fields per line:
entityAttributeName entityAttributeValue entityID registrarID
Note that an entity attribute may be multi-valued, in which case
there is one line of output for each entity attribute value with
the given name.
According to the Entity Attributes specification, any given
entity descriptor may have at most one mdattr:EntityAttributes
element and therefore this script simply ignores redundant
mdattr:EntityAttributes elements.
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
xmlns:mdattr="urn:oasis:names:tc:SAML:metadata:attribute"
xmlns:mdrpi="urn:oasis:names:tc:SAML:metadata:rpi"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
<!-- Output is plain text -->
<xsl:output method="text"/>
<!-- match on each entity attribute value -->
<xsl:template match="md:EntityDescriptor/md:Extensions/mdattr:EntityAttributes[position() = 1]/saml:Attribute
[@NameFormat = 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri']
/saml:AttributeValue">
<xsl:value-of select="../@Name"/>
<xsl:text> </xsl:text>
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
<xsl:value-of select="ancestor::md:EntityDescriptor/@entityID"/>
<xsl:text> </xsl:text>
<xsl:value-of select="ancestor::md:Extensions/mdrpi:RegistrationInfo/@registrationAuthority"/>
<xsl:text>&#10;</xsl:text>
</xsl:template>
<xsl:template match="text()">
<!-- do nothing -->
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment