@@ -57,7 +57,7 @@ def builder(sp, authnsign=False, wsign=False, valid_until=None, cache_duration=N
5757 :param contacts: Contacts info
5858 :type contacts: dict
5959
60- :param organization: Organization ingo
60+ :param organization: Organization info
6161 :type organization: dict
6262 """
6363 if valid_until is None :
@@ -85,8 +85,7 @@ def builder(sp, authnsign=False, wsign=False, valid_until=None, cache_duration=N
8585
8686 sls = ''
8787 if 'singleLogoutService' in sp and 'url' in sp ['singleLogoutService' ]:
88- sls = """ <md:SingleLogoutService Binding="%(binding)s"
89- Location="%(location)s" />\n """ % \
88+ sls = OneLogin_Saml2_Templates .MD_SLS % \
9089 {
9190 'binding' : sp ['singleLogoutService' ]['binding' ],
9291 'location' : sp ['singleLogoutService' ]['url' ],
@@ -105,9 +104,7 @@ def builder(sp, authnsign=False, wsign=False, valid_until=None, cache_duration=N
105104 organization_displaynames .append (""" <md:OrganizationDisplayName xml:lang="%s">%s</md:OrganizationDisplayName>""" % (lang , info ['displayname' ]))
106105 organization_urls .append (""" <md:OrganizationURL xml:lang="%s">%s</md:OrganizationURL>""" % (lang , info ['url' ]))
107106 org_data = '\n ' .join (organization_names ) + '\n ' + '\n ' .join (organization_displaynames ) + '\n ' + '\n ' .join (organization_urls )
108- str_organization = """ <md:Organization>
109- %(org)s
110- </md:Organization>""" % {'org' : org_data }
107+ str_organization = """ <md:Organization>\n %(org)s\n </md:Organization>""" % {'org' : org_data }
111108
112109 str_contacts = ''
113110 if len (contacts ) > 0 :
@@ -122,6 +119,49 @@ def builder(sp, authnsign=False, wsign=False, valid_until=None, cache_duration=N
122119 contacts_info .append (contact )
123120 str_contacts = '\n ' .join (contacts_info )
124121
122+ str_attribute_consuming_service = ''
123+
124+ if 'attributeConsumingService' in sp and len (sp ['attributeConsumingService' ]):
125+ attr_cs_desc_str = ''
126+ if "serviceDescription" in sp ['attributeConsumingService' ]:
127+ attr_cs_desc_str = """ <md:ServiceDescription xml:lang="en">%s</md:ServiceDescription>\n """ % sp ['attributeConsumingService' ]['serviceDescription' ]
128+
129+ requested_attribute_data = []
130+ for req_attribs in sp ['attributeConsumingService' ]['requestedAttributes' ]:
131+ req_attr_nameformat_str = req_attr_friendlyname_str = req_attr_isrequired_str = ''
132+ req_attr_aux_str = ' \>'
133+
134+ if 'nameFormat' in req_attribs .keys () and req_attribs ['nameFormat' ]:
135+ req_attr_nameformat_str = " NameFormat=\" %s\" " % req_attribs ['nameFormat' ]
136+ if 'friendlyName' in req_attribs .keys () and req_attribs ['friendlyName' ]:
137+ req_attr_nameformat_str = " FriendlyName=\" %s\" " % req_attribs ['friendlyName' ]
138+ if 'isRequired' in req_attribs .keys () and req_attribs ['isRequired' ]:
139+ req_attr_isrequired_str = " isRequired=\" %s\" " % req_attribs ['isRequired' ]
140+ if 'attributeValue' in req_attribs .keys () and req_attribs ['attributeValue' ]:
141+ req_attr_aux_str = """ >
142+ <saml:AttributeValue xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion>%(attributeValue)</saml:AttributeValue>
143+ </md:RequestedAttribute>""" % \
144+ {
145+ 'attributeValue' : req_attribs ['attributeValue' ]
146+ }
147+
148+ requested_attribute = OneLogin_Saml2_Templates .MD_REQUESTED_ATTRIBUTE % \
149+ {
150+ 'req_attr_name' : req_attribs ['name' ],
151+ 'req_attr_nameformat_str' : req_attr_nameformat_str ,
152+ 'req_attr_friendlyname_str' : req_attr_friendlyname_str ,
153+ 'req_attr_isrequired_str' : req_attr_isrequired_str ,
154+ 'req_attr_aux_str' : req_attr_aux_str
155+ }
156+ requested_attribute_data .append (requested_attribute )
157+
158+ str_attribute_consuming_service = OneLogin_Saml2_Templates .MD_ATTR_CONSUMER_SERVICE % \
159+ {
160+ 'service_name' : sp ['attributeConsumingService' ]['serviceName' ],
161+ 'attr_cs_desc' : attr_cs_desc_str ,
162+ 'requested_attribute_str' : '\n ' .join (requested_attribute_data )
163+ }
164+
125165 metadata = OneLogin_Saml2_Templates .MD_ENTITY_DESCRIPTOR % \
126166 {
127167 'valid' : ('validUntil="%s"' % valid_until_str ) if valid_until_str else '' ,
@@ -135,6 +175,7 @@ def builder(sp, authnsign=False, wsign=False, valid_until=None, cache_duration=N
135175 'sls' : sls ,
136176 'organization' : str_organization ,
137177 'contacts' : str_contacts ,
178+ 'attribute_consuming_service' : str_attribute_consuming_service
138179 }
139180
140181 return metadata
0 commit comments