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

SAP Sybase SQL Anywhere 16.0 » MobiLink - Getting Started » MobiLink tutorials » Tutorial: Using Java or .NET for custom user authentication


Lesson 1: Creating a Java class for custom authentication (server-side)

In this lesson, you compile a class containing Java 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.

This lesson assumes that you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Using Java or .NET for custom user authentication.

Context and remarks

To create a .NET class for customer authentication, see Lesson 1: Creating a .NET class for custom authentication (server-side).

  1. 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:

    public class MobiLinkAuth {
        public void authenticateUser (
            String user,
            String pwd,
            String newPwd ) {
            if (user.startsWith("128")) {
                // success: an auth status code of 1000
            } else {
                // fail: an authentication_status code of 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.

  2. Save your code.

    This tutorial assumes c:\MLauth as the working directory for server-side components. Save the file as in this directory.

  3. Compile your class file.

    1. Navigate to the directory that contains your Java file.

    2. Compile the MobiLinkAuth class and refer to the MobiLink server Java API library.

      Run the following command, replacing C:\Program Files\SQL Anywhere 16\ with your SQL Anywhere 16 directory:

      javac -classpath "C:\Program Files\SQL Anywhere 16\java\mlscript.jar"


The MobiLinkAuth.class file is generated.

 See also