• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to access J2C alias using CF

Guest
Jan 28, 2014 Jan 28, 2014

Copy link to clipboard

Copied

Hi,

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();

             map.put(com.ibm.wsspi.security.auth.callback.Constants.MAPPING_ALIAS,j2cAlias);

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

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

             lc.login();

             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) {

             e.printStackTrace();

             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.


Thanks,

Ken

Views

661

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation
Resources
Documentation