可配置 Liberty 应用程序客户机容器以使用定制 Java™ 认证和授权服务 (JAAS) 登录模块。
开始之前
请确保您有一个 JAR 文件包含 JAAS 定制登录模块,此模块用来实现
javax.security.auth.spi.LoginModule 接口。
关于此任务
可以使用定制登录模块来作出其他认证决策,或者在主体集中添加信息以在应用程序内部作出更细颗粒度的权限决策。要配置 JAAS 定制登录模块,请完成以下步骤。
过程
- 将 appSecurityClient-1.0 功能部件添加至 client.xml 文件。
<feature>appSecurityClient-1.0</feature>
- 创建用于实现 LoginModule 接口的 com.sample.CustomLoginModule 类并将其打包到
CustomLoginModule.jar 文件中。
- 创建一个 <library> 元素,该元素使用一个
<fileset> 元素指示 CustomLoginModule.jar 文件所在的位置。在此示例中,该文件在客户机的配置目录中,库标识为 customLoginLib。
<library id="customLoginLib">
<fileset dir="${server.config.dir}" includes="CustomLoginModule.jar"/>
</library>
- 创建 <jaasLoginModule> 元素。在此示例中,id 为 myCustom。
- 通过将 controlFlag 属性设置为 REQUIRED,将定制登录模块配置为需要成功认证。
- 将 libraryRef 属性设置为 customLoginLib(上一步中配置的 <library> 元素的标识)。
<jaasLoginModule id="myCustom" className="com.sample.CustomLoginModule" controlFlag="REQUIRED" libraryRef="customLoginLib"/>
- 在应用程序客户机容器 ClientContainer 上创建 <jaasLogincontextEntry> 元素,此元素带有系统定义的
JAAS 配置的标识和名称。您还可以将此 JAAS 配置设置为 WSLogin 或您自己的 JAAS 配置。在 loginModuleRef
属性中,添加 proxy(代理登录模块的标识)和 myCustom(上一步中创建的 jaasLoginModule 元素的标识)。
<jaasLoginContextEntry id="ClientContainer" name="ClientContainer"
loginModuleRef="proxy, myCustom"/>