summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Hedberg <roland.hedberg@adm.umu.se>2013-05-24 18:02:30 +0200
committerRoland Hedberg <roland.hedberg@adm.umu.se>2013-05-24 18:02:30 +0200
commite401cf25e2ace829f3438d06efb3e6749e84014b (patch)
tree183531718d373c5c8b0f50ee3614ccece39abed5
parent77e5a407a52a380cff191ffcf5d74c8cf095b27d (diff)
downloadpysaml2-develop.tar.gz
In some case you want the url to be based on server_name/server_port and not http_host, now you can get what you want.develop
-rw-r--r--src/saml2/httputil.py13
-rwxr-xr-xtools/mdexport_test.py68
-rwxr-xr-xtools/mdimport.py24
3 files changed, 96 insertions, 9 deletions
diff --git a/src/saml2/httputil.py b/src/saml2/httputil.py
index ae672e44..e2a0d492 100644
--- a/src/saml2/httputil.py
+++ b/src/saml2/httputil.py
@@ -154,16 +154,19 @@ def extract(environ, empty=False, err=False):
return formdata
-def geturl(environ, query=True, path=True):
+def geturl(environ, query=True, path=True, use_server_name=False):
"""Rebuilds a request URL (from PEP 333).
+ You may want to chose to use the environment variables
+ server_name and server_port instead of http_host in some case.
+ The parameter use_server_name allows you to chose.
:param query: Is QUERY_STRING included in URI (default: True)
:param path: Is path included in URI (default: True)
+ :param use_server_name: If SERVER_NAME/_HOST should be used instead of
+ HTTP_HOST
"""
url = [environ['wsgi.url_scheme'] + '://']
- if environ.get('SERVER_NAME'):
- url.append(environ['HTTP_HOST'])
- else:
+ if use_server_name:
url.append(environ['SERVER_NAME'])
if environ['wsgi.url_scheme'] == 'https':
if environ['SERVER_PORT'] != '443':
@@ -171,6 +174,8 @@ def geturl(environ, query=True, path=True):
else:
if environ['SERVER_PORT'] != '80':
url.append(':' + environ['SERVER_PORT'])
+ else:
+ url.append(environ['HTTP_HOST'])
if path:
url.append(getpath(environ))
if query and environ.get('QUERY_STRING'):
diff --git a/tools/mdexport_test.py b/tools/mdexport_test.py
new file mode 100755
index 00000000..abd9aefe
--- /dev/null
+++ b/tools/mdexport_test.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+import sys
+
+from saml2 import saml
+from saml2 import md
+from saml2.extension import mdui
+from saml2.extension import idpdisc
+from saml2.extension import dri
+from saml2.extension import mdattr
+from saml2.extension import ui
+from saml2.extension import shibmd
+import xmldsig
+import xmlenc
+
+from saml2.mdstore import MetaDataFile, MetaDataExtern
+
+__author__ = 'rolandh'
+
+"""
+A script that imports and verifies metadata and then dumps it in a basic
+dictionary format.
+"""
+
+
+ONTS = {
+ saml.NAMESPACE: saml,
+ mdui.NAMESPACE: mdui,
+ mdattr.NAMESPACE: mdattr,
+ dri.NAMESPACE: dri,
+ ui.NAMESPACE: ui,
+ idpdisc.NAMESPACE: idpdisc,
+ md.NAMESPACE: md,
+ xmldsig.NAMESPACE: xmldsig,
+ xmlenc.NAMESPACE: xmlenc,
+ shibmd.NAMESPACE: shibmd
+}
+
+MDIMPORT = {
+ "swamid": {
+ "url": "https://kalmar2.org/simplesaml/module.php/aggregator/?id=kalmarcentral2&set=saml2",
+ "cert": "kalmar2.pem",
+ "type": "external"
+ },
+ "incommon": {
+ "file": "InCommon-metadata.xml",
+ "type": "local"
+ },
+ "test": {
+ "file": "mdtest.xml",
+ "type": "local"
+ }
+}
+
+
+item = MDIMPORT[sys.argv[1]]
+
+metad = None
+
+if item["type"] == "local":
+ metad = MetaDataFile(sys.argv[1], ONTS.values(), item["file"])
+elif item["type"] == "external":
+ metad = MetaDataExtern(sys.argv[1], ONTS.values(),
+ item["url"], "/opt/local/bin/xmlsec1", item["cert"])
+
+if metad:
+ metad.load()
+ print metad.dumps()
+
diff --git a/tools/mdimport.py b/tools/mdimport.py
index 10cf994b..6f83d958 100755
--- a/tools/mdimport.py
+++ b/tools/mdimport.py
@@ -1,10 +1,11 @@
#!/usr/bin/env python
import sys
+import time
+from saml2.attribute_converter import ac_factory
+from saml2.mdstore import MetaDataMD, MetaDataFile
__author__ = 'rolandh'
-from saml2.mdie import from_dict
-
import xmldsig
import xmlenc
from saml2 import md
@@ -27,7 +28,20 @@ ONTS = {
xmldsig.NAMESPACE: xmldsig,
}
-_dict = eval(open(sys.argv[1]).read())
-res = from_dict(_dict, ONTS)
+start = time.time()
+for i in range(1, 10):
+ mdmd = MetaDataMD(ONTS, ac_factory("../tests/attributemaps"), "swamid2.md")
+ mdmd.load()
+
+ _ = mdmd.keys()
+
+print time.time() - start
+
+start = time.time()
+for i in range(1, 10):
+ mdf = MetaDataFile(ONTS.values(), ac_factory("../tests/attributemaps"),
+ "../tests/swamid-2.0.xml")
+ mdf.load()
+ _ = mdf.keys()
-print res \ No newline at end of file
+print time.time() - start