Projet

Général

Profil

0001-do-not-crash-if-no-idp-is-found-19260.patch

Benjamin Dauvergne, 07 juin 2019 10:24

Télécharger (3,18 ko)

Voir les différences:

Subject: [PATCH] do not crash if no idp is found (#19260)

Also improve logging of no idp situation in default backend.
 mellon/backends.py | 10 +++++++++-
 mellon/views.py    |  8 +++++---
 2 files changed, 14 insertions(+), 4 deletions(-)
mellon/backends.py
13 13
# You should have received a copy of the GNU Affero General Public License
14 14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15 15

  
16
import logging
17

  
16 18
from django.contrib.auth.backends import ModelBackend
17 19

  
18 20
from . import utils
19 21

  
22
logger = logging.getLogger(__name__)
23

  
20 24

  
21 25
class SAMLBackend(ModelBackend):
22 26
    def authenticate(self, saml_attributes, request=None):
23 27
        # without an issuer we can do nothing
24 28
        if 'issuer' not in saml_attributes:
25
            return
29
            logger.debug('no idp in saml_attributes')
30
            return None
26 31
        idp = utils.get_idp(saml_attributes['issuer'])
32
        if not idp:
33
            logger.debug('unknown idp %s', saml_attributes['issuer'])
34
            return None
27 35
        adapters = utils.get_adapters(idp)
28 36
        for adapter in adapters:
29 37
            if not hasattr(adapter, 'authorize'):
mellon/views.py
113 113
            for idp in utils.get_idps():
114 114
                return idp
115 115
            else:
116
                return None
116
                return {}
117 117
        else:
118 118
            return utils.get_idp(entity_id)
119 119

  
......
154 154
        '''show error message to user after a login failure'''
155 155
        login = self.profile
156 156
        idp = utils.get_idp(login.remoteProviderId)
157
        if not idp:
158
            return HttpResponseBadRequest(
159
                'entity id %r is unknown' % login.remoteProviderId)
157 160
        error_url = utils.get_setting(idp, 'ERROR_URL')
158 161
        error_redirect_after_timeout = utils.get_setting(idp, 'ERROR_REDIRECT_AFTER_TIMEOUT')
159 162
        if error_url:
......
284 287
                'no entity id found for this artifact %r' % artifact)
285 288
        idp = utils.get_idp(login.remoteProviderId)
286 289
        if not idp:
287
            self.log.warning('entity id %r is unknown', login.remoteProviderId)
288 290
            return HttpResponseBadRequest(
289 291
                'entity id %r is unknown' % login.remoteProviderId)
290 292
        verify_ssl_certificate = utils.get_setting(
......
376 378

  
377 379
        next_url = check_next_url(self.request, request.GET.get(REDIRECT_FIELD_NAME))
378 380
        idp = self.get_idp(request)
379
        if idp is None:
381
        if not idp:
380 382
            return HttpResponseBadRequest('no idp found')
381 383
        self.profile = login = utils.create_login(request)
382 384
        self.log.debug('authenticating to %r', idp['ENTITY_ID'])
383
-