473,385 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

LWP Authentication is not sticking

Hi,
I use LWP::UserAgent to automate windows login process. I set the credentials using $ua->credentials("host:port","realm","id","password" ); 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 4217
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 Expert Mod 2GB
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
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
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
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...
0
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...
7
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. #...
8
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...
6
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...
9
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...
0
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...
18
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.