skip to main content
Administering Hybrid Data Pipeline : Authentication : Integrating external authentication with a Java plugin : Building a Java plugin for external authentication : Java authentication plugin sample
  

Try Now
Java authentication plugin sample
The following sample Java authentication plugin can be modified to create a custom plugin for integrating an in-house authentication system with Hybrid Data Pipeline. The external authentication service must be multi-thread safe. In other words, Hybrid Data Pipeline must be able to safely have multiple threads call authenticate() on the same Java plugin object at the same time. The Hybrid Data Pipeline service must also be able to create multiple instances of the plugin.
The Java authentication plugin interface must be implemented with the following methods.
*void init (HashMap<String, Object> attributes, Logger logger)
*void destroy ()
*boolean authenticate (String username, String password, String ipAddress)
The JavaAuthPluginException constructor can be used to handle errors and exceptions.
package com.ddtek.cloudservice.plugins.auth.javaplugin;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Logger;

public class JavaAuthPluginSample implements JavaAuthPluginInterface {

Properties authorizedUsers;

/**
* Initializes a Java authentication plugin with any properties specified when defining the plugin.
* @param props The defined properties for this plugin.
* @param logger A Java logger for the plugin to use.
*/
@Override
public void init (HashMap<String, Object> attributes, Logger logger) {

if (attributes == null) {

authorizedUsers = new Properties ();
authorizedUsers.setProperty ("d2ctest", "d2ctest");
return;
}
authorizedUsers = new Properties ();
Set<String> keySet = attributes.keySet ();
Iterator<String> keys = keySet.iterator ();
while (keys.hasNext ()) {

String key = keys.next ();
Object value = attributes.get (key);
if (value instanceof String) {

authorizedUsers.setProperty (key, (String) value);
}
else {

logger.warning (value.toString () + " [" + value.getClass ().getName () +
"] is not a String");
}
}
}

/**
* Terminates a Java authentication plugin -- free resources and cleanup.
*/
@Override
public void destroy () {}

/**
* Authenticates a username and password.
* If authentication cannot be determined, such as due to a failure
* in the authentication mechanism, an exception should be thrown.
* This routine must be multi-thread safe.
* @param username The name of the user.
* @param password The password to authenticate with.
* @param ipAddress The IP address of the authentication request.
* @returns Whether or not the username and password are valid.
*/
@Override
public boolean authenticate (String username, String password, String ipAddress) {

String pwd = authorizedUsers.getProperty (username);

// Assumes password is never null, but pwd may be null.
return password.equals (pwd);
}
}

/**
* Constructor for JavaAuthPluginException.
*/
public JavaAuthPluginException ();

/**
* Constructor for JavaAuthPluginException.
* @param message Detail message for JavaAuthPluginException.
*/
public JavaAuthPluginException (String message);

/**
* Constructor for JavaAuthPluginException.
* @param message Detail message for JavaAuthPluginException.
* @param cause Cause of the exception.
*/
public JavaAuthPluginException (String message, Throwable cause);

/**
* Constructor for JavaAuthPluginException.
* @param cause Cause of the exception.
*/
public JavaAuthPluginException (Throwable cause);