ejb3.1 client访问 jboss 验证无法正确获取到密码参数

sh111111 2015-07-16 11:10:23
//初始化context
Properties ejbCCProperties=new Properties();

ejbCCProperties.put("remote.connections","default");
ejbCCProperties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED","false");

ejbCCProperties.put("remote.connection.default.username",userName);
ejbCCProperties.put("remote.connection.default.password",passWd);
ejbCCProperties.put("remote.connection.default.host",host);

ejbCCProperties.put("remote.connection.default.port",port);


final EJBClientConfiguration ejbClientConfiguration=new PropertiesBasedEJBClientConfiguration(ejbCCProperties);
final ContextSelector<EJBClientContext> ejbClientContextSelector=new ConfigBasedEJBClientContextSelector(ejbClientConfiguration);
final ContextSelector<EJBClientContext> previousSelector=EJBClientContext.setSelector(ejbClientContextSelector);
Properties jndiEnvironmentProperties=new Properties();
jndiEnvironmentProperties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");

return new InitialContext(jndiEnvironmentProperties);


后台验证类继承UsernamePasswordLoginModule ,validatePassword方法中的inputpassword传过来的值:7cb6a3b1-6fc7-46bd-9646-6eda1f80db9e(实际传的是demo,每次重启发现接收到的值还不一样)

已经研究了半天,实在搞不清楚密码为什么传的不对,username传的是正确的。调试发现jbosscallbackhandler在setSecurityInfo(Principal principal, Object credential)。credential的值就已经是7cb6a3b1-6fc7-46bd-9646-6eda1f80db9e。

同样的验证机制web端是可以调用的,只不过web.xml设置了loginconfig auth-method为form。暂时不清楚ejb client该如何设置

谢谢!
...全文
979 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
EJB3.1 JBoss7.0.2 EclipseJuno-helloworld实现 2013-01-06 02:59:54 分类: Java EJB3.1 JBoss7.1 Eclipse3.7---helloworld实现 一、环境配置: JDK:正常配置 Eclipse:正常下载,解压(V3.7) JBoss:正常下载,解压(V7.1) 二、JBoss Tools安装 在Eclipse里面安装JBoss Tools3.3 1、【Help】——>【Install New Software】——>【Add】 输入: Name: JBossTools Location: http://download.jboss.org/jbosstools/updates/development/indigo/ ——>【OK】——>【Select All】——>【Next】 ——>(中间的步骤一直NEXT,需要选择同意)——>【Finish】 2、【Help】——>【Install New Software】——>【Add】 输入: Name: JBossTools Aop Location: http://download.jboss.org/jbosstools/updates/development/indigo/soa-tooling/ ——>【OK】——>【Select All】——>【Next】 ——>(中间的步骤一直NEXT,需要选择同意)——>【Finish】 三、Eclipse里面配置JBoss 【File】——>【New】——>【Other】 (找到Server,并且选择)——>【Next】 (找到JBoss Community,选择JBoss AS 7.1)——>【Next】 (找到Home Directory)——>【Browse…】——> (选择JBoss解压的位置,即JBoss Home)——> (找到JRE,选择你安装的JRE)——>【Next】 ——>【Next】——>【Finish】 以上步骤完毕后,在Servers视图内会有JBoss服务器出现。 点击该视图内的启动按钮,JBoss服务器开始启动 浏览器可以访问http://127.0.0.1:8080/,就算配置成功。 四、第一个EJB工程 【File】——>【New】——>【Other】 (找到EJB,并且选择EJB Project)——>【Next】 输入: Project name:TestEJB Target runtime:选择JBoss7.1 EJB module version:选择3.1 ——>【Next】——>【Next】 (选择Generate ejb-jar.xml deployment descriptor) ——>【Finish】 生成的目录结构中,ejbModule目录为我们要写JAVA源代码的目录。 即EJB写在这里。 在ejbModule目录上右键【New】——>【Other】 (找到EJB,并且选择Session Bean(EJB 3.x))——>【Next】 输入:包名(com.ejb)、EJB类名(HelloWorld), State type部分:选择Stateless 然后选择Remote ——>【Finish】 自动生成代码如下: package com.ejb; import javax.ejb.Remote; @Remote public interface HelloWorldRemote { } package com.ejb; import javax.ejb.LocalBean; import javax.ejb.Stateless; /** * Session Bean implementation class HelloWorld */ @Stateless @LocalBean public class HelloWorld implements HelloWorldRemote { /** * Default constructor. */ public HelloWorld() { // TODO Auto-generated constructor stub } } 在接口里面增加以下方法 public String sayHello(String name); 类里面实现该方法 public String sayHello(String name){ return "Hello this is " + name + "!"; } 五、部署EJB 在工程上右键——>【Export】——>【EJB JAR file】 在Destination处:——>【Browse…】——> 选择JBoss服务器的部署目录,我的目录如下: D:\eclipse-jboss\jboss-as-7.1.1.Final\standalone\deployments\TestEJB.jar 然后——>【Finish】 在Console视图会出现详细部署信息 六、客户端代码 1、新建一个普通Java Project工程: 2、加入JBOSS运行库,及jboss\bin\client下的jboss-client.jar包 3、把EJB的接口拷贝到该工程内: 4、新建一个客户端类:类名(ClientTest) 代码如下: import java.util.Hashtable; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import com.ejb.HelloWorldRemote; public class ClientTest { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Hashtable jndiProperties = new Hashtable(); jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); try { Context context = new InitialContext(jndiProperties); final String appName = ""; final String moduleName = "TestEJB"; final String distinctName = ""; Object obj = context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/HelloWorld!com.ejb.HelloWorldRemote"); HelloWorldRemote hwr = (HelloWorldRemote)obj; String say = hwr.sayHello("hiyaSoft"); System.out.println(say); } catch (NamingException e) { e.printStackTrace(); } } } 5、在classPath下增加“jboss-ejb-client.properties”文件,内容如下 remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false remote.connections=default remote.connection.default.host=localhost remote.connection.default.port = 4447 remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false 6、运行该客户端,有如下结果: Hello hiyaSoft!

6,787

社区成员

发帖
与我相关
我的任务
社区描述
JBoss技术交流
社区管理员
  • JBoss技术交流社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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