简体   繁体   English

如何从部署到Websphere 6.1的EJB访问身份验证别名

[英]How to access authentication alias from EJB deployed to Websphere 6.1

I need to provide password for keystore in my EJB but I don't want it to be visible to developers. 我需要在EJB中为密钥库提供密码,但我不希望它对开发人员可见。 My idea was to create Authentication Alias in Websphere Console and later lookup for MY_ALIAS and obtain password from alias. 我的想法是在Websphere Console中创建身份验证别名,然后查找MY_ALIAS并从别名获取密码。 I found some discussion related to subject at: http://www.coderanch.com/t/79439/Websphere/Authentication-Data 我在以下网站找到了一些与主题有关的讨论: http//www.coderanch.com/t/79439/Websphere/Authentication

Do anybody knows can alias be lookuped? 有人知道可以别名吗? What is your suggested method to achieve my goal? 您建议的方法是什么来实现我的目标?

Thank you very much! 非常感谢你!

You can use the following code to obtain credentials from J2C authentication data entry: 您可以使用以下代码从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());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM