简体   繁体   English

java LoginContext.login()如何工作?

[英]How does java LoginContext.login() work?

I have this code to create a configuration of a java client to connect to a JBoss application server: 我有以下代码来创建Java客户端的配置以连接到JBoss应用程序服务器:

System.setProperty( "java.security.auth.login.config", "auth.conf" );
LoginContext auth = new LoginContext( "myAuth", 
    new LoginCallbackHandler( username, password ) );
auth.login();

The file auth.conf contains the following lines: 文件auth.conf包含以下几行:

myAuth {
    org.jboss.security.ClientLoginModule required;
};

Now, somewhere else in the code (the LoginContext auth isn't known there) I have an EJB that does a initialContext.lookup( jndiName ) and a narrow() to access a Bean on the JBoss application server. 现在,在代码的其他地方(那里不知道LoginContext auth ),我有一个EJB,它执行initialContext.lookup( jndiName )narrow()来访问JBoss应用程序服务器上的Bean。 This narrow only succeeds if the login information of the first step was correct. 仅当第一步的登录信息正确时,此narrow才会成功。

Question

How does the login information propagate from the LoginContext to the narrow() ? 登录信息如何从LoginContext传播到LoginContext narrow() I don't see any connection between these two places. 我看不到这两个地方之间的任何联系。

And further, how could I do two or more different logins inside of one client? 而且,如何在一个客户端中进行两个或多个不同的登录?

I found a nice explanation in the JBoss documentation (chapter 8.4.1) : 我在JBoss文档(第8.4.1章)中找到了一个很好的解释:

jboss jaas登录

The login() call only binds the name and password to the JBoss EJB layer of the client. login()调用仅将名称和密码绑定到客户端的JBoss EJB层。 All subsequent EJB calls will use these credentials and pass them to the called EJB method. 所有后续的EJB调用都将使用这些凭据,并将它们传递给被调用的EJB方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM