2010-11-12 97 views
1

我有一個Tomcat 5.5服務器,我在上面部署了一個應用程序。 我有類似的東西http://tocatServer:8088/MyApp 我想通過輸入用戶名和密碼來限制這個地址的用戶訪問量,但我需要幫助。我知道我必須在web.xml上添加角色,我嘗試了但沒有成功。 如果可能的話我想給的網址這樣 http://username:[email protected]:8088/MyApp 這個網址是從Java Swing應用程序發送從serlet獲得許可 感謝在Tomcat 5.5應用程序上配置用戶名和密碼

回答

2

要限制訪問Web應用程序(或文件夾在webapp URL)在Tomcat中:

webapps/MyApp/WEB-INF/web.xml添加

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name> 
      Entire webapp 
     </web-resource-name> 
     <url-pattern>/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>member</role-name> 
    </auth-constraint> 
</security-constraint> 
<login-config> 
    <!-- pay attention: BASIC in insecure, use it only for test, search for a more secure method --> 
    <auth-method>BASIC</auth-method> 
    <realm-name>Text reported when prompting the user for un and pw</realm-name> 
</login-config> 

conf/tomcat-users.xml添加

<role rolename="member"/> 
<user username="bubi" password="bubi" roles="member"/> 

然後重新加載webapp並可能重新啓動Tomcat。

來源:O'Reilly's Top Ten Tomcat Configuration Tips - 5. Configuring Basic Authentication

關於第二個問題,我不知道如何去實現它。