-1

次のファイルを書きました -------------------------------

ejb-jar.xml
-------------

<?xml version="1.0"?>

<!DOCTYPE ejb-jar PUBLIC 
'-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 
'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

<ejb-jar>
  <enterprise-beans>
    <session>
     <ejb-name>HelloEJB2</ejb-name>

     <home>com.jlcindia.ejb2.hello.HelloHome</home>
     <remote>com.jlcindia.ejb2.hello.HelloRemote</remote>
     <ejb-class>com.jlcindia.ejb2.hello.HelloBean</ejb-class>
     <session-type>Stateless</session-type>
     <transaction-type>Container</transaction-type>
     <security-role-ref>
     <role-name>managers</role-name>
     <role-link>manager</role-link>
     </security-role-ref>

     <security-role-ref>
     <role-name>students</role-name>
     <role-link>student</role-link>
     </security-role-ref>

     <security-role-ref>
     <role-name>administrators</role-name>
     <role-link>administrator</role-link>
     </security-role-ref>

     </session>
     </enterprise-beans>
     <assembly-descriptor>
     <security-role>
     <role-name>manager</role-name>
     </security-role>

     <security-role>
     <role-name>student</role-name>
     </security-role>

     <security-role>
     <role-name>administrator</role-name>
     </security-role>
     </assembly-descriptor>

</ejb-jar>

weblogic-ejb-jar.xml (using weblogic 8)
----------------------
<?xml version="1.0"?>

<!DOCTYPE weblogic-ejb-jar PUBLIC 
'-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN'
'http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd'>

<weblogic-ejb-jar>

  <weblogic-enterprise-bean>

  <ejb-name>HelloEJB2</ejb-name>
  <jndi-name>JLCHelloHomeJNDI2</jndi-name>
  </weblogic-enterprise-bean>

<security-role-assignment>
<role-name>manager</role-name>
<principal-name>managers</principal-name>
</security-role-assignment>
</weblogic-ejb-jar>

HelloHome.java
-----------------
package com.jlcindia.ejb2.hello;
import java.rmi.RemoteException;


import javax.ejb.*;

public interface HelloHome extends EJBHome{
    public HelloRemote create()throws CreateException,RemoteException;
}


HelloRemote.java
----------------
package com.jlcindia.ejb2.hello;
import java.rmi.RemoteException;

import javax.ejb.*;


public interface HelloRemote extends EJBObject{
    public String getMessage(String name)throws RemoteException;
    public void balance()throws RemoteException;
    public void updateAccount()throws RemoteException;

}


HelloBean.java
------------
package com.jlcindia.ejb2.hello;

import java.rmi.RemoteException;

import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

public class HelloBean implements SessionBean{

    SessionContext sc;
    public void ejbCreate()throws EJBException,RemoteException{
        System.out.println("HelloBean-ejbCreate()");
    }

    public void ejbActivate() throws EJBException, RemoteException {
        System.out.println("HelloBean-ejbActivate()");

    }

    public void ejbPassivate() throws EJBException, RemoteException {
        System.out.println("HelloBean-ejbPassivate()");

    }

    public void ejbRemove() throws EJBException, RemoteException {
        System.out.println("HelloBean-ejbRemove()");

    }

    public void setSessionContext(SessionContext sc) throws EJBException,
            RemoteException {
        System.out.println("HelloBean-setSessionContext()");
        this.sc=sc;

    }
    public String getMessage(String name){
        String msg="Hello!"+name+"welcome to EJB2 with weblogic8";
        System.out.println(msg);
        return msg;
    }

    public void balance(){
        if(sc.isCallerInRole("managers")||sc.isCallerInRole("cashiers"))
        System.out.println("inside balance");
        else{
            System.out.println("not manager or administrator for balance");
        }
    }


    public void updateAccount(){
        if(sc.isCallerInRole("administrators"))
        System.out.println("update account");
        else{
            System.out.println("not administrators for updatation");
        }
    }

}



HelloClient.java
-------------
package com.jlcindia.ejb2.hello;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

public class HelloClient {
    public static void main(String[] args) {
        try{
            Properties p=new Properties();
            p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
            p.put(Context.PROVIDER_URL, "t3://localhost:7001");
            p.put(Context.SECURITY_PRINCIPAL, "manager");
            p.put(Context.SECURITY_CREDENTIALS, "manager");
            Context ctx=new InitialContext(p);
            Object obj=ctx.lookup("JLCHelloHomeJNDI2");
            HelloHome home=(HelloHome)obj;
            HelloRemote hello=home.create();
            String msg=hello.getMessage("srinivas");
            hello.updateAccount();
            hello.balance();
            System.out.println(msg);

        }catch(Exception e){
            e.printStackTrace();
        }
    }

}



and I m using weblogic 8
after deploying and 
runnig the HelloClient



m getting the following Exception
-----------------

javax.naming.AuthenticationException. ルート例外は java.lang.SecurityException: User: manager, failed to be authenticated.at weblogic.common.internal.RMIBootServiceImpl.authenticate(RMIBootServiceImpl.java:95) at weblogic.common.internal.RMIBootServiceImpl_WLSkel.invoke(Unknown Source) ですweblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:466) で weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:409) で weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java) :353) weblogic.security.service.SecurityManager.runAs(SecurityManager.java:144) で weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:404) で weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest. java:30) weblogic.kernel にあります。

Please tell me the solution for this n thanks in adv.
4

1 に答える 1

0

これにはいくつかの理由が考えられます。

1)User: managerに存在しませんWeblogic login realms。この場合、WeblogicUsers/Groupsの設定を確認してください。

2)展開前または展開後に、展開記述子で定義されたUser: managerいずれにもマッピングしていません。rolesデプロイされたアプリケーションを確認User: managerし、提供されたロールのいずれかにマップされているかどうかを確認します。

3)コードが間違ったロール名を参照しています。

例:

isUserInRole("Manager");

<role-name>このコードは、デプロイメント記述子で定義されたいずれも参照していないため、機能しません。小文字大文字正確な 文字を確認してください。isUserInRole大文字と小文字が区別されるためです。

注:ロール チェックを実行するコードを投稿し、可能性のある完全なエラー スタック トレースも投稿してください。

于 2013-05-19T03:11:59.383 に答える