Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » MobiLink - 客户端管理 » MobiLink 客户端简介 » MobiLink 用户 » 自定义用户验证

 

向外部服务器验证

预定义的 Java 同步脚本与 MobiLink 一起提供,它们使您可以更方便地使用 authenticate_user 事件向外部服务器进行验证。预定义脚本可用于以下验证服务器:

  • 使用 JavaMail 1.2 API 的 POP3 或 IMAP 服务器

  • 使用 Java 命名和目录接口 (JNDI) 的 LDAP 服务器

如何使用这些脚本取决于 MobiLink 用户名是否直接映射到外部验证系统中的用户 ID。

注意

您也可以使用 [验证] 选项卡,以 Sybase Central [模型] 模式设置向外部服务器的验证。请参见MobiLink 模型

如果 MobiLink 用户名直接映射到用户 ID

MobiLink 用户名直接映射到验证系统中的有效用户 ID 是一种简单的情况,此时可以直接使用预定义脚本来响应 authenticate_user 连接事件。验证代码将根据存储在 ml_property 表中的属性对自身进行初始化。

♦  在 authenticate_user 中直接使用预定义脚本
  1. 将预定义的 Java 同步脚本添加到 ml_scripts MobiLink 系统表中。可以使用存储过程或在 Sybase Central 中完成此操作。

    • 要使用 ml_add_java_connection_script 存储过程,请运行以下命令:

      call ml_add_java_connection_script(
        'MyVersion',
        'authenticate_user',
        'ianywhere.ml.authentication.ServerType.authenticate' )

      其中 MyVersion 为脚本版本的名称,而 ServerTypeLDAPPOP3IMAP

    • 要使用 Sybase Central 中的 [添加连接脚本向导],请选择 [authenticate_user] 作为脚本类型,并在代码编辑器中输入以下内容:

      ianywhere.ml.authentication.ServerType.authenticate

      其中 ServerTypeLDAPPOP3IMAP

      请参见ml_add_java_connection_script 系统过程

  2. 为该验证服务器添加属性。

    对需要设置的每种属性使用 ml_add_property 存储过程:

    call ml_add_property(
      'ScriptVersion',
      'MyVersion',
      'property_name',
      'property_value' )

    其中,MyVersion 是脚本版本的名称,property_name 由验证服务器决定,property_value 是适用于您的应用程序的值。对想要设置的每种属性重复此调用。

    请参见外部验证程序属性ml_add_property 系统过程

如果 MobiLink 用户名不直接映射到用户 ID

如果 MobiLink 用户名与您的用户 ID 不同,则必须间接调用代码,并且必须从 ml_user 值中抽取或映射用户 ID。可通过编写 Java 类来完成此操作。

请参见使用 Java 语言编写同步脚本

下面是一个简单的示例。本示例省去了 extractUserID 方法中的代码,因为该代码取决于 ml_user 值映射到 userid 的方式。所有操作都是用验证类的 "authenticate" 方法完成的。

package com.mycompany.mycode;

import ianywhere.ml.authentication.*;
import ianywhere.ml.script.*;

public class MLEvents
{
    private DBConnectionContext _context;
    private POP3 _pop3;

    public MLEvents( DBConnectionContext context )
    {
        _context = context;
        _pop3 = new POP3( context );
    }

    public void authenticateUser(
      InOutInteger status,
      String userID,
      String password,
      String newPassword )
    {
        String realUserID = extractUserID( userID );
        _pop3.authenticate( status, realUserID, password, newPassword );
    }

    private String extractUserID( String userID )
    {
        // code here to map ml_user to a "real" POP3 user
    }
}

在本示例中,需要用 DBConnectContext 对象初始化 POP3 对象,以便 POP3 对象可以找到其初始化属性。如果不用这种方法进行初始化,则必须通过代码设置属性。例如,

POP3 pop3 = new POP3();
pop3.setServerName( "smtp.sybase.com" );
pop3.setServerPort( 25 );

这适用于所有的验证类,尽管属性会依类的不同而不同。


外部验证程序属性