将公共对象请求代理体系结构程序化登录迁移到 Java 认证和授权服务(CORBA 和 JAAS)

使用本主题作为如何使用基于 CORBA 的程序化登录 API 执行程序化登录的示例。

开始之前

[AIX Solaris HP-UX Linux Windows][IBM i]本文档概述不推荐的公共对象请求代理体系结构 (CORBA) 程序化登录 API 以及 JAAS 提供的备用方法。WebSphere® Application Server 完全支持 Java™ 认证和授权服务 (JAAS) 作为程序化登录应用程序编程接口 (API)。请参阅为 Java 认证和授权服务配置程序化登录开发带 Java 认证和授权服务的程序化登录,以了解有关 JAAS 支持的更多详细信息。

[z/OS]WebSphere Application Server for z/OS® 环境中不支持公共对象请求代理体系结构 (CORBA) 应用程序编程接口 (API)。如果要将某个应用程序从另一个 WebSphere Application Server 产品移植到 WebSphere Application Server for z/OS,那么必须了解 V6.0.x 中不推荐的安全性 API。如果您要在 WebSphere Application Server for z/OS V8.0 中使用这些应用程序,那么您必须迁移到 Java 认证和授权服务 (JAAS)。

以下列表包含不推荐的 CORBA 程序化登录 API。
  • [AIX Solaris HP-UX Linux Windows][z/OS]${user.install.root}/installedApps/sampleApp.ear/default_app.war/WEB-INF/classes/LoginHelper.java.
  • [AIX Solaris HP-UX Linux Windows][z/OS]${user.install.root}/installedApps/sampleApp.ear/default_app.war/WEB-INF/classes/ServerSideAuthenticator.java.
  • [IBM i]profile_root/installedApps/sampleApp.ear/default_app.war/WEB-INF/classes/ServerSideAuthenticator.java
  • [AIX Solaris HP-UX Linux Windows][IBM i]org.omg.SecurityLevel2.Credentials。此 API 包含在产品中,但是不推荐使用。

WebSphere Application Server 中提供的 API 是标准 JAAS API 和标准 JAAS 接口的产品实现的组合。

[z/OS]WebSphere Application Server for z/OS 中提供的受支持 API 是标准 JAAS API 和标准 JAAS 接口的产品实现(有一些小扩展)的组合。

以下信息只是摘要;请参阅用于您的平台的 JAAS 文档,该文档位于:http://www.ibm.com/developerworks/java/jdk/security/

  • 程序化登录 API:
    • javax.security.auth.login.LoginContext
    • javax.security.auth.callback.CallbackHandler 接口:WebSphere Application Server 产品提供 javax.security.auth.callback.CallbackHandler 接口的以下实现:
      com.ibm.websphere.security.auth.callback.WSCallbackHandlerImpl
      当应用程序将基本认证数据(用户标识、密码和安全领域)或令牌数据推送到产品登录模块时,提供非提示 CallbackHandler 处理程序。建议为服务器端登录使用此 API。
      [AIX Solaris HP-UX Linux Windows][IBM i]com.ibm.websphere.security.auth.callback.WSGUICallbackHandlerImpl
      [AIX Solaris HP-UX Linux Windows][IBM i]提供登录提示 CallbackHandler 处理程序以收集基本认证数据(用户标识、密码和安全领域)。建议为客户端登录使用此 API。

      如果在服务器端使用此 API,将阻止服务器输入。

      com.ibm.websphere.security.auth.callback.WSStdinCallbackHandlerImpl
      提供标准输入登录提示 CallbackHandler 处理程序以收集基本认证数据(用户标识、密码和安全领域)。建议为客户端登录使用此 API。
      注: 如果在服务器端使用此 API,将阻止服务器输入。
    • javax.security.auth.callback.Callback 接口:
      javax.security.auth.callback.NameCallback
      由 JAAS 提供,以将用户名传递到 LoginModules 接口。
      javax.security.auth.callback.PasswordCallback
      由 JAAS 提供,以将密码传递到 LoginModules 接口。
      com.ibm.websphere.security.auth.callback.WSCredTokenCallbackImpl
      由产品提供,以执行基于令牌的登录。使用此 API,应用程序可以传递标记字节数组到 LoginModules 接口。
    • javax.security.auth.spi.LoginModule interface

      WebSphere Application Server 为客户机和服务器端登录提供 LoginModules 实现。请参阅为 Java 认证和授权服务配置程序化登录,以获取详细信息。

  • javax.security.Subject:
    [AIX Solaris HP-UX Linux Windows][IBM i]com.ibm.websphere.security.auth.WSSubject
    [AIX Solaris HP-UX Linux Windows][IBM i]由产品提供的扩展,以使用 javax.security.Subject 中的凭证调用远程 J2EE 资源
    [z/OS]com.ibm.websphere.security.auth.WSSubject
    [z/OS]由产品提供的扩展,以使用 javax.security.Subject 中的凭证调用远程 J2EE 资源

    应用程序必须使用显式调用 WebSphere Application Server 登录模块生成的主体集,调用 WSSubject.doAs() 方法来访问 J2EE 资源。

    com.ibm.websphere.security.cred.WSCredential
    使用 WebSphere Application Server LoginModules 接口 JAAS 登录成功后,创建 com.ibm.websphere.security.cred.WSCredential 凭证并将它存储到主体集。
    com.ibm.websphere.security.auth.WSPrincipal
    一个由 WebSphere Application Server LoginModules 接口认证的已认证主体,在主体集中创建并存储。

过程

  1. [AIX Solaris HP-UX Linux Windows][IBM i]使用下列作为如何使用基于 CORBA 的程序化登录 API 执行程序化登录的示例: 基于 CORBA 的程序化登录 API 由 JAAS 登录替换。
    注: 在 WebSphere Application ServerV9.0 中,不推荐使用以下示例中使用的 LoginHelper 应用程序编程接口 (API),在将来的发行版中会将其移除。建议使用下一个步骤中显示的 JAAS 程序化登录 API。
    public class TestClient {
    ...
    private void performLogin() {
    // Get the ID and password of the user.
    String userid = customGetUserid();
    String password = customGetPassword();
    
    // Create a new security context to hold authentication data.
    LoginHelper loginHelper = new LoginHelper();
    try {
    // Provide the ID and password of the user for authentication.
    org.omg.SecurityLevel2.Credentials credentials = 
    loginHelper.login(userid, password);
    
    // Use the new credentials for all future invocations.
    loginHelper.setInvocationCredentials(credentials);
    // Retrieve the name of the user from the credentials
    // so we can tell the user that login succeeded.
    
    String username = loginHelper.getUserName(credentials);
    System.out.println("Security context set for user: "+username);
    } catch (org.omg.SecurityLevel2.LoginFailed e) {
    // Handle the LoginFailed exception.
    }
    }
    ...
    }
  2. 使用以下示例将基于 CORBA 的程序化登录 API 迁移到 JAAS 程序化登录 API。

    以下示例假设授予应用程序代码必需的 Java 2 安全许可权。有关更多信息,请参阅为 Java 认证和授权服务配置程序化登录保护系统资源和 API(Java 2 安全性)以开发应用程序和 JAAS 文档,它们位于 http://www.ibm.com/developerworks/java/jdk/security/

    public class TestClient {
    ...
    private void performLogin() {
    // Create a new JAAS LoginContext.
    javax.security.auth.login.LoginContext lc = null;
    
    try {
    // Use GUI prompt to gather the BasicAuth data.
    lc = new javax.security.auth.login.LoginContext("WSLogin",
    new com.ibm.websphere.security.auth.callback.WSGUICallbackHandlerImpl());
    
    // create a LoginContext and specify a CallbackHandler implementation
    // CallbackHandler implementation determine how authentication data is collected
    // in this case, the authentication date is collected by  login prompt
    //   and pass to the authentication mechanism implemented by the LoginModule.
    } catch (javax.security.auth.login.LoginException e) {
    System.err.println("ERROR: failed to instantiate a LoginContext and the exception: " 
    + e.getMessage());
    e.printStackTrace();
    
    // may be javax.security.auth.AuthPermission "createLoginContext" is not granted
    //   to the application, or the JAAS Login Configuration is not defined.
    }
    
    if (lc != null)
    try {
    lc.login();  // perform login
    javax.security.auth.Subject s = lc.getSubject();
    // get the authenticated subject
    
    // Invoke a J2EE resources using the authenticated subject
    com.ibm.websphere.security.auth.WSSubject.doAs(s,
    new java.security.PrivilegedAction() {
    public Object run() {
    try {
    bankAccount.deposit(100.00);  // where bankAccount is an protected EJB
    } catch (Exception e) {
    System.out.println("ERROR: error while accessing EJB resource, exception: " 
    + e.getMessage());
    e.printStackTrace();
    }
    return null;
    }
    }
    );
    
    // Retrieve the name of the principal from the Subject
    // so we can tell the user that login succeeded,
    // should only be one WSPrincipal.
    java.util.Set ps = 
    s.getPrincipals(com.ibm.websphere.security.auth.WSPrincipal.class);
    java.util.Iterator it = ps.iterator();
    while (it.hasNext()) {
    com.ibm.websphere.security.auth.WSPrincipal p =
    (com.ibm.websphere.security.auth.WSPrincipal) it.next();
    System.out.println("Principal: " + p.getName());
    }
    } catch (javax.security.auth.login.LoginException e) {
    System.err.println("ERROR: login failed with exception: " + e.getMessage());
    e.printStackTrace();
    
    // login failed, might want to provide relogin logic
    }
    }
    ...
    }

指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tsec_migratecorba
文件名:tsec_migratecorba.html