【问题标题】:How to fix Tomcat WARNING: An attempt was made to authenticate the locked user?如何修复 Tomcat 警告:尝试对锁定的用户进行身份验证?
【发布时间】:2013-02-26 13:16:57
【问题描述】:

我将 Tomcat 7 与 Spring 和 JPA 应用程序、数据库 MySQL 一起使用。 一切正常。但有时会出现 realm.LockOutRealm 身份验证问题。我还在我的应用程序中使用了连接池,例如:

persistence.xml:

<properties>
      <property name="hibernate.connection.username" value="---"/>
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
      <property name="hibernate.connection.password" value="----------"/>
      <property name="hibernate.connection.url" value="jdbc:mysql://----------?autoReconnect=true"/>
      <!--Connection Pooling c3p0 configuration-->
      <!--Minimum number of JDBC connections in the pool. Hibernate default: 1-->
      <property name="hibernate.c3p0.min_size" value="5"/>
      <!--Maximum number of JDBC connections in the pool. Hibernate default: 100-->
      <property name="hibernate.c3p0.max_size" value="20"/>
      <!--When an idle connection is removed from the pool (in second). Hibernate default: 0, never expire.-->
      <property name="hibernate.c3p0.timeout" value="300"/>
      <!--Number of prepared statements will be cached. Increase performance. Hibernate default: 0 , caching is disable.-->
      <property name="hibernate.c3p0.max_statements" value="50"/>
      <!--idle time in seconds before a connection is automatically validated. Hibernate default: 0-->
      <property name="hibernate.c3p0.idle_test_period" value="300"/>
</properties>

server.xml 中的领域如下所示:

<!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

我在网上搜索,但找不到有关此的解决方案。是否有任何人进行蛮力攻击,如果有的话,解决方案是什么。

Catelina.out 中的错误登录是:

Mar 02, 2013 3:28:34 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "tomcat"
Mar 02, 2013 3:29:49 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "tomcat"
Mar 02, 2013 3:31:04 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "tomcat"
Mar 02, 2013 3:37:25 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "admin"
Mar 02, 2013 3:38:47 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "admin"
Mar 02, 2013 3:39:58 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "admin"
Mar 02, 2013 3:46:31 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "coyote"
Mar 02, 2013 3:52:49 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "manager"
Mar 02, 2013 3:59:03 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "administrator"
Mar 02, 2013 4:06:38 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "root"
Mar 02, 2013 4:07:52 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "root"
Mar 02, 2013 4:09:17 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "root"
Mar 02, 2013 4:10:35 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "root"
Mar 02, 2013 4:11:47 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "root"
Mar 02, 2013 4:13:02 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "root"
Mar 02, 2013 4:14:17 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "root"
Mar 02, 2013 4:15:34 PM org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "root"

> Hibernate: select

---------------------------------- 
javax.persistence.PersistenceException: 
org.hibernate.exception.JDBCConnectionException: could not execute query

(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3321)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1940)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2275)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:116)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
    at org.hibernate.loader.Loader.doQuery(Loader.java:674)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    at org.hibernate.loader.Loader.doList(Loader.java:2220)
    ... 39 more
Caused by: java.net.SocketException: Broken pipe

【问题讨论】:

    标签: authentication configuration tomcat7 catalina


    【解决方案1】:

    (致此页面的 16k 访问者:

    由于这是关于 SO,我假设读者是开发人员。)

    此错误表明您有一个脚本/用户尝试使用不正确的用户/密码登录。解决这个问题很简单,只需将正确的用户/密码对添加到文件 ApacheTomcat\conf\<b>tomcat-users.xml</b> 并重新启动服务器。

    还要确保您正确设置了角色。例如。如果您向localhost:8080/manager 发送基本的HTTP 身份验证请求,则需要manager-gui 角色:

    <?xml version='1.0' encoding='utf-8'?>
    <tomcat-users>
      <role rolename="manager-gui"/>
      <user username="foobar" password="foobar" roles="tomcat,role1, manager-gui "/>
    </tomcat-users>
    

    【讨论】:

    • 如果问题是用户不记得密码怎么办?有没有办法在不重启tomcat的情况下解锁账号?
    • 300秒后账户自动解锁(默认)。
    • 我收到此错误是因为我的后端使用的是基本身份验证。即 Tomcat 不应该进行身份验证。无法禁用这些错误?
    【解决方案2】:

    上面的警告意味着您多次验证用户tomcat 失败。 Tomcat怀疑是对用户tomcat的暴力攻击。

    您在应用程序中使用什么身份验证?您在应用程序的 web.xml 中使用什么登录配置?

    resourceName“UserDatabase”的默认配置是文件conf/tomcat-users.xml。 是否更改了resourceName "UserDatabase" 的配置?

    可以在文件server.xml中找到资源UserDatabase的配置:

    <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
                  description="User database that can be updated and saved"
                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                  pathname="conf/tomcat-users.xml" />
    

    默认情况下,所有用户都会被评论。 为了能够使用 XML 文件中的用户,您应该取消注释。然后,您将能够使用用户 tomcat 登录:

    <tomcat-users>
      <role rolename="tomcat"/>
      <user username="tomcat" password="tomcat" roles="tomcat"/>
    </tomcat-users>
    

    最好的问候,

    迈克尔

    【讨论】:

    • 谢谢 Michael。 @Michael:我在 server.xml 中没有改变。它与您粘贴的示例代码相同。而在 tomcat-users.xml 中也与默认副本相同。这里所有的 都被注释掉了。我是否需要取消注释用户才能部署我的应用程序或运行..??我问是因为我有另一个项目,使用不同的机器和 tomcat 7,这在相同的配置下工作正常。在什么情况下我正在尝试或登录用户tomcat。?实际上我没有得到问题出现的实际情况,因为它是随机的,有时会出现这个问题,或者有时不是请建议我
    • @om sharma 如果您使用 Tomcat 身份验证,我仍然需要您的说明。您在应用程序的 web.xml 中使用什么登录配置?基本身份验证的示例: BASIC 如果您使用 Tomcat 身份验证,您需要取消注释文件或定义 Tomcat 领域。如果我的回答符合您的期望,您可以接受并推广它。
    • 赞赏
      在 web.xml 中没有与 login-confi 相关的此类条目。它的默认值我没有手动更改。我正在使用netbeans在tomcat 7上部署应用程序。有什么问题..或者你需要我这边的更多解释吗????? 
    • @om sharma,我检查了 Tomcat 7 源,我可以确认只有当您使用 Tomcat 身份验证或 Tomcat SSO 时,Tomcat 才会调用对所有配置领域的方法进行身份验证。如果您声明不使用 Tomcat 身份验证,则无需取消注释 tomcat-users.xml。此外,在这种情况下不应出现警告。如果它们仅出现在 NetBeans 部署中(而不是在生产中),您可以忽略它们并通过 NetBean 论坛澄清问题。希望对您有所帮助。
    • @Michael:我的系统上安装了两个版本的tomcat。其中一个是我安装的,另一个是在安装时由netbeans 安装的。几天前,我能够很好地运行JSP 项目。但现在它要求我进行身份验证而不是通过身份验证。错误与@OmSharma 相同
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    • 2021-10-29
    • 2021-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多