预定义的 Java 同步脚本与 MobiLink 一起提供,它们使您可以更方便地使用 authenticate_user 事件向外部服务器进行验证。预定义脚本可用于以下验证服务器:
使用 JavaMail 1.2 API 的 POP3 或 IMAP 服务器
使用 Java 命名和目录接口 (JNDI) 的 LDAP 服务器
如何使用这些脚本取决于 MobiLink 用户名是否直接映射到外部验证系统中的用户 ID。
您也可以使用 [验证] 选项卡,以 Sybase Central [模型] 模式设置向外部服务器的验证。请参见MobiLink 模型。
MobiLink 用户名直接映射到验证系统中的有效用户 ID 是一种简单的情况,此时可以直接使用预定义脚本来响应 authenticate_user 连接事件。验证代码将根据存储在 ml_property 表中的属性对自身进行初始化。
将预定义的 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 为脚本版本的名称,而 ServerType 为 LDAP、POP3 或 IMAP。
要使用 Sybase Central 中的 [添加连接脚本向导],请选择 [authenticate_user] 作为脚本类型,并在代码编辑器中输入以下内容:
ianywhere.ml.authentication.ServerType.authenticate |
其中 ServerType 为 LDAP、POP3 或 IMAP。
为该验证服务器添加属性。
对需要设置的每种属性使用 ml_add_property 存储过程:
call ml_add_property( 'ScriptVersion', 'MyVersion', 'property_name', 'property_value' ) |
其中,MyVersion 是脚本版本的名称,property_name 由验证服务器决定,property_value 是适用于您的应用程序的值。对想要设置的每种属性重复此调用。
如果 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 ); |
这适用于所有的验证类,尽管属性会依类的不同而不同。
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |