Websphere:web.xml中的security-constraint不起作用

时间:2011-02-21 15:39:57

标签: websphere web.xml

我想保护单个.jsp页面免受匿名访问。我试图通过以下方式做到这一点:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
t-webapp</display-name>
<servlet>
<servlet>
    <description>
    </description>
    <display-name>
    ZServlet</display-name>
    <servlet-name>ZServlet</servlet-name>
    <servlet-class>
    a.b.c.d.application.t.ZServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>ZServlet</servlet-name>
    <url-pattern>/ZServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<security-constraint>
    <display-name>
    TTests</display-name>
    <web-resource-collection>
        <web-resource-name>TTests</web-resource-name>
        <url-pattern>/ttests.jsp</url-pattern>
        <http-method>GET</http-method>
        <http-method>PUT</http-method>
        <http-method>HEAD</http-method>
        <http-method>TRACE</http-method>
        <http-method>POST</http-method>
        <http-method>DELETE</http-method>
        <http-method>OPTIONS</http-method>
    </web-resource-collection>
    <auth-constraint>
        <description>
        TServletRoles</description>
        <role-name>role_admin1</role-name>
    </auth-constraint>
    <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>
<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.html</form-login-page>
        <form-error-page>/error.html</form-error-page>
    </form-login-config>
</login-config>
<security-role>
    <description>
    role_admin1</description>
    <role-name>role_admin1</role-name>
</security-role>

但是每当我访问ttests.jsp时,我都会立即访问 - 无需填写用户名/密码......我缺少什么?

非常感谢!

1 个答案:

答案 0 :(得分:4)

第一步是确保在您的websphere配置文件上启用了全局安全性,并选中了启用应用程序安全性复选框。