-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) at 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.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。在这种情况下,请检查您Users/GroupsWeblogic中的设置。

2)在部署之前或之后,您没有映射到部署描述符User: manager中定义的任何内容。roles检查您部署的应用程序并查看是否User: manager映射到任何提供的角色。

3)您的代码引用了错误的角色名称。

例如:

isUserInRole("Manager");

此代码不起作用,因为它没有引用<role-name>部署描述符中定义的任何内容。检查小写大写精确 字符。因为isUserInRole区分大小写。

注意:请发布执行角色检查的代码,并发布可能的完整错误堆栈跟踪。

于 2013-05-19T03:11:59.383 回答