In this lesson, you compile a class containing Java or .NET logic for custom authentication.
The MobiLink server must have access to the classes in mlscript.jar to execute Java synchronization logic. mlscript.jar contains a repository of MobiLink Java server API classes to utilize in your Java methods. When you compile your Java class, you reference mlscript.jar.
Create a class named MobiLinkAuth and write an authenticateUser method.
The MobiLinkAuth class includes the authenticateUser method used for the authenticate_user synchronization event. The authenticate_user event provides parameters for the user and password. You return the authentication result in the authentication_status inout parameter.
You register the authenticateUser method for the authenticate_user synchronization event in Lesson 2: Registering your Java or .NET scripts for the authenticate_user event.
Use the following code for your server application:
import ianywhere.ml.script.*; public class MobiLinkAuth { public void authenticateUser ( ianywhere.ml.script.InOutInteger authentication_status, String user, String pwd, String newPwd ) { if (user.substring(0,3).equals("128")) { // success: an auth status code of 1000 authentication_status.setValue(1000); } else { // fail: an authentication_status code of 4000 authentication_status.setValue(4000); } } } |
This code illustrates a simple case of custom user authentication. Authentication succeeds when the client accesses the consolidated database using a user name that starts with 128.
Save your code.
This tutorial assumes c:\MLauth as the working directory for server-side components. Save the file as MobiLinkAuth.java in this directory.
Compile your class file.
Navigate to the directory that contains your Java file.
Compile the MobiLinkAuth class and refer to the MobiLink server Java API library.
Run the following command, replacing C:\Program Files\SQL Anywhere 12\ with your SQL Anywhere 12 directory:
javac MobiLinkAuth.java -classpath "C:\Program Files\SQL Anywhere 12\java\mlscript.jar" |
The MobiLinkAuth.class file is generated.
Proceed to Lesson 2: Registering your Java or .NET scripts for the authenticate_user event.
The MobiLink server must have access to the classes in iAnywhere.MobiLink.Script.dll to execute .NET synchronization logic. iAnywhere.MobiLink.Script.dll contains a repository of MobiLink .NET server API classes to utilize in your .NET methods. When you compile your .NET class, you reference iAnywhere.MobiLink.Script.dll.
Create a class named MobiLinkAuth and write an authenticateUser method.
The MobiLinkAuth class includes the authenticateUser method used for the authenticate_user synchronization event. The authenticate_user event provides parameters for the user and password. You return the authentication result in the authentication_status inout parameter.
You register the authenticateUser method for the authenticate_user synchronization event in Lesson 2: Registering your Java or .NET scripts for the authenticate_user event.
Use the following code for your server application:
using iAnywhere.MobiLink.Script; public class MobiLinkAuth { public void authenticateUser( ref int authentication_status, string user, string pwd, string newPwd ) { if(user.Substring(0,3)=="128") { // success: an auth status code of 1000 authentication_status = 1000; } else { // fail: and authentication_status code of 4000 authentication_status = 4000; } } } |
This code illustrates a simple case of custom user authentication. Authentication succeeds when the client accesses the consolidated database using a user name that starts with 128.
Save your code.
This tutorial assumes c:\MLauth as the working directory for server-side components. Save the file as MobiLinkAuth.cs in this directory.
Compile your class file.
Navigate to the directory that contains your C# file.
Compile the MobiLinkAuth class and refer to the MobiLink server .NET API library.
Run the following command, replacing C:\Program Files\SQL Anywhere 12\ with your SQL Anywhere 12 directory:
csc /out:MobiLinkAuth.dll /target:library /reference:"C:\Program Files\SQL Anywhere 12\Assembly\v2\iAnywhere.MobiLink.Script.dll" MobiLinkAuth.cs |
The MobiLinkAuth.dll assembly is generated.
Proceed to Lesson 2: Registering your Java or .NET scripts for the authenticate_user event.
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |