This repository has been archived by the owner on Feb 19, 2021. It is now read-only.
forked from tachang/PySAML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SAMLMessages.py
43 lines (29 loc) · 1.62 KB
/
SAMLMessages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import xml.dom.minidom
class SAMLMessages():
def getSubjectXML(self, subject):
doc = xml.dom.minidom.Document()
subjectElement = doc.createElement("Subject")
# <NameIdentifier>
nameIDElement = doc.createElement("NameIdentifier")
nameIDElement.setAttribute("Format",subject.nameidformat)
nameIDText = doc.createTextNode(subject.name)
nameIDElement.appendChild(nameIDText)
subjectConfirmationElement = doc.createElement("SubjectConfirmation")
# Go through the list of confirmation methods
for confirmationMethod in subject.confirmationMethods:
confirmationMethodElement = doc.createElement("ConfirmationMethod")
confirmationMethod = doc.createTextNode(confirmationMethod)
confirmationMethodElement.appendChild(confirmationMethod)
subjectConfirmationElement.appendChild(confirmationMethodElement)
subjectElement.appendChild(nameIDElement)
subjectElement.appendChild(subjectConfirmationElement)
return subjectElement.toxml()
def getAuthenticationStatementXML(self, authStatement):
doc = xml.dom.minidom.Document()
authenticationStatementElement = doc.createElement("AuthenticationStatement")
authenticationStatementElement.setAttribute("AuthenticationMethod", authStatement.authMethod)
authenticationStatementElement.setAttribute("AuthenticationInstant", authStatement.authInstant)
# Turn the subject object into an XML node
subject = xml.dom.minidom.parseString(authStatement.subject.getXML())
authenticationStatementElement.appendChild(subject)
return authenticationStatementElement.toxml()