java LoginContext.login() 是如何工作的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2758248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does java LoginContext.login() work?
提问by tangens
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.confcontains the following lines:
该文件auth.conf包含以下几行:
myAuth {
org.jboss.security.ClientLoginModule required;
};
Now, somewhere else in the code (the LoginContext authisn'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. This narrowonly succeeds if the login information of the first step was correct.
现在,在代码中的其他地方(auth那里不知道LoginContext )我有一个 EJB,它执行 ainitialContext.lookup( jndiName )和 anarrow()来访问 JBoss 应用程序服务器上的 Bean。这narrow只有在第一步的登录信息正确的情况下才能成功。
Question
问题
How does the login information propagate from the LoginContextto the narrow()? I don't see any connection between these two places.
登录信息如何从 传播LoginContext到narrow()?我看不出这两个地方之间有任何联系。
And further, how could I do two or more different logins inside of one client?
此外,如何在一个客户端内进行两次或多次不同的登录?
采纳答案by tangens
I found a nice explanation in the JBoss documentation (chapter 8.4.1):
我在JBoss 文档(第 8.4.1 章)中找到了一个很好的解释:


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

