servlet et .htaccess

S

Steve

Hello,

i'm trying to access a file with a servlet (to read it) This file is
protected by the .htaccess file. Each time i get the error : Server
returned HTTP response code: 401, that means no access...
How can i resolve my problem ? Is my .htaccess configuration false ?
Here is it :
AuthUserFile /etc/apache/htpasswd
AuthName "Accès administration"
AuthType Basic
require valid-user
Order deny,allow
allow from 127.0.0.1
allow from localhost

Thanks for your help

Steve
 
M

Michael Scovetta

AFAIK, that won't work, because .htaccess is recognized and used by
Apache to implement arbitrary security that is separated from OS
security. Since Apache does NOT run Servlets, it doesn't control
internal Servlet security, that's left to the O/S.

Unless someone wants to correct me, there may some sort of "Hi I'm
Tomcat, but I'll use Apache's .htaccess file anyway", or maybe Apache
could use .htaccess before the request is proxied over to Tomcat?

Wait, how are you "reading" this file? Are you opening up a
URLConnection and loading the file from localhost? In that case, you
need to pass the Basic connection authentication information over
through the URLConnection object:

URL url = new URL (urlString);
String encoding = new sun.misc.BASE64Encoder()
.encode("username:password".getBytes());
URLConnection uc = url.openConnection();
uc.setRequestProperty ("Authorization", "Basic " + encoding);

and go from there.

-Michael Scovetta
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top