我已经写了以下文件-------------------
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.