HTTP Basic Authentication
Posted on 2001-06-29
I am trying to authenticate users into the website by using the HTTP Basic Authentication. The users are then authenticated into the webserver. I am using Websphere for this purpose.
Then I am using the following code within the servlet to extract the entered user id and password.
String authorization = request.getHeader("Authorization");
String user_text=new String();
String password_text=new String();
if (authorization == null)
htmlOutputStream.print("Unable to find the Authorization Info !!");
String userInfo = authorization.substring(6).trim();
BASE64Decoder decoder = new BASE64Decoder();
String namePassword = new String(decoder.decodeBuffer(userInfo));
int index = namePassword.indexOf(":");
user_text = namePassword.substring(0, index);
password_text = namePassword.substring(index+1);
userID = new String (user_text);
password = new String (password_text);
if (authorization != null)
htmlOutputStream.print("Now to display the user ID and password ");
However, authorization always returns null. What is the problem...
1. Is my header wrong?
2. Is the information not coming into the servlet request?
3. Is there anything wrong with my code?
Please let me know