473,766 Members | 2,055 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 4232
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
2144
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
1763
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
9290
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
3708
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
4840
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
2510
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
4248
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
6880
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
7520
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
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10008
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
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
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
7381
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
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
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
3
2806
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.