【问题标题】:Websphere Liberty Profile and J2C AuthData retrieval via Java API通过 Java API 检索 Websphere Liberty Profile 和 J2C AuthData
【发布时间】:2014-06-16 19:39:08
【问题描述】:

在完整版的 Websphere 中,您可以定义 JAAS 身份验证条目。 这些条目具有唯一的 ID、用户名和密码。通常这些绑定到 WAS 中的其他配置条目,例如 DataSource 配置。

但有时您需要通过 API 直接从应用程序代码访问 J2C 记录。 这里有几篇文章解释了如何在 WAS 中进行操作。 通常你做的是:

LoginContext loginContext = new LoginContext("DefaultPrincipalMapping", callbackHandler);
loginContext.login();

它确实通过 JCA API 在 WAS 中工作,但在 Websphere Liberty Profile 中却不行。 有什么方法可以访问 Websphere Liberty Profile 中的 J2C AuthData? 为此目的在 server.xml 中设置 J2C 所需的最低配置是什么?

我们有类似的东西:

<featureManager>
    <feature>appSecurity-2.0</feature>
</featureManager>
<authData id="someAppCredentials" user="someUser" password="some Password"/>
<jaasLoginContextEntry id="DefaultPrincipalMapping" name="DefaultPrincipalMapping" loginModuleRef="userNameAndPassword"/>

但显然这还不够,因为 WLP 抛出:javax.security.auth.login.LoginException: No LoginModules configured for DefaultPrincipalMapping 如果你尝试做 loginContext.login()。

【问题讨论】:

标签: jaas websphere-8 websphere-liberty jca


【解决方案1】:

似乎从 8.5.5.9 版本开始添加了此功能。

更多详情见:Developing a programmatic login for obtaining authentication data

您将需要server.xml 中的以下功能:

<featureManager>
   <feature>appSecurity-2.0</feature>
   <feature>passwordUtilities-1.0</feature>
   <feature>jca-1.7</feature>
</featureManager>

然后定义你的别名:

<authData id="myAuthData" user="myUser" password="myPassword"/> <!-- password can also be encoded -->

然后在代码中访问:

HashMap map = new HashMap();
map.put(com.ibm.wsspi.security.auth.callback.Constants.MAPPING_ALIAS, "myAuthData"); // Replace value with your alias.
CallbackHandler callbackHandler = new com.ibm.wsspi.security.auth.callback.WSMappingCallbackHandler(map, null);
LoginContext loginContext = new LoginContext("DefaultPrincipalMapping", callbackHandler);
loginContext.login();
Subject subject = loginContext.getSubject();
Set<javax.resource.spi.security.PasswordCredential> creds = subject.getPrivateCredentials(javax.resource.spi.security.PasswordCredential.class);
PasswordCredential passwordCredential = creds.iterator().next();

String userName = passwordCredential.getUserName();
char[] password = passwordCredential.getPassword();
// Do something with the userName and password.

【讨论】:

    【解决方案2】:

    目前,Liberty 配置文件不支持 DefaultPrincipalMapping。应用程序没有 API 可以调用和获取此信息。这可能会在未来的版本中考虑。

    【讨论】:

    • 这仍然是最新的吗?我想使用相同的功能,但找不到任何示例或提示。
    • 当然他们不...为什么我不感到惊讶..我需要的一件事。
    • @veote 现在好像可以使用了。
    猜你喜欢
    • 2013-02-03
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-06
    相关资源
    最近更新 更多