How to access an authentication alias from an EJB deployed in Websphere 6.1

I need to provide a password for the keystore in my EJB, but I do not want it to be visible to developers. My idea was to create an authentication alias in the Websphere console, and then search for MY_ALIAS and get the password from the alias. I found a discussion on the topic: http://www.coderanch.com/t/79439/Websphere/Authentication-Data

Does anyone know if an alias can be found? What is your proposed method to achieve my goal?

Many thanks!

+6
java security websphere jaas
source share
1 answer

You can use the following code to get the credentials from the J2C authentication input:

import com.ibm.wsspi.security.auth.callback.Constants; import com.ibm.wsspi.security.auth.callback.WSMappingCallbackHandlerFactory; import javax.resource.spi.security.PasswordCredential; import javax.security.auth.Subject; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.login.LoginContext; Map map = new HashMap(); map.put(Constants.MAPPING_ALIAS, "YOUR_J2C_DATA_ALIAS"); CallbackHandler callbackHandler = WSMappingCallbackHandlerFactory.getInstance().getCallbackHandler(map, null); LoginContext loginContext = new LoginContext("DefaultPrincipalMapping", callbackHandler); loginContext.login(); Subject subject = loginContext.getSubject(); Set credentials = subject.getPrivateCredentials(); PasswordCredential passwordCredential = (PasswordCredential) credentials.iterator().next(); String user = passwordCredential.getUserName(); String password = new String(passwordCredential.getPassword()); 
+6
source share

All Articles