client_views.py 936 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

import logging
from django.http import HttpResponse
from django.contrib.auth import authenticate

LOGGER = logging.getLogger(__name__)

def user_endpoint(request):
    LOGGER.debug('RabbitMQ sent auth request')
    if 'username' in request.POST and 'password' in request.POST:
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user:
            LOGGER.info('Authenticated client as %s', user)

            if user.is_superuser:
                return HttpResponse("allow administrator")
            else:
                return HttpResponse("allow management")

    LOGGER.error('Failed to authenticate user for RabbitMQ')
    return HttpResponse("deny")

def vhost(request):
    return HttpResponse("allow")

def resource(request):
    return HttpResponse("allow")

def topic(request):
    return HttpResponse("allow")