生のJavaランタイムで実行されているスタンドアロンEJBクライアントからJavaEEサーバーへのカスタムプリンシパルを使用したJAASサブジェクトの伝播をテストしています。JBossとWebSphereの両方の実装を対象としています。
このフォーラムスレッドによると、JBossで簡単に動作すると予想していました。
これが私のEJBクライアントコードコードスニペットです:
Subject subject = new Subject();
Principal myPrincipal = new MyPrincipal("me I myself");
subject.getPrincipals().add(myPrincipal);
PrivilegedExceptionAction<String> action = new PrivilegedExceptionAction<String>() {
public String run() throws Exception {
String result;
System.out.println("Current Subject: " + Subject.getSubject(AccessController.getContext()));
InitialContext ic = new InitialContext();
Business1 b = (Business1) ic.lookup("StatelessBusiness1");
result = b.getNewMessage("Hello World");
return result;
}
};
result = subject.doAs(subject, action);
System.out.println("result "+result);
サーバー側のコードは次のとおりです。
public String getNewMessage(String msg) {
System.out.println("getNewMessage principal: " + sessionContext.getCallerPrincipal());
System.out.println("Current Subject: " + Subject.getSubject(AccessController.getContext()));
return "getNewMessage: " + msg;
}
確かに、これがデフォルトの動作であっても、ejb-jar.xml
セッションBeanに次のセクションを追加しました。
<security-identity>
<use-caller-identity/>
</security-identity>
私のセッションBeanはどのロールによっても保護されていません。
このIBMWebSphereインフォセンターのセクションによると、システムプロパティも有効にしましたcom.ibm.CSI.rmiOutboundPropagationEnabled=true
。
技術的に言えば、サービスコールはJBossまたはWebSphereのいずれかで適切に機能します。ただし、クライアントで作成されたカスタムプリンシパルを含むJAASサブジェクトは、サーバーに伝達されません。またはもちろん、Subject
JNDIコンテキストの作成とEJB呼び出しの直前にダンプされても問題ありません。
サーバーとクライアント(IBM Java6 SR9 FP2 ...)に対して同じJavaランタイムバージョンを実行します。MyPrincipal
シリアル化可能なクラスはサーバーClassPath(AppServer/lib/ext
WebSphereの場合server/default/lib
、JBossの場合)で使用できます。
WebSphereダンプ:
[8/31/12 11:56:26:514 CEST] 00000024 SystemOut O getNewMessage principal: UNAUTHENTICATED
[8/31/12 11:56:26:515 CEST] 00000024 SystemOut O Current Subject: null
JBossダンプ:
12:30:20,540 INFO [STDOUT] getNewMessage principal: anonymous
12:30:20,540 INFO [STDOUT] Current Subject: null
確かに、私はある種の魔法の呪文を逃しました。どれか知っていますか?