あなたは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-15 10:00:38
fnt
これは魅力のように働きました! – Jay
Websphere固有のクラス( 'Constants'と' WSMappingCallbackHandlerFactory')を参照せずにこれを行う方法があるのでしょうか? – FGreg
@FGregこれは可能だとは思わない。 WAS特有のものなので、いくつかの特定のクラスを使用することを想定する必要があります。 BTW、これらは公開WAS APIの一部です。あなたはそれを使用して何か問題がありますか? – fnt