X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=blobdiff_plain;f=ipsilon%2Fproviders%2Fsaml2%2Fadmin.py;h=28ea19fc6067ca76d2cac371937a66a18e93a36c;hp=f8163f702064283b1023503b3d3b6c1469aaf508;hb=cfe24fa3dc15d87f3ace944a2d62a0f4c5ee496c;hpb=348fcbcbaf5c686cdb077c9bed53ded95ad04b49 diff --git a/ipsilon/providers/saml2/admin.py b/ipsilon/providers/saml2/admin.py index f8163f7..28ea19f 100644 --- a/ipsilon/providers/saml2/admin.py +++ b/ipsilon/providers/saml2/admin.py @@ -1,19 +1,4 @@ -# Copyright (C) 2014 Simo Sorce -# -# see file 'COPYING' for use and warranty information -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING import cherrypy from ipsilon.util import config as pconfig @@ -28,6 +13,7 @@ from ipsilon.providers.saml2.provider import ServiceProviderCreator from ipsilon.providers.saml2.provider import InvalidProviderId from copy import deepcopy import requests +import logging class NewSPAdminPage(AdminPage): @@ -58,14 +44,14 @@ class NewSPAdminPage(AdminPage): name = None meta = None if 'content-type' not in cherrypy.request.headers: - self._debug("Invalid request, missing content-type") + self.debug("Invalid request, missing content-type") message = "Malformed request" message_type = ADMIN_STATUS_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,)) + self.debug("Invalid form type (%s), trying to cope" % ( + cherrypy.request.content_type,)) for key, value in kwargs.iteritems(): if key == 'name': name = value @@ -76,7 +62,7 @@ class NewSPAdminPage(AdminPage): if hasattr(value, 'content_type'): meta = value.fullvalue() else: - self._debug("Invalid format for 'meta'") + self.debug("Invalid format for 'meta'") elif key == 'metaurl': if len(value) > 0: try: @@ -84,7 +70,7 @@ class NewSPAdminPage(AdminPage): r.raise_for_status() meta = r.content except Exception, e: # pylint: disable=broad-except - self._debug("Failed to fetch metadata: " + repr(e)) + self.debug("Failed to fetch metadata: " + repr(e)) message = "Failed to fetch metadata: " + repr(e) message_type = ADMIN_STATUS_ERROR return self.form_new(message, message_type) @@ -101,7 +87,7 @@ class NewSPAdminPage(AdminPage): message = str(e) message_type = ADMIN_STATUS_ERROR except Exception, e: # pylint: disable=broad-except - self._debug(repr(e)) + self.debug(repr(e)) message = "Failed to create Service Provider!" message_type = ADMIN_STATUS_ERROR else: @@ -156,6 +142,9 @@ class SPAdminPage(AdminPage): value = kwargs[name] if isinstance(option, pconfig.List): value = [x.strip() for x in value.split('\n')] + # for normal lists we want unordered comparison + if set(value) == set(option.get_value()): + continue elif isinstance(option, pconfig.Condition): value = True else: @@ -167,9 +156,9 @@ class SPAdminPage(AdminPage): aname = '%s_%s' % (name, a) if aname in kwargs: value.append(a) - elif type(option) is pconfig.ComplexList: + elif isinstance(option, pconfig.MappingList): current = deepcopy(option.get_value()) - value = get_complex_list_value(name, + value = get_mapping_list_value(name, current, **kwargs) # if current value is None do nothing @@ -177,9 +166,9 @@ class SPAdminPage(AdminPage): if option.get_value() is None: continue # else pass and let it continue as None - elif type(option) is pconfig.MappingList: + elif isinstance(option, pconfig.ComplexList): current = deepcopy(option.get_value()) - value = get_mapping_list_value(name, + value = get_complex_list_value(name, current, **kwargs) # if current value is None do nothing @@ -191,11 +180,8 @@ class SPAdminPage(AdminPage): continue if value != option.get_value(): - if (type(option) is pconfig.List and - set(value) == set(option.get_value())): - continue cherrypy.log.error("Storing %s = %s" % - (name, value)) + (name, value), severity=logging.DEBUG) new_db_values[name] = value if len(new_db_values) != 0: @@ -247,7 +233,7 @@ class SPAdminPage(AdminPage): message_type = ADMIN_STATUS_ERROR return self.root_with_msg(message, message_type) except Exception as e: # pylint: disable=broad-except - self._debug("Error: %s" % repr(e)) + self.debug("Error: %s" % repr(e)) message = "Internal Error" message_type = ADMIN_STATUS_ERROR return self.root_with_msg(message, message_type) @@ -300,7 +286,7 @@ class Saml2AdminPage(AdminPage): self.providers.remove(page.sp) self.sp.del_subtree(name) except Exception, e: # pylint: disable=broad-except - self._debug("Failed to remove provider %s: %s" % (name, str(e))) + self.debug("Failed to remove provider %s: %s" % (name, str(e))) def add_sps(self): if self.cfg.idp: @@ -310,7 +296,7 @@ class Saml2AdminPage(AdminPage): self.del_sp(sp.name) 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.debug("Failed to find provider %s: %s" % (p, str(e))) def mount(self, page): self.menu = page.menu