summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-03-02 19:03:38 -0500
committerSimo Sorce <simo@redhat.com>2014-03-02 19:11:34 -0500
commite47edacd7eb7f4c90a244aed7313d07eaac08875 (patch)
tree82c1010e7455d91103368308de719c0a91998ab3
parent2959e20b5607edab7313aa5ba4500c1f37358979 (diff)
downloadipsilon-e47edacd7eb7f4c90a244aed7313d07eaac08875.tar.gz
ipsilon-e47edacd7eb7f4c90a244aed7313d07eaac08875.tar.xz
ipsilon-e47edacd7eb7f4c90a244aed7313d07eaac08875.zip
Improve exceptions for saml2 providers
Signed-off-by: Simo Sorce <simo@redhat.com>
-rwxr-xr-xipsilon/providers/common.py14
-rwxr-xr-xipsilon/providers/saml2/auth.py16
-rwxr-xr-xipsilon/providers/saml2/provider.py16
3 files changed, 26 insertions, 20 deletions
diff --git a/ipsilon/providers/common.py b/ipsilon/providers/common.py
index 4599735..f8819c7 100755
--- a/ipsilon/providers/common.py
+++ b/ipsilon/providers/common.py
@@ -22,6 +22,20 @@ from ipsilon.util.page import Page
import cherrypy
+class ProviderException(Exception):
+
+ def __init__(self, message):
+ super(ProviderException, self).__init__(message)
+ self.message = message
+
+ def __str__(self):
+ return repr(self.message)
+
+ def _debug(self, fact):
+ if cherrypy.config.get('debug', False):
+ cherrypy.log('%s: %s' % (self.__class__.__name__, fact))
+
+
class ProviderBase(PluginObject):
def __init__(self, name, path):
diff --git a/ipsilon/providers/saml2/auth.py b/ipsilon/providers/saml2/auth.py
index 7f92d77..0dd16b8 100755
--- a/ipsilon/providers/saml2/auth.py
+++ b/ipsilon/providers/saml2/auth.py
@@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from ipsilon.providers.common import ProviderPageBase
+from ipsilon.providers.common import ProviderPageBase, ProviderException
from ipsilon.providers.saml2.provider import ServiceProvider
from ipsilon.providers.saml2.provider import InvalidProviderId
from ipsilon.providers.saml2.provider import NameIdNotAllowed
@@ -27,25 +27,19 @@ import datetime
import lasso
-class AuthenticationError(Exception):
+class AuthenticationError(ProviderException):
def __init__(self, message, code):
super(AuthenticationError, self).__init__(message)
- self.message = message
self.code = code
+ self._debug('%s [%s]' % (message, code))
- def __str__(self):
- return repr(self.message)
-
-class InvalidRequest(Exception):
+class InvalidRequest(ProviderException):
def __init__(self, message):
super(InvalidRequest, self).__init__(message)
- self.message = message
-
- def __str__(self):
- return repr(self.message)
+ self._debug(message)
class AuthenticateRequest(ProviderPageBase):
diff --git a/ipsilon/providers/saml2/provider.py b/ipsilon/providers/saml2/provider.py
index acf2ee7..03efeb3 100755
--- a/ipsilon/providers/saml2/provider.py
+++ b/ipsilon/providers/saml2/provider.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from ipsilon.providers.common import ProviderException
import cherrypy
import lasso
@@ -34,15 +35,12 @@ NAMEID_MAP = {
}
-class InvalidProviderId(Exception):
+class InvalidProviderId(ProviderException):
- def __init__(self, message):
- msg = 'Invalid Provider ID: %s' % message
- super(InvalidProviderId, self).__init__(msg)
- self.message = msg
-
- def __str__(self):
- return repr(self.message)
+ def __init__(self, code):
+ message = 'Invalid Provider ID: %s' % code
+ super(InvalidProviderId, self).__init__(message)
+ self._debug(message)
class NameIdNotAllowed(Exception):
@@ -101,7 +99,7 @@ class ServiceProvider(object):
for nameid in allowed:
if nip.format == NAMEID_MAP[nameid]:
return nip.format
- raise NameIdNotAllowed()
+ raise NameIdNotAllowed(nip.format)
def _debug(self, fact):
if cherrypy.config.get('debug', False):