Tomcat MemoryRealm无法正常工作

时间:2014-07-21 10:33:09

标签: security tomcat authentication web

我创建了一个Web应用程序并配置了tomcat容器来使用tomcat内存域对用户进行身份验证。但它不起作用。以下是我的配置文件

Web.xml中

   <security-constraint>
    <web-resource-collection>
            <web-resource-name>MyFirst</web-resource-name>
            <description> accessible by authenticated users of the tomcat role</description>
            <url-pattern>/eMedicalBookingServer/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
            <http-method>PUT</http-method>
            <http-method>DELETE</http-method>
    </web-resource-collection>
    <auth-constraint>
            <description>These roles are allowed access</description>
            <role-name>admin</role-name>
    </auth-constraint>
</security-constraint>

<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>MyFirst Protected Area</realm-name>
    <!--  
    <form-login-config>
            <form-login-page>/login.html</form-login-page>
            <form-error-page>/autherr.html</form-error-page>
    </form-login-config>
    -->
</login-config>
<security-role>
    <description>Only 'tomcat' role is allowed to access this web application</description>
    <role-name>admin</role-name>
</security-role>

server.xml

<Realm className="org.apache.catalina.realm.MemoryRealm" />

tomcat-users.xml

<tomcat-users>
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="admin"/>
<role rolename="superuser"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="ars" password="pass" roles="superuser"/>
<user username="ad1" password="pass" roles="admin"/>
</tomcat-users>

以下是启动tomcat后的控制台输出

Jul 21, 2014 6:20:53 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in          production environments was not found on the java.library.path:     
.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
Jul 21, 2014 6:20:53 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property     'source' to 'org.eclipse.jst.jee.server:eMedicalBookingServer' did not find a matching property.
Jul 21, 2014 6:20:54 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jul 21, 2014 6:20:54 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["http-nio-8443"]
Jul 21, 2014 6:20:54 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Jul 21, 2014 6:20:54 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2095 ms
Jul 21, 2014 6:20:54 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jul 21, 2014 6:20:54 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.54
Jul 21, 2014 6:20:55 PM org.apache.tomcat.websocket.server.WsSci onStartup
INFO: JSR 356 WebSocket (Java WebSocket 1.0) support is not available when running on    Java 6. To suppress this message, run Tomcat on Java 7, remove the WebSocket JARs from   $CATALINA_HOME/lib or add the WebSocket JARs to the   tomcat.util.scan.DefaultJarScanner.jarsToSkip property in    $CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API    will be available. 
Jul 21, 2014 6:20:57 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 21, 2014 6:20:57 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8443"]
Jul 21, 2014 6:20:57 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2513 ms

请您查看此配置中的错误。当我打开以下链接时

http://localhost:8080/eMedicalBookingServer/index.html

它没有提示输入用户凭据。

0 个答案:

没有答案