添加安全配置时,GWT Web应用程序会抛出503错误

时间:2017-05-03 08:23:29

标签: servlets gwt jetty security-constraint

我是GWT的新手。我想为现有的webapp添加安全性。 这是我的web.xml的内容:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_1342051730046" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>index pages</web-resource-name>
            <url-pattern>/</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>admin</role-name>
        </auth-constraint>
    </security-constraint>
    <security-role>
        <role-name>admin</role-name>
    </security-role>

    <filter>
        <description>Initialises Guice</description>
        <filter-name>guiceFilter</filter-name>
        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>guiceFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>TEST</realm-name>
    </login-config>

</web-app>

没有安全限制,应用程序运行正常。但是,如果它存在于web.xml中,则会在尝试呼叫远程服务时收到以下错误503服务不可用。

这就是我如何配置Jetty以包含领域:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
    <Set name="contextPath">/fnd</Set>
    <Get name="securityHandler">
        <Set name="userRealm">
            <!-- NOTE: This config is duplicated in the pom (jetty plugin) -->
            <New class="org.mortbay.jetty.security.HashUserRealm">
                <Set name="name">User realm</Set>
                <Set name="config"><SystemProperty name="jetty.home" default="."/>/realm.properties
                </Set>
            </New>
        </Set>
    </Get>
</Configure>

和realm.properties一样,在classpath中:

# Usernames and passwords for the Jetty deployment
admin:admin,admin

此配置有什么问题吗?我希望在访问索引页面时显示基本身份验证对话框。

0 个答案:

没有答案