Knowledge Base

Document information

Document ID: 3731
Subject: Extending user authentication mechanism in Syncrify
Creation date: 8/18/14 11:11 AM
Last modified on: 12/12/18 11:42 AM




Extending Syncrify Server's User Authentication Mechanism



There are two built-in ways a Syncrify Server stores and manages user information:
  1. An XML files
  2. A relational database
In addition to these two built-in mechanisms, you can extend Syncrify Server's ability to use a third-party code to manage users. This page demonstrates steps necessary to provide such extension to Syncrify Server. This third party code will be responsible for:

  • Authenticating users
  • Managing properties like repository path, disk quota, number of versions to keep, etc.


Side effect

Before implementing this custom code, it is important to keep the following side effect in mind:
You will have to test and/or update your code whenever we release a new build. This means you will have to maintain a development environment for Syncrify Server on your end from now on.

Setting up development environment

The custom code must be written in Java and the following steps assumes you are using Eclipse for the IDE.

Step 1 Installation

Install Syncrify Server on the same machine where Eclipse is also running.

Step 2 Required Jar Files

Create a new project and include SyncrifyServer.jar in your project. This file is found in $INSTALL_DIR\lib\ folder of Syncrify.

Step 3 Implementing Interface

You need to create a new class that implements com.synametrics.syncrify.users.UserManager interface. This interface is part of SyncrifyServer.jar and therefore, you should not get any compilation errors. In additional to UserManager, this interface refers to a couple of other classes. These classes are also part of SyncrifyServer.jar.

For reference, the code for com.synametrics.syncrify.users.UserManager interface is displayed below.

Obviously, you will have to write every method since you are implementing an interface. However, depending upon how the data is stored, you can leave the method's body empty. For example, there is no need to write a body for reload and save methods if you are reading/writing from a relational database. This is because the SELECT and INSERT statements in your code will already take care of reading and saving the data.

Similarly, writing a body for addUserProfile method is optional. This method is used to let your code know a new profile was discovered. Your code is not required to take any action when this event occurs.

Step 4 Deploying

Once you are done implementing the interface, bundle all of your files into a JAR file. Place this newly created JAR file in $INSTALL_DIR\libs folder.

Then, locate $INSTALL_DIR\config\AppConfig.xml file and add the following parameter.

<parameter name="CustomUserManagerClass" type="1" value="com.yourcompany.YourClass"></parameter>

Finally, reinstall the service. This is done by running the following program from Command Prompt (DOS Window):

cd \Syncrify
InstallService -uninstallService
InstallService -installService
NOTE: You only need to uninstall/install the service once. This step is not required when you update the JAR file on subsequent builds.

Reference Code

package com.synametrics.syncrify.users;

import java.util.List;
import java.util.Set;

import com.synametrics.syncrify.bean.UserBean;

public interface UserManager {
	
	
	/**
	 * This method is called when a new user needs to be added. The implementing class should update its memory contents
	 * with this new user.
	 * @param oneUserHolder A new user holder that is being added.
	 */
	void addUser(DefaultUserHolder oneUserHolder);
		
	/**
	 * This method should add a new profile if it does not exist or modify an existing one if it is found.
	 * A profile is uniquely identified by user's login id and profile name. The purpose of this method is to let the 
	 * implementing class know a new profile is being added or modified. It can 
	 * chose not to take any action when this method is called.
	 * 
	 * @param userLogin User name, which is typically an email address
	 * @param aProfile Profile that is being added. 
	 */
	void addUserProfile(String userLogin, String aProfile);
	
	
	
	/**
	 * Returns the User Holder object for the given email. 
	 * @param login Email address, which serves as a login ID
	 * @param password If this is null, Holder is returned by matching login alone. If this is provided, a match is found
	 * based on user id and password
	 * 
	 * @return Method should return null if a matching user is NOT found.
	 */
	DefaultUserHolder fetchUserHolder(String login, String password);
	
	/**
	 * Returns a list of file paths that are used for user repository. This information is used to check the hard-disk space 
	 * for the user repositories.
	 * @return Returns a set of repository paths
	 */
	Set<String> getAllRepositories();
	
	/**
	 * Returns a list of all users.
	 * @return Returns a list of users in the system.
	 */
	List<UserBean> getAllUsers();
	
	/**
	 * Returns the total number of users in the system.
	 * @return Total number of users
	 */
	int getTotalUserCount();
	
	/**
	 * Checks if the user is valid.
	 * @param userId User ID
	 * @param password Password
	 * @param ipAddress IP address of the client. If this is null, only user id and password will be checked.
	 * @return true if the user is valid.
	 */
	boolean isUserValid(String userId, String password, String ipAddress);
	
	/**
	 * This method is called when the given user is modified
	 * @param oneUserHolder
	 */
	void modifyUser(DefaultUserHolder oneUserHolder);
	
	/**
	 * Reloads the user list from the persistent storage
	 */
	void reload();
	
	/**
	 * Gets called when a user should be removed from the system.
	 * @param email
	 */
	void removeUser(String email);
	
	/**
	 * This method is invoked when contents for memory should be saved to disk. The implementing class may decide to ignore
	 * calls to this method. This happens when user repository resides in an RDBMS
	 * @return true if data as saved. If the implementation class does not have to save anything, it should return true. A false
	 * should be returned in case of an error.
	 */
	boolean save();

	/**
	 * This method is called when disk usage should be updated for the given user
	 * @param email
	 * @param diskUsage
	 */
	void setDiskUsage(String email, long diskUsage);
}





Add a comment to this document

Do you have a helpful tip related to this document that you'd like to share with other users?

Important: This area is reserved for useful tips. Therefore, do not post any questions here. Instead, use our public forums to post questions.

Navigation

Social Media

Powered by 10MinutesWeb.com