<commit_before>"""
Authentication classes
"""
import logging

from core.provider.authentications.backend import AbstractBackend

from authentications.backend import MD5_HASH, CLEAR_TEXT

class AuthProvider():
    request  = None
    identity = None
    backend  = None

    def __init__(self, backend=None, userProvider=None):
        self.backend = backend
        self.userProvider = userProvider
        if isinstance(backend, AbstractBackend):
            self.backend.load()

    def hasData(self, request):
        """
        Checks if the identity and the credentials are provided
        @return boolean
        """
        return True

    def authenticate(self, request):
        if request.env.has_key('PROVIDER_AUTHENTICATED'):
            if not self.getIdentity(request):
                return False
            return True
        
        request.env['PROVIDER_AUTHENTICATED']=1
        if self._doAuthenticate(request):
            return True
        else:
            (code, headers, body) = self.getErrorResponse(request)
            for (name, value) in headers.items():
                request.setHeader(name, value)
            request.writeDirect(body, code)
            return False

    def setIdentity(self, request, identity):
        request.env['__IDENTITY__'] = identity<commit_msg>Added force parameter for the authentication.<commit_after>"""
Authentication classes
"""
import logging

from core.provider.authentications.backend import AbstractBackend

from authentications.backend import MD5_HASH, CLEAR_TEXT

class AuthProvider():
    request  = None
    identity = None
    backend  = None

    def __init__(self, backend=None, userProvider=None):
        self.backend = backend
        self.userProvider = userProvider
        if isinstance(backend, AbstractBackend):
            self.backend.load()

    def hasData(self, request):
        """
        Checks if the identity and the credentials are provided
        @return boolean
        """
        return True

    def authenticate(self, request, force=False):
        """
        Tries to authenticate the user and stores his identity in the request.
        @param Request request  request object
        @param boolean force    specifies if the authentication must be repeated
                                even in cases where this was already done
        @return boolean
        """
        if not force and request.env.has_key('PROVIDER_AUTHENTICATED'):
            if not self.getIdentity(request):
                return False
            return True
        
        request.env['PROVIDER_AUTHENTICATED']=1
        if self._doAuthenticate(request):
            return True
        else:
            (code, headers, body) = self.getErrorResponse(request)
            for (name, value) in headers.items():
                request.setHeader(name, value)
            request.writeDirect(body, code)
            return False

    def setIdentity(self, request, identity):
        request.env['__IDENTITY__'] = identity
{'fraction_non_alphanumeric': 0.07720344599072233, 'fraction_numerical': 0.0013253810470510272, 'mean_word_length': 2.270855904658722, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '510855', 'n_tokens_mistral': 758, 'n_tokens_neox': 739, 'n_words': 223}