Add Service and Identity Provider abstraction
[cascardo/ipsilon.git] / ipsilon / providers / saml2 / auth.py
index 7f92d77..bac73a5 100755 (executable)
@@ -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/>.
 
 # 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
 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
 
 
 import lasso
 
 
-class AuthenticationError(Exception):
+class AuthenticationError(ProviderException):
 
     def __init__(self, message, code):
         super(AuthenticationError, self).__init__(message)
 
     def __init__(self, message, code):
         super(AuthenticationError, self).__init__(message)
-        self.message = message
         self.code = code
         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)
 
     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):
 
 
 class AuthenticateRequest(ProviderPageBase):
@@ -65,7 +59,7 @@ class AuthenticateRequest(ProviderPageBase):
 
     def _parse_request(self, message):
 
 
     def _parse_request(self, message):
 
-        login = lasso.Login(self.cfg.idp)
+        login = self.cfg.idp.get_login_handler()
 
         try:
             login.processAuthnRequestMsg(message)
 
         try:
             login.processAuthnRequestMsg(message)
@@ -189,7 +183,7 @@ class AuthenticateRequest(ProviderPageBase):
             raise AuthenticationError("Unavailable Name ID type",
                                       lasso.SAML2_STATUS_CODE_AUTHN_FAILED)
 
             raise AuthenticationError("Unavailable Name ID type",
                                       lasso.SAML2_STATUS_CODE_AUTHN_FAILED)
 
-        # TODO: add user attributes as policy requires taking from 'usersession'
+        # TODO: add user attributes as policy requires from 'usersession'
 
     def saml2error(self, login, code, message):
         status = lasso.Samlp2Status()
 
     def saml2error(self, login, code, message):
         status = lasso.Samlp2Status()