Changes between Version 5 and Version 6 of SAML2.0


Ignore:
Timestamp:
01/06/10 14:21:12 (9 years ago)
Author:
pjkersha
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SAML2.0

    v5 v6  
    44The code uses !ElementTree for serialisation to and parsing from XML but an API makes it easily extendable to use other Python XML parsers if desired. 
    55 
     6== Example Code == 
     7{{{ 
     8from ndg.saml.saml2.core import (AttributeQuery, SAMLVersion, Issuer, Subject, 
     9                                 NameID, Attribute, XSStringAttributeValue) 
     10from uuid import uuid4 
     11from datetime import datetime 
     12 
     13attributeQuery = AttributeQuery() 
     14attributeQuery.version = SAMLVersion(SAMLVersion.VERSION_20) 
     15attributeQuery.id = str(uuid4()) 
     16attributeQuery.issueInstant = datetime.utcnow() 
     17 
     18attributeQuery.issuer = Issuer() 
     19attributeQuery.issuer.format = Issuer.X509_SUBJECT 
     20attributeQuery.issuer.value = '/O=NDG/OU=BADC/CN=PolicyInformationPoint' 
     21                 
     22attributeQuery.subject = Subject()   
     23attributeQuery.subject.nameID = NameID() 
     24attributeQuery.subject.nameID.format = NameID.X509_SUBJECT 
     25attributeQuery.subject.nameID.value = '/O=NDG/OU=BADC/CN=PhilipKershaw' 
     26 
     27# special case handling for 'LastName' attribute 
     28emailAddressAttribute = Attribute() 
     29emailAddressAttribute.name = "urn:esg:email:address" 
     30emailAddressAttribute.nameFormat = "%s#%s" % ( 
     31                                XSStringAttributeValue.TYPE_NAME.namespaceURI, 
     32                                XSStringAttributeValue.TYPE_NAME.localPart) 
     33 
     34emailAddress = XSStringAttributeValue() 
     35emailAddress.value = 'pjk@somewhere.ac.uk' 
     36emailAddressAttribute.attributeValues.append(emailAddress) 
     37 
     38attributeQuery.attributes.append(emailAddressAttribute) 
     39 
     40# Convert to ElementTree representation 
     41from ndg.saml.xml.etree import AttributeQueryElementTree, prettyPrint 
     42 
     43elem = AttributeQueryElementTree.toXML(attributeQuery) 
     44 
     45# Serialise as string 
     46xmlOut = prettyPrint(elem) 
     47print(xmlOut) 
     48}}} 
     49 
     50Produces: 
     51 
     52{{{ 
     53<samlp:AttributeQuery xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" Version="2.0" IssueInstant="2010-06-01T13:19:50.690263Z" ID="1c15e748-0f74-41f1-848c-1fbdfeef2a06"> 
     54    <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Format="urn:oasis:names:tc:SAML:1.1:nameid-format:x509SubjectName">/O=NDG/OU=BADC/CN=PolicyInformationPoint</saml:Issuer> 
     55    <saml:Subject xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"> 
     56        <saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:x509SubjectName">/O=NDG/OU=BADC/CN=PhilipKershaw</saml:NameID> 
     57    </saml:Subject> 
     58    <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Name="urn:esg:email:address" NameFormat="http://www.w3.org/2001/XMLSchema#string"> 
     59        <saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema">pjk@somewhere.ac.uk</saml:AttributeValue> 
     60    </saml:Attribute> 
     61</samlp:AttributeQuery> 
     62}}} 
    663== Repository == 
    764http://proj.badc.rl.ac.uk/ndg/browser/TI12-security/trunk/ndg_saml