Liberty 安全性入门
可以使用 <quickStartSecurity> 元素来对 Liberty 快速启用简单(单用户)安全性设置。
关于此任务
您可以遵循一些最低配置步骤来设置安全 Liberty 服务器和 Web 应用程序。Liberty 中的配置操作是动态的,这意味着不必重新启动服务器,配置更新即可生效。
过程
- 创建和启动服务器。
在 Windows 系统上:
服务器.bat create MyNewServer 服务器.bat start MyNewServer
在 Windows 系统之外的所有系统上:
服务器 create MyNewServer 服务器 start MyNewServer
- 在 server.xml 文件中包括 appSecurity-2.0 和 servlet-3.0 功能部件。
server.xml 文件位于 myNewServer 的服务器目录中,例如,wlp\usr\servers\myNewServer\server.xml。
<featureManager> <feature>appSecurity-2.0</feature> <feature>servlet-3.0</feature> </featureManager>
- 定义要授予其服务器管理活动 Administrator 角色的用户名和密码。
<quickStartSecurity userName="Bob" userPassword="bobpwd" />
注: 选择对您有意义的用户名和密码。切勿对应用程序使用示例中的名称和密码。 - 使用相关安全性约束来配置部署描述符以保护 Web 资源。例如,使用 <auth-constraint> 和 <role-name> 元素来定义可以访问 Web 资源的角色。 以下示例 web.xml 文件显示对应用程序中所有 URI 的访问权是受 testing 角色保护。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app id="myWebApp"> <!-- SERVLET DEFINITIONS --> <servlet id="Default"> <servlet-name>myWebApp</servlet-name> <servlet-class>com.web.app.MyWebAppServlet</servlet-class> <load-on-startup/> </servlet> <!-- SERVLET MAPPINGS --> <servlet-mapping id="ServletMapping_Default"> <servlet-name>myWebApp</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <!-- SECURITY ROLES --> <security-role> <role-name>testing</role-name> </security-role> <!-- SECURITY CONSTRAINTS --> <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>testing</role-name> </auth-constraint> </security-constraint> <!-- AUTHENTICATION METHOD: Basic authentication --> <login-config> <auth-method>BASIC</auth-method> </login-config> </web-app>
- 在 server.xml 文件中配置应用程序。 在以下示例中,用户 Bob 映射到应用程序的 testing 角色:
<application type="war" id="myWebApp" name="myWebApp" location="${server.config.dir}/apps/myWebApp.war"> <application-bnd> <security-role name="testing"> <user name="Bob" /> </security-role> </application-bnd> </application>
- 使用用户名 Bob 来访问应用程序并登录。 myWebApp 应用程序的缺省 URL 是 http://localhost:9080/myWebApp
结果
子主题
- Liberty:安全性快速概述
为了解 Liberty 中安全性的基本工作流程,详细介绍了一些常见安全性术语以及示例。 - 在 Liberty 上设置 BasicRegistry 和角色映射
可以配置 Liberty 以使用基本用户注册表来认证和授权用户。
父主题: 保护 Liberty 及其应用程序
相关任务:


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