Changeset 6543
- Timestamp:
- 09/02/10 15:31:24 (11 years ago)
- Location:
- TI12-security/trunk/ndg_security_saml
- Files:
-
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/ndg_security_saml
-
Property
svn:ignore
set to
build
dist
-
Property
svn:ignore
set to
-
TI12-security/trunk/ndg_security_saml/.pydevproject
r6278 r6543 5 5 <pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.5</pydev_property> 6 6 <pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property> 7 <pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH"> 8 <path>/ndg_security_saml</path> 9 </pydev_pathproperty> 7 10 </pydev_project> -
TI12-security/trunk/ndg_security_saml/saml/common/__init__.py
r6069 r6543 32 32 class SAMLObject(object): 33 33 """Base class for all SAML types""" 34 __slots__ = () 35 34 36 @classmethod 35 37 def fromXML(cls, xmlObject): -
TI12-security/trunk/ndg_security_saml/saml/saml2/core.py
r6069 r6543 30 30 __revision__ = "$Id: $" 31 31 from datetime import datetime 32 from urlparse import urlsplit, urlunsplit 33 import urllib 32 34 33 35 from saml.common import SAMLObject, SAMLVersion … … 73 75 BASIC = "urn:oasis:names:tc:SAML:2.0:attrname-format:basic" 74 76 77 __slots__ = ( 78 '__name', 79 '__nameFormat', 80 '__friendlyName', 81 '__attributeValues' 82 ) 83 75 84 def __init__(self): 76 85 """Initialise Attribute Class attributes""" … … 140 149 '''SAML 2.0 Core Statement. Abstract base class which all statement 141 150 types must implement.''' 151 __slots__ = () 142 152 143 153 # Element local name … … 160 170 class AttributeStatement(Statement): 161 171 '''SAML 2.0 Core AttributeStatement''' 162 172 __slots__ = ('__attributes', '__encryptedAttributes') 173 163 174 def __init__(self): 164 175 self.__attributes = TypedList(Attribute) … … 182 193 183 194 def _get_attributes(self): 184 '''@return the attributes expressed in this statement195 '''@return: the attributes expressed in this statement 185 196 ''' 186 197 return self.__attributes … … 189 200 190 201 def _get_encryptedAttributes(self): 191 '''@return the encrypted attribtues expressed in this statement202 '''@return: the encrypted attribtues expressed in this statement 192 203 ''' 193 204 return self.__encryptedAttributes … … 229 240 '''Gets the time when the authentication took place. 230 241 231 @return the time when the authentication took place242 @return: the time when the authentication took place 232 243 ''' 233 244 raise NotImplementedError() … … 236 247 '''Sets the time when the authentication took place. 237 248 238 @param newAuthnInstantthe time when the authentication took place249 @param value: the time when the authentication took place 239 250 ''' 240 251 raise NotImplementedError() … … 244 255 authority. 245 256 246 @return the session index between the principal and the authenticating257 @return: the session index between the principal and the authenticating 247 258 authority 248 259 ''' … … 253 264 authority. 254 265 255 @param newIndexthe session index between the principal and the266 @param value: the session index between the principal and the 256 267 authenticating authority 257 268 ''' … … 262 273 authority ends. 263 274 264 @return the time when the session between the principal and the SAML275 @return: the time when the session between the principal and the SAML 265 276 authority ends 266 277 ''' … … 271 282 authority ends. 272 283 273 @param newSessionNotOnOrAfterthe time when the session between the284 @param value: the time when the session between the 274 285 principal and the SAML authority ends 275 286 ''' … … 280 291 was authenticated. 281 292 282 @return the DNS domain and IP address of the system where the principal293 @return: the DNS domain and IP address of the system where the principal 283 294 was authenticated 284 295 ''' … … 289 300 was authenticated. 290 301 291 @param newLocalitythe DNS domain and IP address of the system where302 @param value: the DNS domain and IP address of the system where 292 303 the principal was authenticated 293 304 ''' … … 297 308 '''Gets the context used to authenticate the subject. 298 309 299 @return the context used to authenticate the subject310 @return: the context used to authenticate the subject 300 311 ''' 301 312 raise NotImplementedError() … … 304 315 '''Sets the context used to authenticate the subject. 305 316 306 @param newAuthnContextthe context used to authenticate the subject317 @param value: the context used to authenticate the subject 307 318 ''' 308 319 raise NotImplementedError() … … 339 350 Get URI of the resource to which authorization is saught. 340 351 341 @return URI of the resource to which authorization is saught352 @return: URI of the resource to which authorization is saught 342 353 ''' 343 354 raise NotImplementedError() … … 347 358 Sets URI of the resource to which authorization is saught. 348 359 349 @param newResourceURIURI of the resource to which authorization is360 @param value: URI of the resource to which authorization is 350 361 saught 351 362 ''' … … 356 367 Gets the decision of the authorization request. 357 368 358 @return the decision of the authorization request369 @return: the decision of the authorization request 359 370 ''' 360 371 raise NotImplementedError() … … 364 375 Sets the decision of the authorization request. 365 376 366 @param newDecisionthe decision of the authorization request377 @param value: the decision of the authorization request 367 378 ''' 368 379 raise NotImplementedError() … … 372 383 Gets the actions authorized to be performed. 373 384 374 @return the actions authorized to be performed385 @return: the actions authorized to be performed 375 386 ''' 376 387 raise NotImplementedError() … … 382 393 authorization decision. 383 394 384 @return the SAML assertion the authority relied on when making the395 @return: the SAML assertion the authority relied on when making the 385 396 authorization decision 386 397 ''' … … 392 403 authorization decision. 393 404 394 @param newEvidencethe SAML assertion the authority relied on when405 @param value: the SAML assertion the authority relied on when 395 406 making the authorization decision 396 407 ''' … … 416 427 TYPE_LOCAL_NAME, 417 428 SAMLConstants.SAML20_PREFIX) 418 429 __slots__ = ( 430 '__qname', 431 '__baseID', 432 '__nameID', 433 '__encryptedID', 434 '__subjectConfirmations' 435 ) 436 419 437 def __init__(self, 420 438 namespaceURI=SAMLConstants.SAML20_NS, 421 439 elementLocalName=DEFAULT_ELEMENT_LOCAL_NAME, 422 440 namespacePrefix=SAMLConstants.SAML20_PREFIX): 423 '''@param namespaceURI the namespace the element is in424 @param elementLocalName the local name of the XML element this Object441 '''@param namespaceURI: the namespace the element is in 442 @param elementLocalName: the local name of the XML element this Object 425 443 represents 426 @param namespacePrefix the prefix for the given namespace444 @param namespacePrefix: the prefix for the given namespace 427 445 ''' 428 446 self.__qname = QName(namespaceURI, … … 481 499 encryptedID = property(fget=_getEncryptedID, 482 500 fset=_setEncryptedID, 483 doc="EncryptedID's Docstring") 501 doc="EncryptedID's Docstring") 502 484 503 def _getSubjectConfirmations(self): 485 504 return self.__subjectConfirmations … … 487 506 subjectConfirmations = property(fget=_getSubjectConfirmations, 488 507 doc="Subject Confirmations") 508 489 509 def getOrderedChildren(self): 490 510 children = [] … … 544 564 ENCRYPTED = "urn:oasis:names:tc:SAML:2.0:nameid-format:encrypted" 545 565 566 __slots__ = ( 567 '__qname', 568 '__name', 569 '__nameQualifier', 570 '__spNameQualifier', 571 '__format', 572 '__spProvidedID', 573 '__value' 574 ) 575 546 576 def __init__(self, namespaceURI, elementLocalName, namespacePrefix): 547 '''@param namespaceURI the namespace the element is in548 @param elementLocalName the local name of the XML element this Object577 '''@param namespaceURI: the namespace the element is in 578 @param elementLocalName: the local name of the XML element this Object 549 579 represents 550 @param namespacePrefix the prefix for the given namespace580 @param namespacePrefix: the prefix for the given namespace 551 581 ''' 552 582 self.__qname = QName(namespaceURI, elementLocalName, namespacePrefix) … … 684 714 SAMLConstants.SAML20_PREFIX) 685 715 716 __slots__ = () 717 686 718 def __init__(self, 687 719 namespaceURI=SAMLConstants.SAML20_NS, … … 718 750 NOT_ON_OR_AFTER_ATTRIB_NAME = "NotOnOrAfter" 719 751 752 __slots__ = ( 753 '__conditions', 754 '__notBefore', 755 '__notOnOrAfter' 756 ) 757 720 758 def __init__(self): 721 759 … … 732 770 '''Get the date/time before which the assertion is invalid. 733 771 734 @return the date/time before which the assertion is invalid'''772 @return: the date/time before which the assertion is invalid''' 735 773 return self.__notBefore 736 774 … … 738 776 '''Sets the date/time before which the assertion is invalid. 739 777 740 @param newNotBeforethe date/time before which the assertion is invalid778 @param value: the date/time before which the assertion is invalid 741 779 ''' 742 780 if not isinstance(value, datetime): … … 748 786 '''Gets the date/time on, or after, which the assertion is invalid. 749 787 750 @return the date/time on, or after, which the assertion is invalid'788 @return: the date/time on, or after, which the assertion is invalid' 751 789 ''' 752 790 return self.__notBefore … … 755 793 '''Sets the date/time on, or after, which the assertion is invalid. 756 794 757 @param newNotOnOrAfterthe date/time on, or after, which the assertion795 @param value: the date/time on, or after, which the assertion 758 796 is invalid 759 797 ''' … … 766 804 '''Gets all the conditions on the assertion. 767 805 768 @return all the conditions on the assertion806 @return: all the conditions on the assertion 769 807 ''' 770 808 return self.__conditions … … 776 814 '''Gets the audience restriction conditions for the assertion. 777 815 778 @return the audience restriction conditions for the assertion816 @return: the audience restriction conditions for the assertion 779 817 ''' 780 818 raise NotImplementedError() … … 783 821 '''Gets the OneTimeUse condition for the assertion. 784 822 785 @return the OneTimeUse condition for the assertion823 @return: the OneTimeUse condition for the assertion 786 824 ''' 787 825 raise NotImplementedError() … … 790 828 '''Gets the ProxyRestriction condition for the assertion. 791 829 792 @return the ProxyRestriction condition for the assertion830 @return: the ProxyRestriction condition for the assertion 793 831 ''' 794 832 raise NotImplementedError() … … 819 857 Gets the list of all child elements attached to this advice. 820 858 821 @return the list of all child elements attached to this advice859 @return: the list of all child elements attached to this advice 822 860 ''' 823 861 raise NotImplementedError() … … 826 864 '''Gets the list of AssertionID references used as advice. 827 865 828 @return the list of AssertionID references used as advice866 @return: the list of AssertionID references used as advice 829 867 ''' 830 868 raise NotImplementedError() … … 833 871 '''Gets the list of AssertionURI references used as advice. 834 872 835 @return the list of AssertionURI references used as advice873 @return: the list of AssertionURI references used as advice 836 874 ''' 837 875 raise NotImplementedError() … … 840 878 '''Gets the list of Assertions used as advice. 841 879 842 @return the list of Assertions used as advice880 @return: the list of Assertions used as advice 843 881 ''' 844 882 raise NotImplementedError() … … 847 885 '''Gets the list of EncryptedAssertions used as advice. 848 886 849 @return the list of EncryptedAssertions used as advice887 @return: the list of EncryptedAssertions used as advice 850 888 ''' 851 889 raise NotImplementedError() … … 885 923 ID_ATTRIB_NAME = "ID" 886 924 925 __slots__ = ( 926 '__version', 927 '__issueInstant', 928 '__id', 929 '__issuer', 930 '__subject', 931 '__conditions', 932 '__advice', 933 '__statements', 934 '__authnStatements', 935 '__authzDecisionStatements', 936 '__attributeStatements' 937 ) 938 887 939 def __init__(self): 888 940 # Base class initialisation … … 905 957 906 958 def _get_version(self): 907 '''@return the SAML Version of this assertion.959 '''@return: the SAML Version of this assertion. 908 960 ''' 909 961 return self.__version 910 962 911 963 def _set_version(self, version): 912 '''@param version the SAML Version of this assertion964 '''@param version: the SAML Version of this assertion 913 965 ''' 914 966 if not isinstance(version, SAMLVersion): … … 925 977 '''Gets the issue instance of this assertion. 926 978 927 @return the issue instance of this assertion'''979 @return: the issue instance of this assertion''' 928 980 return self.__issueInstant 929 981 … … 931 983 '''Sets the issue instance of this assertion. 932 984 933 @param newIssueInstancethe issue instance of this assertion985 @param issueInstant: the issue instance of this assertion 934 986 ''' 935 987 if not isinstance(issueInstant, datetime): … … 946 998 '''Sets the ID of this assertion. 947 999 948 @return the ID of this assertion1000 @return: the ID of this assertion 949 1001 ''' 950 1002 return self.__id … … 953 1005 '''Sets the ID of this assertion. 954 1006 955 @param newIDthe ID of this assertion1007 @param _id: the ID of this assertion 956 1008 ''' 957 1009 if not isinstance(_id, basestring): … … 1066 1118 DEFAULT_ELEMENT_LOCAL_NAME, 1067 1119 SAMLConstants.SAML20_PREFIX) 1120 __slots__ = () 1068 1121 1069 1122 … … 1081 1134 DEFAULT_FORMAT = "%s#%s" % (SAMLConstants.XSD_NS, TYPE_LOCAL_NAME) 1082 1135 1136 __slots__ = ('__value',) 1137 1083 1138 def __init__(self): 1084 1139 self.__value = None … … 1115 1170 TYPE_LOCAL_NAME, 1116 1171 SAMLConstants.SAML20P_PREFIX) 1172 1173 __slots__ = ('__unknownChildren', '__qname') 1117 1174 1118 1175 def __init__(self): … … 1166 1223 SAMLConstants.SAML20P_PREFIX) 1167 1224 1225 __slots__ = ('__value', '__qname') 1226 1168 1227 def __init__(self): 1169 1228 # Value attribute URI. … … 1301 1360 "urn:oasis:names:tc:SAML:2.0:status:UnsupportedBinding" 1302 1361 1362 __slots__ = ('__value', '__childStatusCode', '__qname') 1363 1303 1364 def __init__(self): 1304 1365 # Value attribute URI. … … 1370 1431 SAMLConstants.SAML20P_PREFIX) 1371 1432 1433 __slots__ = ('__statusCode', '__statusMessage', '__statusDetail', '__qname') 1434 1372 1435 def __init__(self): 1373 1436 # StatusCode element. … … 1400 1463 Gets the Code of this Status. 1401 1464 1402 @return Status StatusCode1465 @return: Status StatusCode 1403 1466 ''' 1404 1467 return self.__statusCode … … 1408 1471 Sets the Code of this Status. 1409 1472 1410 @param newStatusCodethe Code of this Status1473 @param value: the Code of this Status 1411 1474 ''' 1412 1475 if not isinstance(value, StatusCode): … … 1424 1487 Gets the Message of this Status. 1425 1488 1426 @return Status StatusMessage1489 @return: Status StatusMessage 1427 1490 ''' 1428 1491 return self.__statusMessage … … 1432 1495 Sets the Message of this Status. 1433 1496 1434 @param newStatusMessagethe Message of this Status1497 @param value: the Message of this Status 1435 1498 ''' 1436 1499 if not isinstance(value, StatusMessage): … … 1448 1511 Gets the Detail of this Status. 1449 1512 1450 @return Status StatusDetail1513 @return: Status StatusDetail 1451 1514 ''' 1452 1515 return self.__statusDetail … … 1456 1519 Sets the Detail of this Status. 1457 1520 1458 @param newStatusDetailthe Detail of this Status1521 @param value: the Detail of this Status 1459 1522 ''' 1460 1523 self.__statusDetail = value … … 1464 1527 doc="status message") 1465 1528 1529 1530 class Action(SAMLObject): 1531 '''SAML 2.0 Core Action''' 1532 1533 # Element local name. 1534 DEFAULT_ELEMENT_LOCAL_NAME = "Action" 1535 1536 # Default element name. 1537 DEFAULT_ELEMENT_NAME = QName(SAMLConstants.SAML20_NS, 1538 DEFAULT_ELEMENT_LOCAL_NAME, 1539 SAMLConstants.SAML20_PREFIX) 1540 1541 # Local name of the XSI type. 1542 TYPE_LOCAL_NAME = "ActionType" 1543 1544 # QName of the XSI type 1545 TYPE_NAME = QName(SAMLConstants.SAML20_NS, 1546 TYPE_LOCAL_NAME, 1547 SAMLConstants.SAML20_PREFIX) 1548 1549 # Name of the Namespace attribute. 1550 NAMEPSACE_ATTRIB_NAME = "Namespace" 1551 1552 # Read/Write/Execute/Delete/Control action namespace. 1553 RWEDC_NS_URI = "urn:oasis:names:tc:SAML:1.0:action:rwedc" 1554 1555 # Read/Write/Execute/Delete/Control negation action namespace. 1556 RWEDC_NEGATION_NS_URI = "urn:oasis:names:tc:SAML:1.0:action:rwedc-negation" 1557 1558 # Get/Head/Put/Post action namespace. 1559 GHPP_NS_URI = "urn:oasis:names:tc:SAML:1.0:action:ghpp" 1560 1561 # UNIX file permission action namespace. 1562 UNIX_NS_URI = "urn:oasis:names:tc:SAML:1.0:action:unix" 1563 1564 # Read action. 1565 READ_ACTION = "Read" 1566 1567 # Write action. 1568 WRITE_ACTION = "Write" 1569 1570 # Execute action. 1571 EXECUTE_ACTION = "Execute" 1572 1573 # Delete action. 1574 DELETE_ACTION = "Delete" 1575 1576 # Control action. 1577 CONTROL_ACTION = "Control" 1578 1579 # Negated Read action. 1580 NEG_READ_ACTION = "~Read" 1581 1582 # Negated Write action. 1583 NEG_WRITE_ACTION = "~Write" 1584 1585 # Negated Execute action. 1586 NEG_EXECUTE_ACTION = "~Execute" 1587 1588 # Negated Delete action. 1589 NEG_DELETE_ACTION = "~Delete" 1590 1591 # Negated Control action. 1592 NEG_CONTROL_ACTION = "~Control" 1593 1594 # HTTP GET action. 1595 HTTP_GET_ACTION = "GET" 1596 1597 # HTTP HEAD action. 1598 HTTP_HEAD_ACTION = "HEAD" 1599 1600 # HTTP PUT action. 1601 HTTP_PUT_ACTION = "PUT" 1602 1603 # HTTP POST action. 1604 HTTP_POST_ACTION = "POST" 1605 1606 def __init__(self, namespaceURI, elementLocalName, namespacePrefix): 1607 ''' 1608 @param namespaceURI: the namespace the element is in 1609 @param elementLocalName: the local name of the XML element this object 1610 represents 1611 @param namespacePrefix: the prefix for the given namespace''' 1612 super(Action, self).__init__(namespaceURI, 1613 elementLocalName, 1614 namespacePrefix) 1615 1616 # URI of the Namespace of this Action 1617 self.__namespace = None 1618 1619 # Action value 1620 self.__action = None 1621 1622 def _getNamespace(self): 1623 ''' 1624 gets the namespace scope of the specified action. 1625 1626 @return: the namespace scope of the specified action 1627 ''' 1628 self.__namespace 1629 1630 def _setNamespace(self, value): 1631 ''' 1632 Sets the namespace scope of the specified action. 1633 1634 @param value: the namespace scope of the specified action 1635 ''' 1636 if not isinstance(value, basestring): 1637 raise TypeError('Expecting string type for "namespace" ' 1638 'attribute; got %r' % type(value)) 1639 self.__namespace = value 1640 1641 namespace = property(_getNamespace, _setNamespace, 1642 doc="Action Namespace") 1643 1644 def _getAction(self): 1645 ''' 1646 gets the URI of the action to be performed. 1647 1648 @return: the URI of the action to be performed 1649 ''' 1650 return self.__action 1651 1652 def _setAction(self, value): 1653 ''' 1654 Sets the URI of the action to be performed. 1655 1656 @param value: the URI of the action to be performed 1657 ''' 1658 if not isinstance(value, basestring): 1659 raise TypeError('Expecting string type for "action" ' 1660 'attribute; got %r' % type(value)) 1661 self.__action = value 1662 1663 action = property(_getAction, _setAction, 1664 doc="Action string") 1665 1466 1666 1467 1667 class RequestAbstractType(SAMLObject): … … 1510 1710 1511 1711 # Inapplicable consent URI. 1512 INAPPLICABLE_CONSENT = "urn:oasis:names:tc:SAML:2.0:consent:inapplicable" 1513 1712 INAPPLICABLE_CONSENT = "urn:oasis:names:tc:SAML:2.0:consent:inapplicable" 1713 1714 __slots__ = ( 1715 '__version', 1716 '__id', 1717 '__issueInstant', 1718 '__destination', 1719 '__consent', 1720 '__issuer', 1721 '__extensions' 1722 ) 1723 1514 1724 def __init__(self): 1515 1725 # SAML Version of the request. … … 1535 1745 1536 1746 def _get_version(self): 1537 '''@return the SAML Version of this assertion.1747 '''@return: the SAML Version of this assertion. 1538 1748 ''' 1539 1749 return self.__version 1540 1750 1541 1751 def _set_version(self, version): 1542 '''@param version the SAML Version of this assertion1752 '''@param version: the SAML Version of this assertion 1543 1753 ''' 1544 1754 if not isinstance(version, SAMLVersion): … … 1555 1765 '''Gets the date/time the request was issued 1556 1766 1557 @return the issue instance of this request'''1767 @return: the issue instance of this request''' 1558 1768 return self.__issueInstant 1559 1769 … … 1561 1771 '''Sets the date/time the request was issued 1562 1772 1563 @param value the issue instance of this request1773 @param value: the issue instance of this request 1564 1774 ''' 1565 1775 if not isinstance(value, datetime): … … 1576 1786 '''Sets the unique identifier for this request. 1577 1787 1578 @return the ID of this request1788 @return: the ID of this request 1579 1789 ''' 1580 1790 return self.__id … … 1583 1793 '''Sets the unique identifier for this request 1584 1794 1585 @param newIDthe ID of this assertion1795 @param value: the ID of this assertion 1586 1796 ''' 1587 1797 if not isinstance(value, basestring): … … 1595 1805 '''Gets the URI of the destination of the request. 1596 1806 1597 @return the URI of the destination of the request1807 @return: the URI of the destination of the request 1598 1808 ''' 1599 1809 return self.__destination … … 1602 1812 '''Sets the URI of the destination of the request. 1603 1813 1604 @param newDestinationthe URI of the destination of the request'''1814 @param value: the URI of the destination of the request''' 1605 1815 if not isinstance(value, basestring): 1606 1816 raise TypeError('Expecting basestring derived type for ' … … 1674 1884 class SubjectQuery(RequestAbstractType): 1675 1885 """SAML 2.0 Core Subject Query type""" 1886 __slots__ = ('__subject', ) 1676 1887 1677 1888 def __init__(self): … … 1681 1892 '''Gets the Subject of this request. 1682 1893 1683 @return the Subject of this request'''1894 @return: the Subject of this request''' 1684 1895 return self.__subject 1685 1896 … … 1687 1898 '''Sets the Subject of this request. 1688 1899 1689 @param newSubjectthe Subject of this request'''1900 @param value: the Subject of this request''' 1690 1901 if not isinstance(value, Subject): 1691 1902 raise TypeError('Setting "subject", got %r, expecting %r' % … … 1716 1927 SAMLConstants.SAML20P_PREFIX) 1717 1928 1929 __slots__ = ('__attributes',) 1930 1718 1931 def __init__(self): 1719 1932 self.__attributes = TypedList(Attribute) … … 1722 1935 '''Gets the Attributes of this query. 1723 1936 1724 @return the list of Attributes of this query'''1937 @return: the list of Attributes of this query''' 1725 1938 return self.__attributes 1726 1939 … … 1733 1946 1734 1947 1735 class StatusResponseType(SAMLObject): 1736 '''SAML 2.0 Core Status Response Type 1737 ''' 1738 1948 class Evidentiary(SAMLObject): 1949 """Base class for types set in an evidence object""" 1950 __slots__ = () 1951 1952 1953 class AssertionURIRef(Evidentiary): 1954 __slots__ = ('__assertionURI',) 1955 1956 def __init__(self, namespaceURI, elementLocalName, namespacePrefix): 1957 ''' 1958 @param namespaceURI: the namespace the element is in 1959 @param elementLocalName: the local name of the XML element this Object 1960 represents 1961 @param namespacePrefix: the prefix for the given namespace''' 1962 super(AssertionURIRef, self).__init__(namespaceURI, 1963 elementLocalName, 1964 namespacePrefix) 1965 1966 # URI of the Assertion 1967 self.__assertionURI = None 1968 1969 def _getAssertionURI(self): 1970 return self.__assertionURI 1971 1972 def _setAssertionURI(self, value): 1973 if not isinstance(value, basestring): 1974 raise TypeError('Expecting string type for "assertionID" ' 1975 'attribute; got %r' % type(value)) 1976 self.__assertionURI = value 1977 1978 def getOrderedChildren(self): 1979 return None 1980 1981 assertionURI = property(_getAssertionURI, _setAssertionURI, 1982 doc="Assertion URI") 1983 1984 1985 class AssertionIDRef(Evidentiary): 1986 '''SAML 2.0 Core AssertionIDRef.''' 1987 1988 # Element local name. 1989 DEFAULT_ELEMENT_LOCAL_NAME = "AssertionIDRef" 1990 1991 # Default element name. 1992 DEFAULT_ELEMENT_NAME = QName(SAMLConstants.SAML20_NS, 1993 DEFAULT_ELEMENT_LOCAL_NAME, 1994 SAMLConstants.SAML20_PREFIX) 1995 1996 __slots__ = ("_AssertionID",) 1997 1998 def __init__(self, namespaceURI, elementLocalName, namespacePrefix): 1999 ''' 2000 @param namespaceURI: the namespace the element is in 2001 @param elementLocalName: the local name of the XML element this Object 2002 represents 2003 @param namespacePrefix: the prefix for the given namespace 2004 ''' 2005 super(AssertionIDRef, self).__init__(namespaceURI, 2006 elementLocalName, 2007 namespacePrefix) 2008 self.__assertionID = None 2009 2010 def _getAssertionID(self): 2011 '''Gets the ID of the assertion this references. 2012 2013 @return: the ID of the assertion this references''' 2014 return self.__assertionID 2015 2016 def _setAssertionID(self, value): 2017 '''Sets the ID of the assertion this references. 2018 2019 @param value: the ID of the assertion this references''' 2020 if not isinstance(value, basestring): 2021 raise TypeError('Expecting string type for "assertionID" ' 2022 'attribute; got %r' % type(value)) 2023 self.__assertionID = value 2024 2025 def getOrderedChildren(self): 2026 return None 2027 2028 assertionID = property(_getAssertionID, _setAssertionID, 2029 doc="Assertion ID") 2030 2031 2032 class EncryptedElementType(SAMLObject): 2033 '''SAML 2.0 Core EncryptedElementType''' 2034 1739 2035 # Local name of the XSI type. 1740 TYPE_LOCAL_NAME = "StatusResponseType" 2036 TYPE_LOCAL_NAME = "EncryptedElementType" 2037 2038 # QName of the XSI type. 2039 TYPE_NAME = QName(SAMLConstants.SAML20_NS, 2040 TYPE_LOCAL_NAME, 2041 SAMLConstants.SAML20_PREFIX) 2042 2043 __slots__ = () 2044 2045 def _getEncryptedData(self): 2046 '''Get the EncryptedData child element. 2047 2048 @return the EncryptedData child element''' 2049 raise NotImplementedError() 2050 2051 def _setEncryptedData(self, value): 2052 '''Set the EncryptedData child element. 2053 2054 @param newEncryptedData the new EncryptedData child element''' 2055 raise NotImplementedError() 2056 2057 def _getEncryptedKeys(self): 2058 '''A list of EncryptedKey child elements. 2059 2060 @return a list of EncryptedKey child elements''' 2061 raise NotImplementedError() 2062 2063 2064 class EncryptedAssertion(EncryptedElementType, Evidentiary): 2065 '''SAML 2.0 Core EncryptedAssertion.''' 2066 2067 # Element local name. 2068 DEFAULT_ELEMENT_LOCAL_NAME = "EncryptedAssertion" 2069 2070 # Default element name. 2071 DEFAULT_ELEMENT_NAME = QName(SAMLConstants.SAML20_NS, 2072 DEFAULT_ELEMENT_LOCAL_NAME, 2073 SAMLConstants.SAML20_PREFIX) 2074 __slots__ = () 2075 2076 2077 class Evidence(SAMLObject): 2078 '''SAML 2.0 Core Evidence.''' 2079 2080 # Element local name. 2081 DEFAULT_ELEMENT_LOCAL_NAME = "Evidence" 2082 2083 # Default element name. 2084 DEFAULT_ELEMENT_NAME = QName(SAMLConstants.SAML20_NS, 2085 DEFAULT_ELEMENT_LOCAL_NAME, 2086 SAMLConstants.SAML20_PREFIX) 2087 2088 # Local name of the XSI type. 2089 TYPE_LOCAL_NAME = "EvidenceType" 2090 2091 # QName of the XSI type. 2092 TYPE_NAME = QName(SAMLConstants.SAML20_NS, 2093 TYPE_LOCAL_NAME, 2094 SAMLConstants.SAML20_PREFIX) 2095 2096 __slots__ = ('__evidence',) 2097 2098 def __init__(self, namespaceURI, elementLocalName, namespacePrefix): 2099 ''' 2100 @param namespaceURI: the namespace the element is in 2101 @param elementLocalName: the local name of the XML element this Object 2102 represents 2103 @param namespacePrefix: the prefix for the given namespace''' 2104 super(Evidence, self).__init__(namespaceURI, 2105 elementLocalName, 2106 namespacePrefix) 2107 # Assertion of the Evidence. 2108 self.__evidence = TypedList(Evidentiary) 2109 2110 def _getAssertionIDReferences(self): 2111 '''Gets the list of AssertionID references used as evidence. 2112 2113 @return: the list of AssertionID references used as evidence''' 2114 return [i for i in self.__evidence 2115 if (getattr(i, "DEFAULT_ELEMENT_NAME") == 2116 AssertionIDRef.DEFAULT_ELEMENT_NAME)] 2117 2118 def _getAssertionURIReferences(self): 2119 '''Gets the list of AssertionURI references used as evidence. 2120 2121 @return: the list of AssertionURI references used as evidence''' 2122 return [i for i in self.__evidence 2123 if (getattr(i, "DEFAULT_ELEMENT_NAME") == 2124 AssertionURIRef.DEFAULT_ELEMENT_NAME)] 2125 2126 def _getAssertions(self): 2127 '''Gets the list of Assertions used as evidence. 2128 2129 @return: the list of Assertions used as evidence''' 2130 return [i for i in self.__evidence 2131 if (getattr(i, "DEFAULT_ELEMENT_NAME") == 2132 Assertion.DEFAULT_ELEMENT_NAME)] 2133 2134 def _getEncryptedAssertions(self): 2135 '''Gets the list of EncryptedAssertions used as evidence. 2136 2137 @return: the list of EncryptedAssertions used as evidence''' 2138 return [i for i in self.__evidence 2139 if (getattr(i, "DEFAULT_ELEMENT_NAME") == 2140 EncryptedAssertion.DEFAULT_ELEMENT_NAME)] 2141 2142 def _getEvidence(self): 2143 '''Gets the list of all elements used as evidence. 2144 2145 @return: the list of Evidentiary objects used as evidence''' 2146 return self.__evidence 2147 2148 def getOrderedChildren(self): 2149 children = [] 2150 2151 if len(self.evidence) == 0: 2152 return None 2153 2154 children.extend(self.evidence) 2155 2156 return tuple(children) 2157 2158 2159 class AuthzDecisionQuery(SubjectQuery): 2160 '''SAML 2.0 AuthzDecisionQuery.''' 2161 2162 # Element local name. 2163 DEFAULT_ELEMENT_LOCAL_NAME = "AuthzDecisionQuery" 2164 2165 # Default element name. 2166 DEFAULT_ELEMENT_NAME = QName(SAMLConstants.SAML20P_NS, 2167 DEFAULT_ELEMENT_LOCAL_NAME, 2168 SAMLConstants.SAML20P_PREFIX) 2169 2170 # Local name of the XSI type. 2171 TYPE_LOCAL_NAME = "AuthzDecisionQueryType" 1741 2172 1742 2173 # QName of the XSI type. … … 1745 2176 SAMLConstants.SAML20P_PREFIX) 1746 2177 2178 # Resource attribute name. 2179 RESOURCE_ATTRIB_NAME = "Resource" 2180 2181 __slots__ = ( 2182 '__resource', 2183 '__evidence', 2184 '__actions' 2185 ) 2186 2187 def __init__(self, namespaceURI, elementLocalName, namespacePrefix): 2188 '''@param namespaceURI: the namespace the element is in 2189 @param elementLocalName: the local name of the XML element this Object 2190 represents 2191 @param namespacePrefix: the prefix for the given namespace 2192 ''' 2193 super(AuthzDecisionQuery, self).__init__(namespaceURI, 2194 elementLocalName, 2195 namespacePrefix) 2196 2197 # Resource attribute value. 2198 self.__resource = None 2199 2200 # Evidence child element. 2201 self.__evidence = None 2202 2203 # Action child elements. 2204 self.__actions = TypedList(Action) 2205 2206 def _getResource(self): 2207 '''Gets the Resource attrib value of this query. 2208 2209 @return: the Resource attrib value of this query''' 2210 return self.__resource 2211 2212 def _setResource(self, value): 2213 '''Sets the Resource attrib value of this query normalizing the path 2214 component, removing spurious port numbers (80 for HTTP and 443 for 2215 HTTPS) and converting the host component to lower case. 2216 2217 @param value: the new Resource attrib value of this query''' 2218 if not isinstance(value, basestring): 2219 raise TypeError('Expecting string type for "resource" attribute; ' 2220 'got %r instead' % type(value)) 2221 2222 # Normalise the path, set the host name to lower case and remove 2223 # port redundant numbers 80 and 443 2224 splitResult = urlsplit(value) 2225 uriComponents = list(splitResult) 2226 2227 # hostname attribute is lowercase 2228 uriComponents[1] = splitResult.hostname 2229 2230 isHttpWithStdPort = (splitResult.port == '80' and 2231 splitResult.scheme == 'http') 2232 2233 isHttpsWithStdPort = (splitResult.port == '443' and 2234 splitResult.scheme == 'https') 2235 2236 if not isHttpWithStdPort and not isHttpsWithStdPort: 2237 uriComponents[1] += ":" + splitResult.port 2238 2239 uriComponents[2] = urllib.quote(splitResult.path) 2240 2241 self.__resource = urlunsplit(uriComponents) 2242 2243 resource = property(fget=_getResource, fset=_setResource, 2244 doc="Resource for which authorisation is requested") 2245 2246 def _getActions(self): 2247 '''Gets the Actions of this query. 2248 2249 @return: the Actions of this query''' 2250 return self.__actions 2251 2252 actions = property(fget=_getActions, 2253 doc="The actions for which authorisation is requested") 2254 2255 def _getEvidence(self): 2256 '''Gets the Evidence of this query. 2257 2258 @return: the Evidence of this query''' 2259 return self.__evidence 2260 2261 def _setEvidence(self, value): 2262 '''Sets the Evidence of this query. 2263 @param newEvidence: the new Evidence of this query''' 2264 if not isinstance(value, Evidence): 2265 raise TypeError('Expecting Evidence type for "evidence" ' 2266 'attribute; got %r' % type(value)) 2267 2268 self.__evidence = value 2269 2270 evidence = property(fget=_getEvidence, fset=_setEvidence, 2271 doc="A set of assertions which the Authority may use " 2272 "to base its authorisation decision on") 2273 2274 def getOrderedChildren(self): 2275 children = [] 2276 2277 superChildren = super(AuthzDecisionQuery, self).getOrderedChildren() 2278 if superChildren: 2279 children.extend(superChildren) 2280 2281 children.extend(self.actions) 2282 2283 if evidence is not None: 2284 children.extend(evidence) 2285 2286 if len(children) == 0: 2287 return None 2288 2289 return tuple(children) 2290 2291 2292 class StatusResponseType(SAMLObject): 2293 '''SAML 2.0 Core Status Response Type 2294 ''' 2295 2296 # Local name of the XSI type. 2297 TYPE_LOCAL_NAME = "StatusResponseType" 2298 2299 # QName of the XSI type. 2300 TYPE_NAME = QName(SAMLConstants.SAML20P_NS, 2301 TYPE_LOCAL_NAME, 2302 SAMLConstants.SAML20P_PREFIX) 2303 1747 2304 # ID attribute name 1748 2305 ID_ATTRIB_NAME = "ID" … … 1784 2341 INAPPLICABLE_CONSENT = "urn:oasis:names:tc:SAML:2.0:consent:inapplicable" 1785 2342 2343 __slots__ = ( 2344 '__qname', 2345 '__version', 2346 '__id', 2347 '__inResponseTo', 2348 '__issueInstant', 2349 '__destination', 2350 '__consent', 2351 '__issuer', 2352 '__status', 2353 '__extensions' 2354 ) 2355 1786 2356 def __init__(self): 1787 2357 self.__qname = None … … 1810 2380 1811 2381 def _get_version(self): 1812 '''@return the SAML Version of this response.2382 '''@return: the SAML Version of this response. 1813 2383 ''' 1814 2384 return self.__version 1815 2385 1816 2386 def _set_version(self, version): 1817 '''@param version the SAML Version of this response2387 '''@param version: the SAML Version of this response 1818 2388 ''' 1819 2389 if not isinstance(version, SAMLVersion): … … 1830 2400 '''Sets the ID of this response. 1831 2401 1832 @return the ID of this response2402 @return: the ID of this response 1833 2403 ''' 1834 2404 return self.__id … … 1849 2419 '''Get the unique request identifier for which this is a response 1850 2420 1851 @return value: the unique identifier of the originating2421 @return: the unique identifier of the originating 1852 2422 request 1853 2423 ''' … … 1873 2443 '''Gets the issue instance of this response. 1874 2444 1875 @return the issue instance of this response'''2445 @return: the issue instance of this response''' 1876 2446 return self.__issueInstant 1877 2447 … … 1879 2449 '''Sets the issue instance of this response. 1880 2450 1881 @param newIssueInstance the issue instance of this response2451 @param newIssueInstance: the issue instance of this response 1882 2452 ''' 1883 2453 if not isinstance(issueInstant, datetime): … … 1894 2464 '''Gets the URI of the destination of the response. 1895 2465 1896 @return the URI of the destination of the response2466 @return: the URI of the destination of the response 1897 2467 ''' 1898 2468 return self.__destination … … 1954 2524 '''Gets the Status of this response. 1955 2525 1956 @return the Status of this response2526 @return: the Status of this response 1957 2527 ''' 1958 2528 return self.__status … … 1961 2531 '''Sets the Status of this response. 1962 2532 1963 @param newStatus the Status of this response2533 @param newStatus: the Status of this response 1964 2534 ''' 1965 2535 if not isinstance(value, Status): … … 2011 2581 SAMLConstants.SAML20P_PREFIX) 2012 2582 2583 __slots__ = () 2584 2013 2585 def __init__(self): 2014 2586 '''''' -
TI12-security/trunk/ndg_security_saml/saml/test/test_saml.py
r6069 r6543 25 25 Subject, NameID, StatusCode, 26 26 StatusMessage, Status, Conditions, 27 XSStringAttributeValue) 27 XSStringAttributeValue, 28 AuthzDecisionQuery) 28 29 29 30 from saml.common.xml import SAMLConstants … … 309 310 assertion.conditions = Conditions() 310 311 assertion.conditions.notBefore = datetime.utcnow() 311 assertion.conditions.notOnOrAfter = assertion.conditions.notBefore + \312 timedelta(seconds=60*60*8)312 assertion.conditions.notOnOrAfter = (assertion.conditions.notBefore + 313 timedelta(seconds=60*60*8)) 313 314 314 315 assertion.subject = Subject() … … 336 337 print(xmlOutput) 337 338 print("_"*80) 339 340 def test06CreateAuthzDecisionQuery(self): 341 authzDecisionQuery = AuthzDecisionQuery() 342 self.assert_(authzDecisionQuery) 338 343 339 344 if __name__ == "__main__": -
TI12-security/trunk/ndg_security_saml/setup.cfg
r6278 r6543 9 9 # BSD - See LICENCE file for details 10 10 [egg_info] 11 # tag_build = rc111 ##tag_build = rc1 12 12 #tag_svn_revision = true 13 13 -
TI12-security/trunk/ndg_security_saml/setup.py
r6279 r6543 20 20 setup( 21 21 name = 'ndg_security_saml', 22 version = '0. 2',22 version = '0.3', 23 23 description = 'NERC DataGrid SAML Implementation', 24 24 long_description = ('SAML 2.0 implementation for use with NDG '
Note: See TracChangeset
for help on using the changeset viewer.