2013-02-23 68 views
15

我正在嘗試登錄tomcat管理器應用程序,但我無法在tomcat-users.xml中成功創建登錄用戶。 最初的內容是這樣的:Tomcat 7管理器 - 如何驗證?

<?xml version="1.0" encoding="UTF-8"?> 
<!-- 
    Licensed to the Apache Software Foundation (ASF) under one or more 
    contributor license agreements. See the NOTICE file distributed with 
    this work for additional information regarding copyright ownership. 
    The ASF licenses this file to You under the Apache License, Version 2.0 
    (the "License"); you may not use this file except in compliance with 
    the License. You may obtain a copy of the License at 

     http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, software 
    distributed under the License is distributed on an "AS IS" BASIS, 
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
    See the License for the specific language governing permissions and 
    limitations under the License. 
--><tomcat-users> 
<!-- 
    NOTE: By default, no user is included in the "manager-gui" role required 
    to operate the "/manager/html" web application. If you wish to use this app, 
    you must define such a user - the username and password are arbitrary. 
--> 
<!-- 
    NOTE: The sample user and role entries below are wrapped in a comment 
    and thus are ignored when reading this file. Do not forget to remove 
    <!.. ..> that surrounds them. 
--> 
<!-- 
    <role rolename="tomcat"/> 
    <role rolename="role1"/> 
    <user username="tomcat" password="tomcat" roles="tomcat"/> 
    <user username="both" password="tomcat" roles="tomcat,role1"/> 
    <user username="role1" password="tomcat" roles="role1"/> 
--> 
</tomcat-users> 

閱讀on the official page我修改的文件這樣的,但沒有結果。

<?xml version="1.0" encoding="utf-8"?> 
<tomcat-users> 
    <role rolename="manager-gui"/> 
    <role rolename="manager-status"/> 
    <role rolename="manager-script"/> 
    <role rolename="manager-jmx"/> 
    <user username="admin" password="admin" roles="manager-gui"/> 
</tomcat-users> 
+0

嘗試重新啓動tomcat,它有時會有所幫助。 – Kapep 2013-02-23 16:26:02

+0

我重新啓動了服務,結果相同。 :( – 2013-02-23 16:58:28

+1

@JackWillson以前的答案是錯誤的,因爲管理員角色之間不應該有任何空格,因爲這個列表應該用逗號分隔它必須是這樣的: 2014-06-09 10:53:06

回答

23

看來這是正確的配置。注意不要將角色與空間分開!

​​
+1

正如這裏指出的那樣(http ://stackoverflow.com/questions/18746195/tomcat-7-manager-cant-login)角色之間不能有任何空間,所以這應該是這樣的: 2014-06-09 10:57:20

5

你不應該與經理腳本或-jmx角色結合起來,因爲損害跨站點腳本保護的經理桂角色。最後的經理角色不能像gui角色那樣受到保護。

8

接受的答案在一個細節上是錯誤的,但非常重要的一個 - 管理員的角色之間不應有任何空格,因爲此列表應該用逗號分隔(如在此指出Tomcat 7 Manager can't login)。我有同樣的問題,並以同樣的方式解決。

所以,與其這樣(在一些答案建議:

<user username="admin" password="admin" roles="manager-gui, manager-script, manager-jmx, manager-status, admin-gui, admin-script"/> 

它必須是這樣的:

<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/> 

所以乾脆就應該是這樣的:

<?xml version="1.0" encoding="UTF-8"?> 
<tomcat-users> 
    <role rolename="manager-gui"/> 
    <role rolename="manager-script"/> 
    <role rolename="manager-jmx"/> 
    <role rolename="manager-status"/> 
    <role rolename="admin-gui"/> 
    <role rolename="admin-script"/> 
    <user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/> 
</tomcat-users> 
0

您已添加管理角色用戶以訪問此功能。要編輯tomcat-users.xml文件 apache-tomcat-7.0.56-windows-x64\apache-tomcat-7.0.56\conf如果你在窗戶上。搜索<role rolename= >行。這將有可能評論。添加此代碼: -

<role rolename="manager-gui"/> 
<user username="your-user-name" password="your-password" roles="manager-gui,manager-script"/> 
+0

從https://tomcat.apache.org/tomcat-7。0-doc/manager-howto.html 「建議不要將manager-script或manager-jmx角色授予具有manager-gui角色的用戶。」 – gliptak 2017-03-27 14:05:40

2

您是否在conf文件夾的server.xml中配置了數據庫領域?默認的server.xml中已經安裝了UserDatabase資源,所以如果你已經改變了,那麼無論你如何設置tomcat-user xml,你都無法進行身份驗證。

在conf/server.xml文件中... 在GlobalNamingResource標記中定義資源以使用MemoryUserDatabaseFactory並在您的引擎中定義Realm以使用UserDatabaseRealm。只需打開原始的server.xml(我正在使用tomcat 7.0.62)並搜索這些名稱,您將看到配置。根據您的應用和需求,您可能需要進行其他更改。

+0

這對我來說是個問題,對於tomcat用戶沒有任何改變會像Denise說的那樣改變,如果sserver xml已被修改並且缺少這個 - 如果在嘗試tomcat-users.xml更改後出現相同的身份驗證問題嘗試這個! – RMSTOKES 2016-04-12 09:41:55