jsp访问EJB 问题!

飞鱼1979 2005-04-29 09:07:31
问题:我是用jsp访问本地网络的一个session这个session需要认证才能访问:

我现在遇到的问题是;如果我加上这个认证的程序块,就不能通过,
但是如果我把这个访问session的程序作为一个单独的Client类的时候是能通过的
我不知道什么原因:(

下面是我的client类
是正常的

/*
* Created on 2005-4-16
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package junit;


import javax.naming.Context;
import javax.naming.InitialContext;
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.Properties;
import javax.ejb.CreateException;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import net.lancetech.ioffice.pub.PublicBasic;
import net.lancetech.ioffice.pub.PublicBasicHome;
import net.ioffice.lanceAuthentication.*;
import javax.security.auth.login.LoginContext;

import com.jivesoftware.base.Log;
import com.jivesoftware.base.UnauthorizedException;

import com.jivesoftware.base.AuthToken;

import com.jivesoftware.base.AuthFactory;
import com.jivesoftware.base.UnauthorizedException;
import com.jivesoftware.base.Log;

/**
* @author kuanda
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class TestEJB {

private net.lancetech.ioffice.pub.PublicBasicHome getHome()
throws NamingException {
return (net.lancetech.ioffice.pub.PublicBasicHome) getContext().lookup(
"iOffice/PublicBasic");
}

private InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();
props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://192.168.0.131:1099");
props.put(InitialContext.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");

InitialContext initialContext = new InitialContext(props);
return initialContext;
}

public PublicBasic testBean(String username, String password)
throws UnauthorizedException
{
if (username == null || password == null) {
throw new UnauthorizedException();
}

char[] charPass;
charPass = new char[password.length()];

for (int i = 0;i< password.length();i++){
charPass[i] = password.charAt(i);
}

try {



iOfficeCallbackHandler handler = new iOfficeCallbackHandler(username, charPass);
LoginContext lc = new LoginContext("iOffice", handler);

lc.login();

net.lancetech.ioffice.pub.PublicBasic myBean = getHome().create();


return myBean;

} catch (RemoteException e) {
e.printStackTrace();
return null;
} catch (CreateException e) {
e.printStackTrace();
return null;
} catch (NamingException e) {
e.printStackTrace();
return null;
} catch (javax.security.auth.login.LoginException e){
e.printStackTrace();
throw new UnauthorizedException();
}

}

public static void main(String[] args) {
TestEJB test = new TestEJB();
PublicBasic myb;
try{
myb = test.testBean("wangyukui@lance-tech.net","wangyukui");
System.out.println( myb.getMyself().firstName);
}catch(UnauthorizedException e){
e.printStackTrace();
}
catch (RemoteException e) {
e.printStackTrace();

}

}
}
...全文
100 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
寒舍人 2005-04-29
  • 打赏
  • 举报
回复
帮你顶
keen1982 2005-04-29
  • 打赏
  • 举报
回复
我不会ejb啊,javaBeans 还是熟一点得,只能帮你顶了!!!

然后关注这个话题!!!

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧