2011-10-25 6 views
4

EJBプロジェクトでは、 "javax.ejb.SessionContext"内の呼び出しのプリンシパル名を置き換える必要があります。私はJboss AS 6.0 Finalをアプリケーションサーバーとして使用します。カスタムプリンシパルはJboss ASのEJB SessionContextに伝播されません

UsernamePasswordLoginModuleを拡張してカスタムプリンシパルを追加したカスタムUserLoginModuleを定義しましたが、カスタムプリンシパルはEJB SessionContextに伝播されません。ここで

は私のカスタムログインモジュールからいくつかのコードです:

@Override 
protected Group[] getRoleSets() throws LoginException { 

    Group[] groups = new Group[2]; 
    groups[0] = new SimpleGroup("Roles"); 
    groups[0].addMember(createRoleIdentity()); 

    Group callerPrincipal = new SimpleGroup("CallerPrincipal"); 
    callerPrincipal.addMember(createIdentity(this.getUsername())); 
    groups[1] = callerPrincipal; 
    subject.getPrincipals().add(callerPrincipal); 

    return groups; 
} 

@Override 
protected Principal createIdentity(String username) throws LoginException { 
    return new MyCustomPrincipal(username); 
} 

} 

マイカスタムログインモジュールはうまく動作しますが、私は「javax.ejb.SessionContextの」から取得呼び出し側プリンシパルはまだSimplePrincipalです。

それはJobssのバグがあることが判明:http://community.jboss.org/thread/44388:EJBContext.getCallerPrincipal()は、カスタムプリンシパルhttps://issues.jboss.org/browse/JBAS-8427

と関連トピックを返すされていません。

これについていくつかの経験があり、Jbossが作成するデフォルトのプリンシパルを置き換えても安全だと思いますか?それらの副作用はありますか?

+0

これは解決策に残ったJBoss 7 –

答えて

3

私のチームの助けを借りて、私は解決策を得ました。これは、同じ問題を抱えている人に役立つことを願っています。代わりの

「sessionContext.getCallerPrincipalは()」 は、カスタムプリンシパルを取得するには、以下を使用します。

 try { 
      Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container"); 

      Set<Group> subjectGroups = subject.getPrincipals(Group.class); 
      Iterator<Group> iter = subjectGroups.iterator(); 
      while (iter.hasNext()) { 
       Group group = iter.next(); 
       String name = group.getName(); 
       if (name.equals("CallerPrincipal")) { 
        Enumeration<? extends Principal> members = group.members(); 
        if (members.hasMoreElements()) { 

           Principal principal = (Principal) members.nextElement(); 
           return principal; 

         } 
        } 
       } 
      } 
     } catch (PolicyContextException e1) { 
      ... 
     } 
+0

おめでとうで問題になるようです。あなたができるときは、他の人があなたの成功から学ぶかもしれないようにあなたの答えを「受け入れ」とマークしてください。乾杯〜 –

関連する問題