package com.eforce.baby.auth.handler;
import java.io.IOException;
import org.apache.log4j.Logger;
import com.eforce.baby.auth.handler.UserLoginCallback;
import com.eforce.baby.auth.handler.PasswordCallback;
import com.eforce.baby.auth.handler.DatasourceNameCallback;
import com.eforce.baby.auth.handler.DatabaseTypeCallback;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
/**
* <p> This application implements <code>EEMSCallbackHandler</code> and passes
* it to underlying security services so that they may interact with
* the application to retrieve specific authentication data,
* such as usernames, passwords, datasource name and database type
* or to display certain information, such as error and warning messages.
*
* @author Arindam Mazumder
* @version 1.0, 07/08/2004
* @since EEMS architecture refresh
*/
public class EEMSCallbackHandler implements CallbackHandler
{
private Logger log = (Logger) Logger.getInstance(this.getClass().getName());
/* Stores user login name */
private String userLogin;
/* Stores user password */
private String password;
/* Stores datasource name of the underlying database */
private String datasourceName;
/* Stores database type of the underlying database */
private String databaseType;
/**
* <p> Retrieve or display the information requested in the
* provided Callbacks.
*
* <p> The <code>handle</code> method implementation checks the
* instance(s) of the <code>Callback</code> object(s) passed in
* to retrieve or display the requested information.
*
* @param callbacks an array of <code>Callback</code> objects provided
* by an underlying security service which contains
* the information requested to be retrieved or displayed.
*
* @exception java.io.IOException if an input or output error occurs. <p>
*
* @exception UnsupportedCallbackException if the implementation of this
* method does not support one or more of the Callbacks
* specified in the <code>callbacks</code> parameter.
*/
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
{
for (int i = 0; i < callbacks.length; i++)
{
if (callbacks[i] instanceof UserLoginCallback)
{
// set the username to the username given in the constructor
UserLoginCallback ulc = (UserLoginCallback) callbacks[i];
ulc.setUserLogin(userLogin);
}
else if (callbacks[i] instanceof PasswordCallback)
{
// set the password to the password given in the constructor
PasswordCallback pc = (PasswordCallback) callbacks[i];
pc.setPassword(password);
}
else if (callbacks[i] instanceof DatasourceNameCallback)
{
// set the username to the username given in the constructor
DatasourceNameCallback dnc = (DatasourceNameCallback) callbacks[i];
dnc.setDatasourceName(datasourceName);
}
else if (callbacks[i] instanceof DatabaseTypeCallback)
{
// set the username to the username given in the constructor
DatabaseTypeCallback dnc = (DatabaseTypeCallback) callbacks[i];
dnc.setDatabaseType(databaseType);
}
else
{
throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
}
}
}
/**
* Returns the database type of the underlying database
*
* @return a String representing the database type
*/
public String getDatabaseType()
{
return databaseType;
}
/**
* Returns the datasource name of the underlying database
*
* @return a String representing the datasource name
*/
public String getDatasourceName()
{
return datasourceName;
}
/**
* Sets the database type of the underlying databse
*
* @param string the database type
*/
public void setDatabaseType(String string)
{
databaseType = string;
}
/**
* Sets the datasource name of the underlying databse
*
* @param string the datasource name
*/
public void setDatasourceName(String string)
{
datasourceName = string;
}
/**
* Returns the user's login name
*
* @return a string representing the user's login name
*/
public String getUserLogin()
{
return userLogin;
}
/**
* Sets the user's login name
*
* @param string the user's login name
*/
public void setUserLogin(String string)
{
userLogin = string;
}
/**
* Returns the user's password
*
* @return a string representing the user's password
*/
public String getPassword()
{
return password;
}
/**
* Sets the user's password
*
* @param string the user's password
*/
public void setPassword(String string)
{
password = string;
}
}