java程序访问websphere6.1 下 的EJB3.0
请问,我用java程序,去调用一个发布在websphere application sever6.1 下的ejb3.0程序怎么掉,因为在调用的时候是加了,用户名密码,传过去,做一个安全认证的.我想问,是我的代码错了,还是那俩个文件放错了,还是都错了。
希望能给个全点的答案, 谢谢。
代码如下。
接口:
package itso.bank;
public inte易做图ce SecurityEJB {
public String echo(String message);
}
实现类:
package itso.bank;
import javax.annotation.security.RolesAllowed;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Remote(SecurityEJB.class)
@Stateless
public class SecurityEJBBean implements SecurityEJB {
@RolesAllowed( { "user" })
public String echo(String message) {
return message + " test";
}
}
测试代码:
public static void main(String[] args) {
// TODO Auto-generated method stub
Properties properties = new Properties();
properties.put("org.omg.CORBA.ORBClass", "com.ibm.CORBA.iiop.ORB");
properties.put(Context.PROVIDER_URL, "iiop://localhost:2809");
properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
properties.setProperty(Context.SECURITY_PRINCIPAL, "guo");
properties.setProperty(Context.SECURITY_CREDENTIALS, "guo");
try{
Context context = new InitialContext(properties);
itso.bank.SecurityEJB security = (itso.bank.SecurityEJB)context.lookup("ejb/TestEJB/TestEJB.jar/SecurityEJBBean#itso.bank.SecurityEJB");
System.out.println(security.echo("XXX"));
}
}
还有2个props文件
users.props
# Format:
# name:passwd:uid:gids:display name
# where name = userId/userName of the user
# passwd = password of the user
# uid = uniqueId of the user
# gid = groupIds of the groups that the user belongs to
# display name = (optional) display name for the user
admin:admin:0:0:Administrator
guo:guo:1::
visitor:visitor:2::
jacek:password:3::
groups.props
# Format:
# name:gid:users:display name
# where name = groupId of the group
# gid = uniqueId of the group
# users = list of all the userIds that the group contains
# display name = (optional) display name for the group
administrator:0:admin:Administrative group
user:1:guo:1 --------------------编程问答-------------------- 没人知道吗? 自己顶下 --------------------编程问答-------------------- 没遇到过,路过学习学习!帮顶! --------------------编程问答-------------------- 调用程序看似没有问题,不用main方法,在web环境下调一下试试。
补充:企业软件 , WebSphere