我正在尝试从独立的Java应用程序中查找EJB。我正在考虑WebSphere Application Server 6.1,但如果有人知道如何为另一个应用程序服务器执行此操作,它可能会让我朝着正确的方向前进。
我目前正在做的事情:
initialContext= new InitialContext(env);
initialContext.lookup("");
lc = new LoginContext("WSLogin", new WSCallbackHandlerImpl("wasadmin", "defaultWIMFileBasedRealm", "wasadmin"));
lc.login();
subject = lc.getSubject();
WSSubject.setRunAsSubject(subject);
这不起作用......我的主题仍然是“/ UNAUTHENTICATED”,当我尝试查找EJB时出现错误。我还在执行应用程序时为VM指定以下参数:
-Dcom.ibm.CORBA.ConfigURL = “C:\ WAS \型材\ AppSrv01 \特性\ sas.client.props” -Djava.security.auth.login.config = “C:\ WAS \型材\ AppSrv01 \特性\ wsjaas_client.conf”
答案 0 :(得分:1)
对于WebSphere 6,尝试从同样的WebSphere中部署的servlet(Jersey-RESTful WAR)中加入一个安全的EJB;这是适用的代码
Properties prop = new Properties();
prop.put("org.omg.CORBA.ORBClass", "com.ibm.CORBA.iiop.ORB");
prop.put("java.naming.factory.initial", "com.ibm.websphere.naming.WsnInitialContextFactory");
prop.put("java.naming.provider.url", "corbaloc:iiop:localhost:9810");
prop.put("com.ibm.CORBA.securityEnabled", "true");
prop.put("com.ibm.CORBA.validateBasicAuth", "true");
Context ctx;
try {
ctx = new InitialContext(prop);
System.out.println("Resolved Inital Context");
Object ejbHome = ctx.lookup("");
System.out.println("Resolved Home OperationManagerEJB");
logger.info("So far so good, tryining to Login ");
LoginContext lc;
lc = new LoginContext("WSLogin",new WSCallbackHandlerImpl("username","password"));
lc.login();
logger.info("Login Suceeded with omc_user");
WSSubject.setRunAsSubject(lc.getSubject()); //This is one key call
logger.info("Setting the authorization sibject");
参考