Example #1
0
 def attributs(self):
     """
         Property.
         A fresh :class:`dict` for the user attributes, using ``settings.CAS_AUTH_CLASS``
     """
     return utils.import_attr(settings.CAS_AUTH_CLASS)(
         self.username).attributs()
Example #2
0
 def test_import_attr(self):
     """
         test the import_attr function. Feeded with a dotted path string, it should
         import the dotted module and return that last componend of the dotted path
         (function, class or variable)
     """
     with self.assertRaises(ImportError):
         utils.import_attr('toto.titi.tutu')
     with self.assertRaises(AttributeError):
         utils.import_attr('cas_server.utils.toto')
     with self.assertRaises(ValueError):
         utils.import_attr('toto')
     self.assertEqual(utils.import_attr('cas_server.default_app_config'),
                      'cas_server.apps.CasAppConfig')
     self.assertEqual(utils.import_attr(utils), utils)
Example #3
0
 def test_import_attr(self):
     """
         test the import_attr function. Feeded with a dotted path string, it should
         import the dotted module and return that last componend of the dotted path
         (function, class or variable)
     """
     with self.assertRaises(ImportError):
         utils.import_attr('toto.titi.tutu')
     with self.assertRaises(AttributeError):
         utils.import_attr('cas_server.utils.toto')
     with self.assertRaises(ValueError):
         utils.import_attr('toto')
     self.assertEqual(
         utils.import_attr('cas_server.default_app_config'),
         'cas_server.apps.CasAppConfig'
     )
     self.assertEqual(utils.import_attr(utils), utils)
Example #4
0
    def clean(self):
        """
            Validate that the submited :attr:`username` and :attr:`password` are valid

            :raises django.forms.ValidationError: if the :attr:`username` and :attr:`password`
                are not valid.
            :return: The cleaned POST data
            :rtype: dict
        """
        cleaned_data = super(UserCredential, self).clean()
        if "username" in cleaned_data and "password" in cleaned_data:
            auth = utils.import_attr(settings.CAS_AUTH_CLASS)(cleaned_data["username"])
            if auth.test_password(cleaned_data["password"]):
                cleaned_data["username"] = auth.username
            else:
                raise forms.ValidationError(
                    _(u"The credentials you provided cannot be determined to be authentic.")
                )
        return cleaned_data
Example #5
0
 def attributs(self):
     """
         Property.
         A fresh :class:`dict` for the user attributes, using ``settings.CAS_AUTH_CLASS`` if
         possible, and if not, try to fallback to cached attributes (actually only used for ldap
         auth class with bind password check mthode).
     """
     try:
         return utils.import_attr(settings.CAS_AUTH_CLASS)(self.username).attributs()
     except NotImplementedError:
         try:
             user = UserAttributes.objects.get(username=self.username)
             attributes = user.attributs
             if attributes is not None:
                 return attributes
             else:
                 return {}
         except UserAttributes.DoesNotExist:
             return {}
Example #6
0
    def clean(self):
        """
            Validate that the submited :attr:`username` and :attr:`password` are valid

            :raises django.forms.ValidationError: if the :attr:`username` and :attr:`password`
                are not valid.
            :return: The cleaned POST data
            :rtype: dict
        """
        cleaned_data = super(UserCredential, self).clean()
        if "username" in cleaned_data and "password" in cleaned_data:
            auth = utils.import_attr(settings.CAS_AUTH_CLASS)(cleaned_data["username"])
            if auth.test_password(cleaned_data["password"]):
                cleaned_data["username"] = auth.username
            else:
                raise forms.ValidationError(
                    _(u"The credentials you provided cannot be determined to be authentic.")
                )
        return cleaned_data
Example #7
0
 def attributs(self):
     """
         Property.
         A fresh :class:`dict` for the user attributes, using ``settings.CAS_AUTH_CLASS`` if
         possible, and if not, try to fallback to cached attributes (actually only used for ldap
         auth class with bind password check mthode).
     """
     try:
         return utils.import_attr(settings.CAS_AUTH_CLASS)(self.username).attributs()
     except NotImplementedError:
         try:
             user = UserAttributes.objects.get(username=self.username)
             attributes = user.attributs
             if attributes is not None:
                 return attributes
             else:
                 return {}
         except UserAttributes.DoesNotExist:
             return {}