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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009 UmeƄ University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Contains classes and functions that a SAML2.0 Service Provider (SP) may use
to do attribute aggregation.
"""
import os
import urllib
import saml2
import base64
from saml2 import samlp, saml
from saml2.sigver import correctly_signed_response
from saml2.soap import SOAPClient
from saml2.client import Saml2Client
DEFAULT_BINDING = saml2.BINDING_HTTP_REDIRECT
class AttributeResolver(object):
def __init__(self, environ, metadata=None, config=None, saml2client=None):
self.metadata = metadata
if saml2client:
self.saml2client = saml2client
else:
self.saml2client = Saml2Client(environ, config)
def extend(self, subject_id, issuer, vo_members, name_id_format=None,
sp_name_qualifier=None, log=None):
"""
:param subject_id: The identifier by which the subject is know
among all the participents of the VO
:param issuer: Who am I the poses the query
:param vo_members: The entity IDs of the IdP who I'm going to ask
for extra attributes
:param nameid_format: Used to make the IdPs aware of what's going
on here
:param log: Where to log exciting information
:return: A dictionary with all the collected information about the
subject
"""
extended_identity = {}
for member in vo_members:
for ass in self.metadata.attribute_services(member):
for attr_serv in ass.attribute_service:
log and log.info("Send attribute request to %s" % \
attr_serv.location)
(resp, issuer,
not_on_or_after) = self.saml2client.attribute_query(
subject_id,
issuer,
attr_serv.location,
sp_name_qualifier=sp_name_qualifier,
format=name_id_format, log=log)
if resp:
# unnecessary
del resp["__userid"]
extended_identity[issuer] = (not_on_or_after, resp)
return extended_identity
|