Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8046105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:42:37+00:00 2026-06-05T05:42:37+00:00

For a while now I have been trying to find a way for jython

  • 0

For a while now I have been trying to find a way for jython to access site using NTLM. I have just basic knowledge of python and next to none in java, so I could use some help (or an example) how to make the request use NTLM in this script part I have found. I am using this with open source application grinder.

First I start with importing jcifs in script along with others used by grinder:

from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest
from HTTPClient import NVPair

from jcifs.ntlmssp import Type1Message
from jcifs.ntlmssp import Type2Message, Type3Message
from jcifs.util import Base64 

This code part was provided in example I found. It was the closes thing I could find, that would fit my needs, since I just need to get the full response to request.

def NTLMAuthentication1(url, request, info, NTLMfield):
    token_type1 = info.token_type1()

    params = (NVPair("Authorization", "NTLM "+token_type1), )
    result = request.GET(url, None, params)
    NTLMfield = result.getHeader("WWW-Authenticate")
    return NTLMAuthentication2(url, request, info, NTLMfield)

def NTLMAuthentication2(url, request, info, NTLMfield):
    if NTLMfield.startswith("Negotiate"):
        token_type2 = NTLMfield[len("Negotiate "):]
    else:
        token_type2 = NTLMfield[5:]

    token_type3 = info.token_type3(token_type2)
    params = (NVPair("Cookie", "WSS_KeepSessionAuthenticated=80"),
              NVPair("Authorization", "NTLM " + token_type3), )
    result = request.GET(url, None, params)
    return result

# this function validate request and its result to see if the NTLM authentication is required
def NTLMAuthentication(lastResult, request, info):
    # get last http request's url
    url = lastResult.getEffectiveURI().toString()[len(request.getUrl()):]

    # The result is ask for authentication
    if lastResult.statusCode != 401 and lastResult.statusCode != 407:
        return lastResult

    NTLMfield = lastResult.getHeader("WWW-Authenticate")
    if NTLMfield == None:
        return lastResult

    # check it is the first shakehands
    if NTLMfield == "Negotiate, NTLM" or NTLMfield == "NTLM":
        return NTLMAuthentication1(url, request, info, NTLMfield)

    # check it is the second shakehands
    elif len(NTLMfield) > 4 and NTLMfield[:4] == "NTLM":
        return NTLMAuthentication2(url, request, info, NTLMfield)

    else:
        return lastResult

class NTLMAuthenticationInfo:
    def __init__(self, domain, host, user, passwd):
        self.domain = 'domain'
        self.host = 'host'
        self.user = 'user'
        self.passwd = 'password' 

    def token_type1(self):
        msg = Type1Message(Type1Message.getDefaultFlags(), self.domain, self.host)
        return Base64.encode(msg.toByteArray())

    def token_type3(self, token_type2):
        msg2 = Type2Message(Base64.decode(token_type2))

#if jcifs 1.3.7 using msg3 = Type3Message(msg2, self.passwd, self.domain, self.user, self.host)
        msg3 = Type3Message(msg2, self.passwd, self.domain, self.user, self.host)
        return Base64.encode(msg3.toByteArray())

In the main part the request looks something like this:

result = request101.GET('/')

where request101 has been predefined with URL and header. So, basically, I don’t have a clue how to implement the

I have tried this

result = request101.GET('/')
print str(NTLMAuthentication(result, request101, NTLMAuthenticationInfo))

as well as just this

 NTLMAuthentication(request101.GET('/'), request101, NTLMAuthenticationInfo)

but neither of these worked. Any tips on how to run this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:42:38+00:00Added an answer on June 5, 2026 at 5:42 am

    try this

    ai = NTLMAuthenticationInfo("domain", "your host", "user", "password")
    result = request101.GET('/')
    result = NTLMAuthentication(result, request101, ai)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Been trying to find this online for a while now. I have a SDL_Surface
I have been trying this for a while now and can't get it to
I have been trying to figure this out for a while now, but every
I have been trying this for a good while now but I can't seem
I have been working on this problem for a while now. I am trying
I've looked around for a while now and have not been able to find
I have been using PHPUnit for a while now, but suddenly hit a big
I've been trying to find the best way to do this for a while
I have been trying to understand joins for a while now, I've noticed quite
I have been trying to figure out this problem for a while now and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.