source: TI12-security/trunk/NDGSecurity/python/Tests/saml_eg.py @ 6988

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/Tests/saml_eg.py@6988
Revision 6988, 1.5 KB checked in by pjkersha, 9 years ago (diff)

Fix to WSGI SSL authn module for proxy cert support with Apache.

Line 
1from ndg.saml.saml2.core import (AttributeQuery, SAMLVersion, Issuer, Subject,
2                                 NameID, Attribute, XSStringAttributeValue)
3from uuid import uuid4
4from datetime import datetime
5
6attributeQuery = AttributeQuery()
7attributeQuery.version = SAMLVersion(SAMLVersion.VERSION_20)
8attributeQuery.id = str(uuid4())
9attributeQuery.issueInstant = datetime.utcnow()
10
11attributeQuery.issuer = Issuer()
12attributeQuery.issuer.format = Issuer.X509_SUBJECT
13attributeQuery.issuer.value = '/O=NDG/OU=BADC/CN=PolicyInformationPoint'
14               
15attributeQuery.subject = Subject() 
16attributeQuery.subject.nameID = NameID()
17attributeQuery.subject.nameID.format = NameID.X509_SUBJECT
18attributeQuery.subject.nameID.value = '/O=NDG/OU=BADC/CN=PhilipKershaw'
19
20# special case handling for 'LastName' attribute
21emailAddressAttribute = Attribute()
22emailAddressAttribute.name = "urn:esg:email:address"
23emailAddressAttribute.nameFormat = "%s#%s" % (
24                                XSStringAttributeValue.TYPE_NAME.namespaceURI,
25                                XSStringAttributeValue.TYPE_NAME.localPart)
26
27emailAddress = XSStringAttributeValue()
28emailAddress.value = 'pjk@somewhere.ac.uk'
29emailAddressAttribute.attributeValues.append(emailAddress)
30
31attributeQuery.attributes.append(emailAddressAttribute)
32
33# Convert to ElementTree representation
34from ndg.saml.xml.etree import AttributeQueryElementTree, prettyPrint
35
36elem = AttributeQueryElementTree.toXML(attributeQuery)
37
38# Serialise as string
39xmlOut = prettyPrint(elem)
40print(xmlOut)
41
42
Note: See TracBrowser for help on using the repository browser.