Documente Academic
Documente Profesional
Documente Cultură
Extendingthegenerictableloadertoencryptuserpasswords
<Previous|Next>
Extendingthegenerictableloadertoencryptuserpasswords
Inthislesson,youcreateanewJavaclasstoimplementtheColumnHandlerinterfaceto
encryptuserpassworddata.
Createacustomcolumnhandlertoresolvedatafromdatabasecolumnsthatarebasedoninput
valuesthatcannotbemappedtothecolumnvaluethroughtheconfiguration.Forexample,ifyour
inputtopopulatethepasswordcolumninthedatabaseisacleartextpassword,butthecolumnin
thedatabasetableexpectsanencryptedvalue,createacustomcolumnhandlertoencryptthe
cleartextpasswordandreturnanencryptedpasswordfromtheresolveColumnValue()method.
Procedure
1. OpenWebSphereCommerceDeveloper.
2. SwitchtotheJavaEEperspective.
3. IntheEnterpriseExplorerview,navigateto
WebSphereCommerceServerExtensionsLogic>src.
4. RightclicksrcthenclickNew>Package.
5. IntheNamefield,typecom.mycompany.commerce.dataload.password.ClickFinishtocreatea
newpackage.
6. Rightclickcom.mycompany.commerce.dataload.passwordthenclickNew>Class.
7. IntheNamefield,typePasswordEncryptionHandler.
8. FromtheSuperclassfield,clickBrowsetobrowsefortheAbstractColumnHandlerabstract
classthenclickOK.
9. ClickFinishtocreatetheclass.Anewfileopensforediting.
10. Pastethefollowingcodesnippetintothenewfile:
packagecom.mycompany.commerce.dataload.password;
importjava.util.Map;
importcom.ibm.commerce.foundation.common.util.logging.LoggingHelper;
importcom.ibm.commerce.foundation.dataload.config.AbstractColumnHandler;
importcom.ibm.commerce.foundation.dataload.exception.DataLoadException;
importcom.ibm.commerce.foundation.dataload.object.ExtendedTableDataObject;
importcom.ibm.commerce.member.dataload.helper.MemberDataLoadHelper;
importcom.ibm.commerce.util.WCPasswordEncrypter;
/**
*ThemainpurposeofthePasswordEncryptionHandleristoresolvethecolumnvaluebased
*ontheinputvalueswhichcannotbesimplymappedtothecolumnvalue
*throughtheconfiguration.Forexample,topopulatethepasswordcolumninthe
*database,yourinputisacleartextpassword,butthecolumninthedatabaseexpects
*anencryptedvalue,youneedtowriteacustomhandlertoencrypttheclear
*passwordandreturnanencryptedpasswordfromthemethodresolveColumnValue().
*/
publicclassPasswordEncryptionHandlerextendsAbstractColumnHandler{
privatefinalstaticStringCLASSNAME=PasswordEncryptionHandler.class.getName();
privatestaticfinaljava.util.logging.LoggerLOGGER=LoggingHelper.getLogger(Passw
privatestaticfinalStringCUSTOM_KEY_CONFIG_LOCATION="customKeyConfigLocation";
privatestaticfinalStringINSTANCE_CONFIG_LOCATION="instanceConfigLocation";
http://www01.ibm.com/support/knowledgecenter/api/content/nl/enus/SSZLC2_7.0.0/com.ibm.commerce.data.doc/tutorial/tmlcustomizedataloadencrypt3.htm
1/3
7/22/2015
Extendingthegenerictableloadertoencryptuserpasswords
/**
*Resolvethecolumnvaluebasedontheinputparameterspassedin.
*TheparametermapwillcontainthemapfromLOGONIDtothevalueoflogonId.
*TheextenededTableDataObjectrepresentstherowofthetable.
*@paramparameterMapaparametermapwhicharenamevaluepairs
*definedintheconfiguration.
*@paramextenededTableDataObjectthecurrenttabledataobjectwhichcontains
*thetableconfigurationandsomecolumnvalueswhichhavebeen
*resolvedsofar.
*@returnresolvednewcolumnvaluefortheencryptedpassword
*@throwsDataLoadExceptioniftherearesomeerrorstoresolvethevalue.
*/
publicStringresolveColumnValue(Map<String,String>parameterMap,
ExtendedTableDataObjectextendedTableDataObject)throwsDataLoadExce
//TODOAutogeneratedmethodstub
finalStringMETHODNAME="resolveColumnValue";
/*Enablethelogtraceforthemethod*/
if(LoggingHelper.isEntryExitTraceEnabled(LOGGER)){
LOGGER.entering(CLASSNAME,METHODNAME);
/*CallAPItogetthesaltvalue*/
Stringsalt=MemberDataLoadHelper.generateSalt();1
/*StorethesaltvaluebackintotheUSREEGtable*/
extendedTableDataObject.addColumnData2("SALT",salt);
Stringpassword=parameterMap.get("logonPassword");
StringInstanceconfigLocation=parameterMap.get(INSTANCE_CONFIG_LOCATION);
StringcustomKeyConfigLocation=parameterMap.get(CUSTOM_KEY_CONFIG_LOCATION
StringencryptedPWD=null;
try{
WCPasswordEncrypterencrypter=newWCPasswordEncrypter();
/*Providethefilelocationwhichthemerchantkeyisstoredinso
encrypter.initializeKeyRegistry3(customKeyConfigLocation,Instan
/*Encrypttheplaintextpassword*/
encryptedPWD=encrypter.encryptPassword4(password,salt);
}catch(Exceptione){
//TODOAutogeneratedcatchblock
e.printStackTrace();
if(LoggingHelper.isEntryExitTraceEnabled(LOGGER)){
LOGGER.exiting(CLASSNAME,METHODNAME);
/*returntheencryptedpassword*/
returnencryptedPWD;
}
}
1 generateSalt()
Generatesarandomsaltstringwithalengthof12characters.
2 extendedTableDataObject.addColumnData
ExtendsTableDataObjecttoincludemoreIDresolverinformationforcertain
databasetablecolumns.Thisclassrepresentsarowinaphysicaldatabasetable
http://www01.ibm.com/support/knowledgecenter/api/content/nl/enus/SSZLC2_7.0.0/com.ibm.commerce.data.doc/tutorial/tmlcustomizedataloadencrypt3.htm
2/3
7/22/2015
Extendingthegenerictableloadertoencryptuserpasswords
suchasUSERREG.addColumnDatatakesthecolumnnameandvalueasinputfor
SaltandaddsthevaluebacktotheSALTcolumnintheUSERREGdatabasetable.
3 initializeKeyRegistry
Initializesthekeyregistrybyprovidingoneofthefollowingparameters:
customKeyConfigFilename
Specifiesthefullpathtothecustomkeyconfigurationfilewhenthe
merchantkeyisstoredinanexternalmedium.
instanceXMLFilename
SpecifiesthefullpathtotheinstanceconfigurationXMLfilewhenthe
merchantkeyisstoredwithintheinstanceconfigurationfile.
Ifbothparametersarespecified,aninitialattemptismadetoinitializethekey
registrywiththecustomkeyconfigurationfile.Ifthatfails,anattemptismadeto
initializethekeyregistrywiththeinstanceconfigurationfile.
4 encryptPassword
ReturnstheWebSphereCommerceencryptedpasswordwiththegivencleartext
passwordandsalt.Thecallerofthismethodmustfirstinitializethekeyregistry
bycallingtheinitializeKeyRegistry(StringinstanceXMLFilename,String
customKeyConfigFilename)method.
Relatedtasks:
Creatingcustomcolumnhandlers
<Previous|Next>
http://www01.ibm.com/support/knowledgecenter/api/content/nl/enus/SSZLC2_7.0.0/com.ibm.commerce.data.doc/tutorial/tmlcustomizedataloadencrypt3.htm
3/3