信任关联拦截器

improve this page | report issue


概述

IBM Mobile Foundation 提供 Java 库以便于通过 IBM WebSphere 信任关联拦截器对外部资源进行认证。

Java 库是作为 JAR 文件 (com.ibm.mfp.oauth.tai-8.0.0.jar) 提供的。

本教程显示如何使用作用域 (accessRestricted) 来保护简单 Java Servlet TAI/GetBalance

先决条件:

流程

服务器设置

  1. MobileFirst Operations Console → 下载中心 → 工具选项卡下载安全工具 .zip。 您将在其中找到 mfp-oauth-tai.zip 归档。 解压缩此 zip。
  2. com.ibm.mfp.oauth.tai.jar 文件添加到 usr/extension/lib 中的 WebSphere Application Server 实例。
  3. OAuthTai.mf 文件添加到 usr/extension/lib/features 中的 WebSphere Application Server 实例。

web.xml 设置

将安全性约束和安全角色添加到 WebSphere Application Server 实例的 web.xml 文件:

<security-constraint>
   <web-resource-collection>
      <web-resource-name>TrustAssociationInterceptor</web-resource-name>
      <url-pattern>/TAI/GetBalance</url-pattern>
   </web-resource-collection>
   <auth-constraint>
      <role-name>TAIUserRole</role-name>
   </auth-constraint>
</security-constraint>

<security-role id="SecurityRole_TAIUserRole">
   <description>This is the role that Mobile Foundation OAuthTAI uses to protect the resource, and it is mandatory to map it to 'All Authenticated in Application' in WebSphere Application Server full profile and to 'ALL_AUTHENTICATED_USERS' in WebSphere Application Server Liberty.</description>
   <role-name>TAIUserRole</role-name>
</security-role>

server.xml

将 WebSphere Application Server server.xml 文件修改为您的外部资源。

  • 配置功能管理器以包含以下功能:

    <featureManager>
             <feature>jsp-2.2</feature>
             <feature>appSecurity-2.0</feature>
             <feature>usr:OAuthTai-8.0</feature>
             <feature>servlet-3.0</feature>
             <feature>jndi-1.0</feature>
    </featureManager>
    
  • 添加安全角色作为 Java servlet 中的类注释:

@ServletSecurity(@HttpConstraint(rolesAllowed = "TAIUserRole"))

如果使用 servlet-2.x,那么需要在 web.xml 文件中定义安全角色:

<application contextRoot="TAI" id="TrustAssociationInterceptor" location="TAI.war" name="TrustAssociationInterceptor"/>
   <application-bnd>
      <security-role name="TAIUserRole">
         <special-subject type="ALL_AUTHENTICATED_USERS"/>
      </security-role>
   </application-bnd>
</application>
  • 配置 OAuthTAI。 在此将 URL 设置为受保护的 URL:

    <usr_OAuthTAI id="myOAuthTAI" authorizationURL="http://localhost:9080/mfp/api" clientId="ExternalResourceId" clientSecret="ExternalResourcePass" cacheSize="500">
              <securityConstraint httpMethods="GET POST" scope="accessRestricted" securedURLs="/GetBalance"></securityConstraint>
    </usr_OAuthTAI>
    
    • authorizationURL:MobileFirst Server (http(s):/your-hostname:port/runtime-name/api) 或外部 AZ 服务器,例如,IBM DataPower。

    • clientID:资源服务器必须是已注册的保密客户机。 要了解如何注册保密客户机,请阅读保密客户机教程。 *保密客户机必须 具有允许的作用域 authorization.introspect,以使其可验证令牌。

    • clientSecret:资源服务器必须是已注册的保密客户机。 要了解如何注册保密客户机,请阅读保密客户机教程。
    • cacheSize(可选):TAI 使用 Java-Token-Validator 高速缓存来缓存令牌和自省数据作为值,从而在较短时间间隔内无需再次自省来自客户机请求中的令牌。

      缺省大小为 50000 个令牌。

      如果想要保证在每个请求上自省令牌,请将高速缓存值设置为 0。

    • scope:资源服务器针对一个或多个作用域进行认证。 作用域可以是安全性检查或映射到安全性检查的作用域元素。

使用来自 TAI 的令牌自省数据

通过资源,您可能想要访问 TAI 拦截和验证的令牌信息。 您可以在 API 参考大全中找到在令牌上发现的数据列表。 要获得此数据,请使用 WSSubject API

Map<String, String> credentials = WSSubject.getCallerSubject().getPublicCredentials(Hashtable.class).iterator().next();
JSONObject securityContext = new JSONObject(credentials.get("securityContext"));
...
securityContext.get('mfp-device')

样本应用程序

您可以在受支持的应用程序服务器(WebSphere Application Server Full Profile 和 WebSphere Application Server Liberty Profile)上部署项目。
下载简单 Java servlet

样本用法

  1. 确保更新保密客户机和 MobileFirst Operations Console 中的密钥值。
  2. 部署安全性检查:UserLoginPinCodeAttempts
  3. 注册匹配应用程序。
  4. accessRestricted 作用域映射到安全性检查。
  5. 更新客户机应用程序以针对 servlet URL 生成 WLResourceRequest
  6. 将 securityConstraint 作用域设置为客户机需要进行认证的安全性检查。
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on June 01, 2020