2

In full version of Websphere you can define JAAS Authentication Entries. Those entries has unique ID, username and password. Usually those are bounded to other configuration entries in WAS, for instance DataSource configurations.

But sometimes you need to access J2C records straight from application code via API. There are couple of post here explaining how to do it in WAS. Usually what you do is:

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

It does indeed work in WAS via JCA API, but not in Websphere Liberty Profile. Is there any way to access J2C AuthData in Websphere Liberty Profile? What is minimum configuration required to setup J2C in server.xml for the purpose?

We have something like:

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

but it is clearly not enough since WLP throws: javax.security.auth.login.LoginException: No LoginModules configured for DefaultPrincipalMapping if you try to do loginContext.login().

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

現時点では、DefaultPrincipalMapping は Liberty プロファイルではサポートされていません。アプリケーションが呼び出してこの情報を取得するための API はありません。これは、将来のリリースで検討される可能性があるものです。

于 2014-07-08T13:14:38.243 に答える