Sample Web Express Logon plug-in
This sample plug-in illustrates the directions in Creating plug-ins for Web Express Logon for creating a Network Security or Credential Mapper plug-in. It uses the CMResponse object to return parameters and status. You can use this sample as a guide for creating your own plug-ins. This sample does not retrieve information; it simply returns values that are coded as constants. Your plug-in must add logic to retrieve the needed information.
////////////////////////////////////////////////////////////////////////////////
//ZIETrans sample plug-in for either Network Security or
//Credential Mapper purposes
//
//This sample is provided AS IS.
//Permission to use, copy and modify this software for any purpose and
//without fee is hereby granted. provided that the name of IBM not be used in
//advertising or publicity pertaining to distribution of the software without
//specific written permission.
//
//IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SAMPLE, INCLUDING ALL
//IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL IBM
//BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
//DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
//IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
//OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SAMPLE.
////////////////////////////////////////////////////////////////////////////////
import java.util.Properties;
import com.ibm.eNetwork.security.sso.CMRequest;
import com.ibm.eNetwork.security.sso.CMResponse;
import com.ibm.eNetwork.security.sso.PasswordCipher;
import com.ibm.eNetwork.security.sso.Ras;
import com.ibm.eNetwork.security.sso.SSOConstants;
import com.ibm.eNetwork.security.sso.cms.CMInterface;
public class CMPIHardCode implements CMInterface
{
private static final String className = "com.ibm.hats.common.wel.CMPIHardCode";
private static final String KEY_USERID = "CMPI_HARD_CODE_USERID";
private static final String KEY_PASSWORD = "CMPI_HARD_CODE_PASSWORD";
private static final String KEY_STATUS = "CMPI_HARD_CODE_STATUS";
private static final String KEY_TRACE_LEVEL = "CMPI_HARD_CODE_TRACE_LEVEL";
private static final int DEFAULT_TRACE_LEVEL = Ras.TRACE_NONE;
// Configured parameters to this plug-in
private String userID;
private String password;
private int status;
private int traceLevel;
private boolean initOK = true;
private String cmID = null;
private Properties pInit = null;
public int Init(Properties p, String id)
{
this.pInit = p;
this.cmID = id;
this.initOK = true;
userID = getProperty(KEY_USERID);
password = getProperty(KEY_PASSWORD);
status = Integer.parseInt(getProperty(KEY_STATUS));
String traceStr = getProperty(KEY_TRACE_LEVEL);
if ( traceStr != null )
traceLevel = Integer.parseInt(traceStr);
else
traceLevel = DEFAULT_TRACE_LEVEL;
return( this.initOK ? SSOConstants.SSO_SUCCESS
: SSOConstants.SSO_INVALID_PARAMETER );
}
/**
* This sample plug-in has no actions to take at destroy time
*/
public void Destroy()
{
}
/**
* Retrieve the requested credentials here, and return them to Credential Mapper
*/
public CMResponse CMSGetUserCredentials(CMRequest req)
{
// Perform whatever business logic is needed here to assign credentials.
// This testing sample just returns the plug-in's configured values.
CMResponse resp = new CMResponse(userID, password, status);
return( resp );
}
/**
* Return plug-in information to the Toolkit Web Express Logon Editor
*/
public String getName()
{
return( "Fixed credentials (for testing)" );
}
public String getDescription()
{
return( "Hard-codes returned credentials based on parameters (for testing)" );
}
public String getAuthor()
{
return( "Plugin author, for example IBM Corporation" );
}
/**
* Return the list of parameters this plug-in uses/allows to
* the Toolkit Web Express Logon Editor
*/
String strParms[] = { KEY_USERID, KEY_PASSWORD, KEY_STATUS};
public String[] getParameters()
{
return( strParms );
}
/**
* Return information about the requested parameter to the
* Toolkit Web Express Logon Editor
*/
public Properties getParameterInfo(String strParm)
{
Properties p = new Properties();
if ( KEY_USERID.equals(strParm) )
{
p.put(CMInterface.cmiRequired, "true");
}
else if ( KEY_PASSWORD.equals(strParm) )
{
p.put(CMInterface.cmiRequired, "true");
p.put(CMInterface.cmiEncrypted, "true");
}
else if ( KEY_STATUS.equals(strParm) )
{
p.put(CMInterface.cmiRequired, "true");
p.put(CMInterface.cmiDefaultValue,
Integer.toString(SSOConstants.SSO_SUCCESS));
}
else if ( KEY_TRACE_LEVEL.equals(strParm) )
{
p.put(CMInterface.cmiRequired, "false");
p.put(CMInterface.cmiDefaultValue,
Integer.toString(DEFAULT_TRACE_LEVEL));
}
return( p );
}
/**
* Retrieve the parameter value
*/
private String getProperty(String propName)
{
final String methodName = "getProperty";
if ( traceLevel >= Ras.TRACE_MAXIMUM )
Ras.traceEntry(className, methodName, propName);
boolean requiredParm =
"true".equals(getParameterInfo(propName).
getProperty(CMInterface.cmiRequired));
boolean encryptedParm =
"true".equals(getParameterInfo(propName).
getProperty(CMInterface.cmiEncrypted));
String value = pInit.getProperty(cmID + propName); // must use cmID prefix !!
if ( value == null || value.trim().equals("") )
{
value = pInit.getProperty(propName);
}
if ( (value == null || value.trim().equals("")) && requiredParm )
{
if ( traceLevel >= Ras.TRACE_MINIMUM )
Ras.logMessage(Ras.MSG_ERROR, className, methodName,
"PARAMETER_ERROR", propName);
initOK = false;
}
else if ( encryptedParm )
value = PasswordCipher.decrypt(value);
if ( traceLevel >= Ras.TRACE_MAXIMUM )
Ras.traceExit(className, methodName, (encryptedParm ? "********"
: value));
return( value );
}
}