Move accessory functions to a generic tools module
[cascardo/ipsilon.git] / ipsilon / providers / saml2idp.py
index f37474d..87cc7f6 100755 (executable)
@@ -21,9 +21,9 @@ from ipsilon.providers.common import ProviderBase, ProviderPageBase
 from ipsilon.providers.common import FACILITY
 from ipsilon.providers.saml2.auth import AuthenticateRequest
 from ipsilon.providers.saml2.admin import AdminPage
-from ipsilon.providers.saml2.certs import Certificate
 from ipsilon.providers.saml2.provider import IdentityProvider
-from ipsilon.providers.saml2 import metadata
+from ipsilon.tools.certs import Certificate
+from ipsilon.tools import saml2metadata as metadata
 from ipsilon.util.user import UserSession
 from ipsilon.util.plugin import PluginObject
 import cherrypy
@@ -98,10 +98,21 @@ class SSO(ProviderPageBase):
         self.Continue = Continue(*args, **kwargs)
 
 
+class Metadata(ProviderPageBase):
+    def GET(self, *args, **kwargs):
+        with open(self.cfg.idp_metadata_file) as m:
+            body = m.read()
+        cherrypy.response.headers["Content-Type"] = "text/xml"
+        cherrypy.response.headers["Content-Disposition"] = \
+            'attachment; filename="metadata.xml"'
+        return body
+
+
 class SAML2(ProviderPageBase):
 
     def __init__(self, *args, **kwargs):
         super(SAML2, self).__init__(*args, **kwargs)
+        self.metadata = Metadata(*args, **kwargs)
 
         # Init IDP data
         try:
@@ -177,6 +188,13 @@ Provides SAML 2.0 authentication infrastructure. """
                 'example.com'
             ]
         }
+        if cherrypy.config.get('debug', False):
+            import logging
+            import sys
+            logger = logging.getLogger('lasso')
+            lh = logging.StreamHandler(sys.stderr)
+            logger.addHandler(lh)
+            logger.setLevel(logging.DEBUG)
 
     @property
     def allow_self_registration(self):