def toXML(cls, attributeValue): """Create an XML representation of the input SAML ESG Group/Role type Attribute Value @type attributeValue: ndg.security.common.saml_utils.esgf.ESGFGroupRoleAttributeValue @param attributeValue: Group/Role Attribute Value to be represented as an ElementTree Element @rtype: ElementTree.Element @return: ElementTree Element """ elem = AttributeValueElementTreeBase.toXML(attributeValue) if not isinstance(attributeValue, ESGFGroupRoleAttributeValue): raise TypeError("Expecting %r type; got: %r" % (ESGFGroupRoleAttributeValue, type(attributeValue))) if not Config.use_lxml: ElementTree._namespace_map[attributeValue.namespaceURI ] = attributeValue.namespacePrefix tag = str(QName.fromGeneric(cls.TYPE_NAME)) groupRoleElem = etree.makeEtreeElement(tag, cls.DEFAULT_ELEMENT_NAME.prefix, cls.DEFAULT_ELEMENT_NAME.namespaceURI) groupRoleElem.set(cls.GROUP_ATTRIB_NAME, attributeValue.group) groupRoleElem.set(cls.ROLE_ATTRIB_NAME, attributeValue.role) elem.append(groupRoleElem) return elem
def toXML(cls, xacmlAuthzDecisionStatement): if not isinstance(xacmlAuthzDecisionStatement, XACMLAuthzDecisionStatement): raise TypeError("Expecting %r class got %r" % (XACMLAuthzDecisionStatement, type(xacmlAuthzDecisionStatement))) if not xacmlAuthzDecisionStatement.xacmlContextResponse: raise AttributeError("No xacmlContextResponse has been set for the " "XACMLAuthzDecisionStatement") tag = str(QName.fromGeneric(cls.DEFAULT_ELEMENT_NAME)) elem = etree.makeEtreeElement(tag, cls.DEFAULT_ELEMENT_NAME.prefix, cls.DEFAULT_ELEMENT_NAME.namespaceURI) xacmlContextResponseElem = ResponseElementTree.toXML( xacmlAuthzDecisionStatement.xacmlContextResponse) elem.append(xacmlContextResponseElem) if xacmlAuthzDecisionStatement.xacmlContextRequest: xacmlContextRequestElem = RequestElementTree.toXML( xacmlAuthzDecisionStatement.xacmlContextRequest) elem.append(xacmlContextRequestElem) return elem
def toXML(cls, xacmlAuthzDecisionQuery): """Create an XML representation of the input SAML Authorization Decision Query object @type xacmlAuthzDecisionQuery: saml.saml2.core.AuthzDecisionQuery @param xacmlAuthzDecisionQuery: SAML Authorization Decision Query @rtype: ElementTree.Element @return: Attribute Query as ElementTree XML element """ if not isinstance(xacmlAuthzDecisionQuery, XACMLAuthzDecisionQuery): raise TypeError("Expecting %r class got %r" % (XACMLAuthzDecisionQuery, type(xacmlAuthzDecisionQuery))) if not xacmlAuthzDecisionQuery.xacmlContextRequest: raise AttributeError("No xacmlContextRequest has been set for the " "XACMLAuthzDecisionQuery") issueInstant = SAMLDateTime.toString(xacmlAuthzDecisionQuery.issueInstant) attrib = { cls.ID_ATTRIB_NAME: xacmlAuthzDecisionQuery.id, cls.ISSUE_INSTANT_ATTRIB_NAME: issueInstant, # Nb. Version is a SAMLVersion instance and requires explicit cast cls.VERSION_ATTRIB_NAME: str(xacmlAuthzDecisionQuery.version), } tag = str(QName.fromGeneric(cls.DEFAULT_ELEMENT_NAME)) elem = etree.makeEtreeElement(tag, cls.DEFAULT_ELEMENT_NAME.prefix, cls.DEFAULT_ELEMENT_NAME.namespaceURI, **attrib) issuerElem = IssuerElementTree.toXML(xacmlAuthzDecisionQuery.issuer) elem.append(issuerElem) requestElem = RequestElementTree.toXML( xacmlAuthzDecisionQuery.xacmlContextRequest) elem.append(requestElem) return elem