Archive for the ‘Coldfusion’ category

WSSE Security Header Authentication with ColdFusion

July 20th, 2010

I recently had a project that required interaction with a web service using wsse authentication. The example given by the vendor failed to authenticate as well as the wsse online documentation.

Unfortunately there is very little info I could find on using ColdFusion with wsse authentication and the error messages were less than helpful.

After many days of trial and error I finally got it to work, hopefully this will save someone the headache.

Creating the Header:

<CFFUNCTION NAME=”getSecurityHeader”>

<cfset myUsername = #uname# />
<cfset myPassword = #passwd# />
<cfset dtNow = Now() />
<cfset dtGMT = DateAdd(”s”,GetTimeZoneInfo().UTCTotalOffset,dtNow) />
<cfset myDate = “#DateFormat(dtGMT,”yyyy-mm-dd”)#” & “T” & “#timeformat(dtGMT,”HH:mm:ss”)#” & “Z”>

<cfscript>
myNonce = createUUID();
myObj = createObject(”webservice”,this.checkInstantConsumer.DropPath);

headerElement = createObject(”java”,”org.apache.axis.message.SOAPHeaderElement”);

headerElement.init(”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd”, “wsse:Security”);

headerElement.addChildElement(”wsse:UsernameToken”);

headerElement.getFirstChild().addChildElement(”wsse:Username”).setValue(myUsername);

mypass = headerElement.getFirstChild().addChildElement(”wsse:Password”);
mypass.setValue(myPassword);
//mypass.setAttribute(”Type”, “PasswordText”);

headerElement.getFirstChild().addChildElement(”wsse:Nonce”).setValue(
ToBase64(Hash(myNonce, “SHA”)) );

myCreated = headerElement.getFirstChild().addChildElement(”wsu:Created”);
myCreated.setValue(myDate);
myCreated.setAttribute(”xmlns:wsu”,”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd”);

headerElement.setMustUnderstand(1);
headerElement.setActor(”");

myObj.setHeader(headerElement);

securityheader = headerElement.tostring();
</cfscript>

<CFRETURN securityheader />
</CFFUNCTION>

Using the Created Header:

<!— Get wsse Security Header —>
<cfscript>
securityHeader=getSecurityHeader();
</cfscript>
<cfoutput>
<!— Crreate SOAP Request —>
<cfsavecontent variable=”request.thisrequest”><?xml version=”1.0″ encoding=”utf-8″?>
<soap:Envelope xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”>
<soap:Header>
#securityHeader#
</soap:Header>
<soap:Body>
<Method xmlns=”https://www.site.com/Method/”>
<Element1>#Element1Value#</Element1>
<Element2>#Element2Value#</Element2>
</Method>
</soap:Body>
</soap:Envelope>
</cfsavecontent>

Setting Up OpenBD on a Linux Cpanel Server

August 21st, 2009

There is an excellent writeup on openbluedragon.org that explains installing OpenBD on Centos/Redhat with Apache and Tomcat. Cpanel can be used to install Tomcat so the setup is a little different.

Install Tomcat

This can be done in WHM under EasyApache (Apache Update).  Just check the Tomcat option when saving your build.

Install OpenBD

cd /usr/local/jakarta/
wget http://openbd.viviotech.net/downloader.cfm/id/64/file/openbd.war
cp /usr/local/jakarta/openbd.war /usr/local/jakarta/tomcat

Go to http://localhost:8080/openbd/bluedragon/administrator. Login with the password admin and change the default password to whatever you want.

Enable CFM

By default Tomcat will execute any jsp page for an account that has jsp enabled. To enable cfm we have to modify the setup script slightly.  To do this open /scripts/addservlets2 in your favorite editor and modify the IfModule mod_jk.c portion of the file to look like the code below.

<IfModule mod_jk.c>
JkMount /*.cfm ajp13
JkMount /*.cfc ajp13
JkMount /*.do ajp13
JkMount /*.jsp ajp13
JkMount /*.cfchart ajp13
JkMount /*.cfres ajp13
JkMount /*.cfm/* ajp13
JkMount /*.cfml/* ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
</IfModule>

Enable Tomcat for your Domain

/scripts/addservlets2 --domain=yourdomain.com

Copy Directories

Unfortunately with this setup you have to have an admin for every domain.

cp -Rf /usr/local/jakarta/tomcat/bluedragon /home/yourdomaindirectory/public_html
cp -Rf /usr/local/jakarta/tomcat/WEB-INF /home/yourdomaindirectory/public_html