This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Automatic Basic Authentication

 
Deyan Sultov
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

[Background]
I have a simple JSP - Servlet application that user interacts with. There is a possibility user to define a set of URL's(as well as user/pass if they are protected) which later he can visit by pressing a button. The user should be able to log authomatically no matter whether these sites are pass protected.

[Problem]
One of these sites uses Basic Authentication. Is is possible to implement an authomatic login in this case. I tried the following mechanism but it didn't work:

String userPassword = theUsername + ":" + thePassword;
String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
response.setHeader("Authorization", "Basic " + encoding);
response.sendRedirect('URL to GO');

Please can you help me.

Thanks in advance,
Deyan
[ May 05, 2005: Message edited by: Deyan Sultov ]
 
Thomas Mcfarrow
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I would try using the RequestDispatcher.forward(......). The end result of redirect won't have the headers or parameters set. Forward passes the values on

Regards.
 
Deyan Sultov
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean to try something like
RequestDispatcher rd = request.getRequestDispatcher("URL to GO");
response.setHeader("Authorization", "Basic " + encoding);
rd.forward(request, response);

Unfortunately the request.getRequestDispatcher(String path) expects a path which is not outside of the current context. In my case the path is of a completely different site.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you're going to be able to do this from the server.

You used to be able to build links that looked like:
http://USER:PASSWORD@DOMAIN

This capability has recently been pulled from MSIE. I think it still works in Mozilla and Firefox.

[ May 09, 2005: Message edited by: Ben Souther ]
[ May 09, 2005: Message edited by: Ben Souther ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic