2

在完整版的 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:如果您尝试执行 loginContext.login(),则没有为 DefaultPrincipalMapping 配置 LoginModules。

4

2 回答 2

1

看起来这个功能是从 8.5.5.9 版本开始添加的。

有关更多详细信息,请参阅:开发用于获取身份验证数据的编程登录

您将需要以下功能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.
于 2016-10-28T08:58:19.590 回答
0

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

于 2014-07-08T13:14:38.243 回答