473,706 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LWP Authentication is not sticking

4 New Member
Hi,
I use LWP::UserAgent to automate windows login process. I set the credentials using $ua->credentials("h ost:port","real m","id","passwo rd"); but it fetches only the current page requested. It fails for subsequent requests and pops up the windows form again to supply the credentials. I have created a cookie jar too but this doesnt help as the authentication is not sticking. Any help on this is highly appreciated.

The code is as follows.
Expand|Select|Wrap|Line Numbers
  1. # Module: authenticate.pl
  2. # @author Kiran Kamath
  3.  
  4. #flush the buffer
  5. $|=1;
  6. use CGI;
  7. use CGI::Request;
  8.  
  9. use LWP::UserAgent;
  10. use HTTP::Request;
  11. use LWP::ConnCache;
  12. use HTTP::Cookies;
  13. use LWP::DebugFile;
  14.  
  15. # Configurations required for the script 
  16. require "authvar.ph";
  17. use POSIX qw(strftime);
  18.  
  19. # Set up Alert log
  20.  
  21. open(ALERTS,"$AUTH_LOG") or warn "Cannot open alert log file:$!";
  22. $AlertDate=`date $AUTH_DATE_FORMAT`;
  23. chomp($AlertDate);
  24.  
  25. print ALERTS "$AlertDate authenticate-module entry\n\n" if($AUTH_DEBUG);
  26.  
  27. #Get username and password from POST message
  28.  
  29. $req = GetRequest($pkg);
  30. $uid=$req->param('uid');
  31. $passwd=$req->param('passwd');
  32. my $timeout=10;
  33. $uid=some id ;
  34. $passwd=some passwd ;
  35.  
  36. if(defined($uid) && defined($passwd))
  37. {
  38.     chomp($uid); chomp($passwd);
  39.     print ALERTS "$AlertDate [ UID=$uid , PASSWD=$passwd ]\n";
  40.  
  41.  
  42.     my($res,$request);
  43.  
  44.     # LWP::UserAgent is a class implementing a web user agent used to dispatch web requests.
  45.     $ua = LWP::UserAgent->new();
  46.     $ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727)');
  47.  
  48.     #Set the timeout so that requests is aborted if no activity on the connection to the server is observed for timeout seconds.
  49.     $ua->timeout($timeout);
  50.  
  51.  
  52.     # Set the credentials for a realm 
  53.     $ua->credentials("$AUTH_DOMAIN:$AUTH_PORT","$AUTH_NAME","$uid","$passwd");
  54.  
  55.     # LWP::ConCache is used for the browser to support HTTP Keep-Alive
  56.     # This is required so that after the request is performed connection is not lost and is persistent.
  57.  
  58.     $cache=$ua->conn_cache(LWP::ConnCache->new());
  59.  
  60.     # Cache all the connections
  61.     $ua->conn_cache->total_capacity(undef);
  62.  
  63.     $cookie_jar=HTTP::Cookies->new();
  64.     $cookie_jar->set_cookie("1","nortelid","axptnrtl","/","naxptsts.intec.telcordia.com","4443",1,1,3600,0);
  65.  
  66.     # Give the browser an in-memory empty cookie jar
  67.     $ua->cookie_jar($cookie_jar);
  68.     $ua->default_header('Accept-Language'=>'en-us');
  69.     $ua->default_header('Accept-Encoding'=>'gzip, deflate');
  70.     #$ua->default_header('Accept'=>'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*');
  71.     $ua->default_header('Accept'=>'*/*');
  72.  
  73.  
  74.     $request = new HTTP::Request('GET', $AUTH_URI);
  75.  
  76.     $cookie_jar->add_cookie_header($request);    
  77.  
  78.     $res=$ua->request($request);
  79.  
  80.     $cookie_jar->extract_cookies($res);
  81.  
  82.     my $status = $res->code;
  83.     print ALERTS "$AlertDate Return Status for $AUTH_URI was $status\n";
  84.  
  85.     if($res->is_success){
  86.         $status_message=$res->as_string;
  87.         #print ALERTS "$AlertDate [DEBUG STATUS MESSAGE=$status_message]\n\n";
  88.         print $res->content;
  89.         print ALERTS "$AlertDate [Success Redirecting]\n\n";
  90.     }
  91.     else
  92.     {
  93.         print ALERTS "$AlertDate [Authenticate Header= " . $res->header('WWW-Authenticate') . "]\n";
  94.         print ALERTS "$AlertDate [ERROR STATUS: " .$res->status_line. "]\n\n";
  95.     }
  96. }
  97.  
  98. print ALERTS "$AlertDate authenticate-module exit\n\n" if($AUTH_DEBUG);
  99. close(ALERTS);
  100.  

Thanks
Kiran
Sep 22 '07 #1
4 4228
kkamath
4 New Member
Hi,
I got the script working when i use webserver url (http). However it doesnt work when going through a proxy server (https). After displaying the initial page it prompts for credentials. This doesnt happen with http. I set env proxy in the script. It handles subsequent requests too. In case of https (proxy server), it doesnt maintaain the credentials for a particular realm.


Any help on this is appreciated.


Thanks
Kiran Kamath
Sep 24 '07 #2
numberwhun
3,509 Recognized Expert Moderator Specialist
Hi,
I got the script working when i use webserver url (http). However it doesnt work when going through a proxy server (https). After displaying the initial page it prompts for credentials. This doesnt happen with http. I set env proxy in the script. It handles subsequent requests too. In case of https (proxy server), it doesnt maintaain the credentials for a particular realm.


Any help on this is appreciated.


Thanks
Kiran Kamath
The reason that doesn't happen for HTTP is because HTTP is not an authenticated, secure session. HTTPS denotes an SSL session that is authenticated and secure. If you are using it, then you should setup to handle it. I haven't played with LWP yet, but I am sure that the documentation would go over this.

Regards,

Jeff
Sep 24 '07 #3
kkamath
4 New Member
The reason that doesn't happen for HTTP is because HTTP is not an authenticated, secure session. HTTPS denotes an SSL session that is authenticated and secure. If you are using it, then you should setup to handle it. I haven't played with LWP yet, but I am sure that the documentation would go over this.

Regards,

Jeff
The documentation doesnt describe anything on this. Can the ACL's on the proxy server be configured to get this working?

Thanks
Kiran
Sep 24 '07 #4
kkamath
4 New Member
Hi,
How to make authentication stick to subsequent pages using LWP . I tried creating cookies after authentication against a realm. but subsequent requests asks for credentials. Anyone knows how to accomplish this? Any help is highly appreciated.


Thanks
Kiran
Sep 26 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
2142
by: Mark H | last post by:
Hey all-- I'm building a database and I basically need to keep out people who aren't authorized, but it's not like I need top security here. I'm just doing basic user/pass of a SQL database, and when a user authenticates I start a session for him. My question is, is there any way for a hacker to easily start a session without having logged in? For instance, if I save the user name and IP address in the session will it be relatively...
0
1751
by: Jp Calderone | last post by:
I've been trying to implement support for this authentication scheme for a little while now, and in the last couple days I've been completely stumped. I know about the digest authentication code in urllib2, and while I'd like to use it directly, it is too closely tied to HTTP for my needs. I have taken hints from the code, but I am still stuck with something that doesn't recognize correct challenge responses as correct. I've reduced...
7
9286
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. # No warranty express or implied for the accuracy, fitness to purpose
8
3707
by: Bob Everland | last post by:
I have an application that is ISAPI and the only way to secure it is through NT permissions. I need to have a way to login to windows authentication so that when I get to the ISAPI application no boxes come up. I want an ASP page to sit between the user and the ISAPI application. The rest of my application is using authentication that is database driven and wouldn't want the users to know the userid and password. Is this possible? If so...
6
4832
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms Authentication set up and it worked just fine. Then I realized that I needed to have some pages unsecure. I then created 2 directories. One named Secure and the other named Public. I placed my web.config file in my
9
2507
by: Tom B | last post by:
In my web.config file I've specified Windows for the authentication, in IIS I've set it to Integrated Authentication. But my SQL connection is still showing Anonymous. Is there somewhere else I need to check? Thanks Win 2003, SQL Server 2000
0
4235
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET Applications and owner of Access Microsystems. Doug can be reached at doug@accessmicrosystems.com. --------------------------------------------------------------------------------
18
6874
by: Rippo | last post by:
Hi I am using role base forms authentication in asp.net and have come across a problem that I would like advice on. On a successful login a session variable is set to identify a user. This is all good as this session variable is used to retrieve data for that user etc. However if I restart the webserver then the users session is lost but the ticket is still active. Therefore the user is not redirected back to the login page.
2
7516
by: Frank Swarbrick | last post by:
I am trying to understand "client authentication" works. My environment is DB2/UDB LUW 8.2 on zSeries SLES9 as the database server and DB2 for VSE 7.4 as the client. We currently have DB2/LUW set up as follows: Client Userid-Password Plugin (CLNT_PW_PLUGIN) = Client Kerberos Plugin (CLNT_KRB_PLUGIN) = Group Plugin (GROUP_PLUGIN) = GSS Plugin for Local Authorization ...
0
9287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7912
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5939
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4710
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2503
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2096
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.