针对安全性配置 Java Servlet 3.1 支持
WebSphere® Application Server(传统) 支持 Java™ Servlet 3.1 规范中定义的所有安全性更新。
关于此任务
在 WebSphere Application Server(传统) 中利用 Java Servlet 3.1 功能。
过程
- 将 servlet-3.1 功能添加到 server.xml 文件:
<feature>servlet-3.1</feature>
- 确定要使用下列哪项 Java Servlet 3.1 功能:
- 在登录表单中指定 autocomplete=off。
如果您对表单登录页面使用 HTML,请将密码表单字段设置为 autocomplete="off",以便在 Web 浏览器中禁用自动填写密码。例如:
<form method="POST" action="j_security_check"> <input type="text" name="j_username"> <input type="password" name="j_password" autocomplete="off"> </form>
- 指定所有认证安全性约束 (**)。
特殊角色名 ** 指示任何已认证的用户。如果授权约束中显示 **,那么认证用户后,该用户将可以访问此约束中指定的方法。用户无需映射到应用程序绑定中的此角色。例如:
<security-constraint id="SecurityConstraint_1"> <web-resource-collection id="WebResourceCollection_1"> <web-resource-name>Protected with ** role</web-resource-name> <url-pattern>/AnyAuthSecurityConstraint</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <auth-constraint id="AuthConstraint_1"> <role-name>**</role-name> </auth-constraint> </security-constraint>
使用角色名 ** 调用 isUserInRole() 方法时,如果已认证用户,那么 isUserInRole() 将返回 true。如果 ** 是安全角色中的配置中定义的角色,那么系统不会将其作为特殊的任何已认证的用户角色处理。必须将用户映射到应用程序绑定中的该角色才能使 isUserInRole 返回 true。
- 在 web.xml 文件中指定 deny-uncovered-http-methods 标志。
如果在 web.xml 文件中指定了 deny-uncovered-http-methods 元素,那么容器将拒绝任何未涵盖的 HTTP 方法,即,未在请求 URL 的最佳匹配 URL 模式的组合安全性约束中列举的方法。将返回 403 (SC_FORBIDDEN) 状态码。 例如:
<servlet-mapping id="ServletMapping_1"> <servlet-name>MyServlet</servlet-name> <url-pattern>/MyURLPattern</url-pattern> </servlet-mapping> <deny-uncovered-http-methods/> <!-- SECURITY CONSTRAINTS --> <security-constraint id="SecurityConstraint_1"> <web-resource-collection id="WebResourceCollection_1"> <web-resource-name>Protected with Employee or Manager roles</web-resource-name> <url-pattern>/MyURLPattern</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <auth-constraint id="AuthConstraint_1"> <role-name>Employee</role-name> <role-name>Manager</role-name> </auth-constraint> </security-constraint>
如果在 web.xml 文件中指定了 deny-uncovered-http-methods 元素,那么对于每个 Servlet 中的每个 URL 模式,将在 messages.log 文件中记录一条消息,指出未涵盖的方法并提供有关这些未涵盖方法不受保护且不可访问的注释。例如:For URL MyURLPattern in servlet MyServlet, the following HTTP methods are uncovered, and not accessible: DELETE OPTIONS HEAD PUT TRACE
如果未在 web.xml 文件中指定了 deny-uncovered-http-methods 元素,那么对于每个 Servlet 中的每个 URL 模式,将在 messages.log 文件中记录一条消息,指出未涵盖的方法并提供有关这些未涵盖方法不受保护且可访问的注释。例如:For URL MyURLPattern in servlet MyServlet, the following HTTP methods are uncovered, and accessible: DELETE OPTIONS HEAD PUT TRACE
- 在登录表单中指定 autocomplete=off。
结果


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tsec_servlet31
文件名:tsec_servlet31.html