In this lesson, you compile a class containing Java logic for custom authentication.
Prerequisites
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).
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.startsWith("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 16\ with your SQL Anywhere 16 directory:
javac MobiLinkAuth.java -classpath "C:\Program Files\SQL Anywhere 16\java\mlscript.jar" |
![]() |
Discuss this page in DocCommentXchange.
|
Copyright © 2014, SAP AG or an SAP affiliate company. - SAP Sybase SQL Anywhere 16.0 |