def authenticate(self, username=None, password=None, *args, **kwargs):  
        try:
            logger.info("%s attempting to connect to Splunk server at %s:%s"%
                        (username, settings.SPLUNKD_HOST, settings.SPLUNKD_PORT) )           
            service = connect(
                username=username,
                password=password,
                scheme=settings.SPLUNKD_SCHEME,
                host=settings.SPLUNKD_HOST,
                port=settings.SPLUNKD_PORT
            )
        except Exception, e:
            if hasattr(e, 'status') and e.status == 401:
                logger.error("Failed to connect. Server returned 401: Unauthorized." % username)
                return None
            else:
                logger.exception(e)
                raise
        
        user = service.users[username]
        properties = user.content()
        user_id = "%s:%s" % (username, service.token)
        user_id = aes.encrypt(str(user_id))
        
        splunkweb_info = None
    
        try:
            r1 = requests.get(
                get_splunkweb_url("account/login"),
                allow_redirects=True)
            
            cval = r1.cookies['cval']
            r = requests.post(
                r1.url,
                cookies=r1.cookies,
                data={"username":username, "password":password, "cval":cval})
            
            splunkweb_info = SplunkWebInfo(r.cookies)
        except Exception, e:
            logger.exception(e)
            pass
        
        # TODO: We need to find a better way to do this, specifically,
        # the way we pass the session_id, which are the Splunkweb cookie
        # values, is a hack.
        return SplunkUser(
            id=user_id,
            splunkweb=splunkweb_info,
            service=service,
            username=username, 
            password=password, 
            email=properties["email"],
            is_superuser="admin" in properties["roles"],
            is_staff="admin" in properties["roles"],
            is_active=True,
            realname=properties["realname"],
            tz=properties['tz']
        )
dataset/ETHPy150Open splunk/splunk-webframework/server/splunkdj/auth/backends.py/SplunkAuthenticationBackend.authenticate/original