I am in a situation where I need to make a custom authentication and custom middleware to authenticate and authorize the user. I have to chek the username password params in the POST request or if the cookie is set or not for token based authentication. Now, as I know that function overloading is not allowed in python, how could I achieve it. I am putting the code below for custom auth and custom middleware.
Custom Middleware:
from django.contrib.auth import authenticate
class AuthMiddleWare(object):
def process_request(self, request):
if request.path != '/favicon.ico':
print "inside process_request " + request.path
if request.method == 'POST' and request.POST.has_key('username' ) and request.POST.has_key('password'):
authenticate(username = request.POST.get('username'),password = request.POST.get('password'))
if 'SPRING_SECURITY_REMEMBER_ME_COOKIE' in request.COOKIES:
authenticate(token = request.COOKIES.get('SPRING_SECURITY_REMEMBER_ME_COOKIE'))
return None
And the custom auth backend :
from core.api import NcpAPI
class CustomNCPAuthBackend(object):
"""
This is custom authentication backend.
Authenticate against the webservices call.
The method below would override authenticate() of django.contrib.auth
"""
def authenticate(self, username = None, password = None):
print "inside authenticate of username and password with username being : "+username
return None
def authenticate(self,token=None):
print "inside authenticate of token with token being : "+token
return None
The problem is even when I am checking for username and password in post request it calls the token one as token is there, but how could I force it somehow?
I tried deleting the cookie and trying again but still it doesn't fire up the authentication function with username and password as params.
What could be solution for this please?