6

我需要为我的 EJB 中的密钥库提供密码,但我不希望它对开发人员可见。我的想法是在 Websphere Console 中创建身份验证别名,然后查找 MY_ALIAS 并从别名获取密码。我在以下位置找到了一些与主题相关的讨论:http: //www.coderanch.com/t/79439/Websphere/Authentication-Data

有人知道可以查找别名吗?你建议的实现我的目标的方法是什么?

非常感谢!

4

1 回答 1

7

您可以使用以下代码从 J2C 身份验证数据条目中获取凭据:

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());
于 2011-06-15T10:00:38.660 回答