'Wrapping function.'

def SecurityCheck(self, func, request, *args, **kwargs):

    request.user = ''
    authorized = False
    try:
        (auth_type, authorization) = request.headers.get('Authorization', '    ').split('    ', 1)
        if (auth_type == 'Basic'):
            (user, password) = authorization.decode('base64').split(':', 1)
            token = access_control.ACLToken(username=user)
            fd = aff4.FACTORY.Open(('aff4:/users/%s' % user), aff4_type=aff4_users.GRRUser, token=token)
            crypted_password = fd.Get(fd.Schema.PASSWORD)
            if (crypted_password and crypted_password.CheckPassword(password)):
                authorized = True
                request.user = user
    except (IndexError, KeyError, IOError, access_control.UnauthorizedAccess):
        pass
    if (not authorized):
        result = werkzeug_wrappers.Response('Unauthorized', status=401)
        result.headers['WWW-Authenticate'] = "Basic    realm='Secure    Area'"
        return result
    response = func(request, *args, **kwargs)
    return response
