Eclipseでユーザー認証するには
【環境条件】
OS;win7
IED;Eclipse4.4(ルナ)
サーバー;Tomcat8.0.33
【ユーザー認証方法】
①BASIC認証用のサーブレットを用意する
BASIC認証(サーブレットの用意)
②web.xmlを書く
BASIC認証(web.xmlの編集)
セキュリティロールの概略

実際の例

【サーブレットの実行】
トムキャットを
ブラウザで「http://localhost:8080/auth/AuthTest1」へアクセスすると、Windowセキュリティ画面が立ち上がる。

その画面に、ユーザー名とパスワード入れると、サーブレットが開く

【エラー表示】
Windowセキュリティ画面からユーザー名とパスワードを入れて下記のようなエラーを出たら

Windowセキュリティ画面からユーザー名とパスワードを入れて下記のようなエラーを出たら、Eclipseのプロジェクト「Servers」の「tomcat-users.xml」を調べる

【tomcat-users.xml】

下記のところを確認!
<tomcat-users version="1.0" xmlns="http://tomcat.apache.org/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd">
<user password="0000" roles="admin-gui,manager-gui" username="nnnn"/>←ここ確認
もし、設定されていなかったら、自分に合ったように書き換える
参照サイト→BASIC認証(UserDatabaseRealmレルム)
ただし、Tomcatのバージンによってはrolesの設定が異なる
【再インストルTomcat】
どうしても、HTTPステータス403のエラーが出るなら、再びTomcatのインストールをする。その時、必ずユーザー名とパスワードを入れる。

更に、EclipseのServers設定を更新するのを忘れてはならない!
【動作確認】
Eclipseからサーバを立ち上げ、ブラウザから「http://localhost:8080/」にアクセスする

続いて、右側の「Manager add」ボタンを押す、Windowセキュリティ画面からユーザー名とパスワードを入れて成功すると、下記のように成る。
