diff options
Diffstat (limited to 'coip/apps/saml2/views.py')
-rw-r--r-- | coip/apps/saml2/views.py | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/coip/apps/saml2/views.py b/coip/apps/saml2/views.py index 497e219..4b999fb 100644 --- a/coip/apps/saml2/views.py +++ b/coip/apps/saml2/views.py @@ -5,7 +5,7 @@ Created on Apr 2, 2012 ''' import re -from saml2 import server +from saml2 import server, BINDING_SOAP from saml2 import saml from saml2 import soap import logging @@ -14,8 +14,46 @@ from django.http import HttpResponse, HttpResponseBadRequest from saml2.config import Config from saml2.metadata import entity_descriptor from coip.apps.saml2 import conf +from saml2.saml import NAME_FORMAT_URI +from django.conf import settings +from coip.apps.saml2.conf import CONFIG -aa = server.Server("coip.apps.saml2.conf", log=logging, debug=1, stype="aa") +def _config(request): + host = request.get_host() + c = { + "entityid" : request.build_absolute_uri("/saml2/entity"), + "description": "COIP", + "service": { + "aa": { + "name" : "COIP", + "endpoints" : { + "attribute_service" : [(request.build_absolute_uri("/saml2/aq"), BINDING_SOAP)], + }, + "policy": { + "default": { + "lifetime": {"minutes":15}, + "attribute_restrictions": None, # means all I have + "name_form": NAME_FORMAT_URI + }, + }, + "subject_data": ("dict", {}), + } + }, + "debug" : 1, + "key_file" : "%s/%s.key" % (settings.SSL_KEY_DIR,host), + "cert_file" : "%s/%s.crt" % (settings.SSL_CRT_DIR,host), + "attribute_map_dir" : "%s/saml2/attributemaps" % settings.BASE_DIR, + "metadata" : { + "local": ["%s/saml2/metadata/sp.xml" % settings.BASE_DIR], + }, + "organization": { + "display_name": "COIP on %s" % host, + "name": "COIP on %s" % host, + "url": request.build_absolute_uri("/"), + }, + } + + return CONFIG().load(c) def _aa_reply(aa, aq, user, sp_entityid): consumer_url = aa.metadata.consumer_url(aq.issuer.text) @@ -31,13 +69,13 @@ def _aa_reply(aa, aq, user, sp_entityid): issuer=aa.conf.entityid) def metadata(request): - cnf = Config().load(conf.CONFIG, metadata_construction=True) + cnf = Config().load(_config(request), metadata_construction=True) ed = entity_descriptor(cnf, 0) return HttpResponse(content=ed,content_type="text/xml") def aq(request): if request.method == 'POST': - global aa + aa = server.Server(config=_config(request), log=logging, debug=1, stype="aa") request_xml = soap.parse_soap_enveloped_saml_attribute_query(request.raw_post_data) logging.debug(request_xml) (subject, attribute, aq) = aa.parse_attribute_query(request_xml,False) |