summaryrefslogtreecommitdiffstats
path: root/ipsilon
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-04-04 13:08:02 -0400
committerSimo Sorce <simo@redhat.com>2014-04-04 13:08:28 -0400
commite3547ec9148642659c3708db8a54fb008b1d9995 (patch)
tree0d65f941909588313bf9454fb72ea0dbaa2935e0 /ipsilon
parent8cdf10beebc47e1dfa095d052a2f7ed317e905a0 (diff)
downloadipsilon-e3547ec9148642659c3708db8a54fb008b1d9995.tar.gz
ipsilon-e3547ec9148642659c3708db8a54fb008b1d9995.tar.xz
ipsilon-e3547ec9148642659c3708db8a54fb008b1d9995.zip
Admin functions to add new Service Providers
Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'ipsilon')
-rwxr-xr-xipsilon/providers/saml2/admin.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/ipsilon/providers/saml2/admin.py b/ipsilon/providers/saml2/admin.py
index c8d26b8..7db19fc 100755
--- a/ipsilon/providers/saml2/admin.py
+++ b/ipsilon/providers/saml2/admin.py
@@ -20,6 +20,83 @@
import cherrypy
from ipsilon.util.page import Page
from ipsilon.providers.saml2.provider import ServiceProvider
+from ipsilon.providers.saml2.provider import ServiceProviderCreator
+from ipsilon.providers.saml2.provider import InvalidProviderId
+
+
+class NewSPAdminPage(Page):
+
+ def __init__(self, site, parent):
+ super(NewSPAdminPage, self).__init__(site)
+ self.parent = parent
+ self.title = 'New Service Provider'
+ self.backurl = parent.url
+ self.url = '%s/new' % (parent.url,)
+
+ def form_new(self, message=None, message_type=None):
+ return self._template('admin/providers/saml2_sp_new.html',
+ title=self.title,
+ message=message,
+ message_type=message_type,
+ name='saml2_sp_new_form',
+ backurl=self.backurl, action=self.url)
+
+ def GET(self, *args, **kwargs):
+ return self.form_new()
+
+ def POST(self, *args, **kwargs):
+
+ if self.user.is_admin:
+ #TODO: allow authenticated user to create SPs on their own
+ # set the owner in that case
+ name = None
+ meta = None
+ if 'content-type' not in cherrypy.request.headers:
+ self._debug("Invalid request, missing content-type")
+ message = "Malformed request"
+ message_type = "error"
+ return self.form_new(message, message_type)
+ ctype = cherrypy.request.headers['content-type'].split(';')[0]
+ if ctype != 'multipart/form-data':
+ self._debug("Invalid form type (%s), trying to cope" % (
+ cherrypy.request.content_type,))
+ for key, value in kwargs.iteritems():
+ if key == 'name':
+ name = value
+ elif key == 'meta':
+ if hasattr(value, 'content_type'):
+ meta = value.fullvalue()
+ else:
+ self._debug("Invalid format for 'meta'")
+
+ if name and meta:
+ try:
+ spc = ServiceProviderCreator(self.parent.cfg)
+ sp = spc.create_from_buffer(name, meta)
+ sp_page = self.parent.add_sp(name, sp)
+ message = "SP Successfully added"
+ message_type = "success"
+ return sp_page.form_standard(message, message_type)
+ except InvalidProviderId, e:
+ message = str(e)
+ message_type = "error"
+ except Exception, e: # pylint: disable=broad-except
+ self._debug(repr(e))
+ message = "Failed to create Service Provider!"
+ message_type = "error"
+ else:
+ message = "A name and a metadata file must be provided"
+ message_type = "error"
+ else:
+ message = "Unauthorized"
+ message_type = "error"
+
+ return self.form_new(message, message_type)
+
+ def root(self, *args, **kwargs):
+ op = getattr(self, cherrypy.request.method, self.GET)
+ if callable(op):
+ return op(*args, **kwargs)
class SPAdminPage(Page):
@@ -141,6 +218,7 @@ class AdminPage(Page):
self.add_sp(sp.name, sp)
except Exception, e: # pylint: disable=broad-except
self._debug("Failed to find provider %s: %s" % (p, str(e)))
+ self.add_subtree('new', NewSPAdminPage(self._site, self))
page.add_subtree(self.name, self)
def root(self, *args, **kwargs):