0 Replies Latest reply on Jan 28, 2014 10:53 AM by gr8white

    How to access J2C alias using CF

    gr8white Level 1



      We have a ColdFusion (9.01) application deployed under WebSphere 7.  There are some application credentials stored in a J2C alias that was configured using the WAS console.  I would like to know if there is any way I can retrieve those credentials programmatically using ColdFusion.


      I found an example of how to retrieve them using Java which is currently not an option but I was wondering if the underlying objects can be accessed from CF.


      Here is the Java example:


      public static javax.resource.spi.security.PasswordCredential getJ2CData(String j2cAlias) throws Exception {

               String methodName = "getJ2CData";

               javax.resource.spi.security.PasswordCredential result = null;

               try {

                   // ----------WAS 6 change -------------

                   HashMap map = new HashMap();


                   CallbackHandler cbh = (WSMappingCallbackHandlerFactory.getInstance()).getCallbackHandler(map, null);

                   LoginContext lc = new LoginContext("DefaultPrincipalMapping", cbh);


                   javax.security.auth.Subject subject = lc.getSubject();

                   java.util.Set creds = subject.getPrivateCredentials();

                   result = (javax.resource.spi.security.PasswordCredential) creds.toArray()[0];

              } catch(Exception e) {


                   log.severe("APPLICATION ERROR: cannot load credentials for j2calias = " + j2cAlias);

                   throw new Exception("Unable to get credentials");


              return result;



      Any help will be greatly appreciated.