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: Register 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,2).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 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.
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: Register 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,2)=="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 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.
For more information about the authenticate_user event, including a table of authentication_status return codes, see authenticate_user connection event.
For more information about implementing custom authentication using Java or .NET, see Java and .NET user authentication.
For a detailed example of Java custom authentication, see Java synchronization example.
For a detailed example of .NET custom authentication, see .NET synchronization example.
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |