servlet et .htaccess

Discussion in 'Java' started by Steve, May 6, 2004.

  1. Steve

    Steve Guest

    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
    Steve, May 6, 2004
    #1
    1. Advertising

  2. 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



    (Steve) wrote in message news:<>...
    > 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
    Michael Scovetta, May 6, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    4
    Views:
    2,399
    Andy Fish
    Dec 17, 2003
  2. Sean Clarke
    Replies:
    1
    Views:
    1,878
    Sudsy
    Jan 7, 2004
  3. circuit_breaker
    Replies:
    2
    Views:
    1,981
    Jack Jia
    Apr 4, 2004
  4. chamikara
    Replies:
    1
    Views:
    49,831
  5. DiscoStu
    Replies:
    0
    Views:
    492
    DiscoStu
    Jul 8, 2004
Loading...

Share This Page