配置 Java Servlet 3.1 支持以实现安全性
Liberty 支持 Java™ Servlet 3.1 规范中定义的所有安全性更新。
有关此任务
利用 Liberty上的 Java Servlet 3.1 功能部件。
过程
- 在
server.xml文件中添加servlet-3.1功能部件:<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元素,那么messages.log文件中将对每个 servlet 中的每个 URL 模式记录一条消息,此消息指示已发现方法,并且带有一个注释,说明这些已发现方法不受保护并且不可访问。 例如: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元素,那么messages.log文件中将对每个 servlet 中的每个 URL 模式记录一条消息,此消息指示已发现方法,并且带有一个注释,说明这些已发现方法不受保护并且可访问。 例如:For URL MyURLPattern in servlet MyServlet, the following HTTP methods are uncovered, and accessible: DELETE OPTIONS HEAD PUT TRACE
- 在登录表单中指定 autocomplete=off。