How does java LoginContext.login() work?

Posted by tangens on Stack Overflow See other posts from Stack Overflow or by tangens
Published on 2010-05-03T13:15:06Z Indexed on 2010/05/03 13:18 UTC
Read the original article Hit count: 232

Filed under:
|
|
|

I have this code to create a configuration of a java client to connect to a JBoss application server:

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:

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. This narrow only succeeds if the login information of the first step was correct.

Question

How does the login information propagate from the LoginContext to the 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?

© Stack Overflow or respective owner

Related posts about java

Related posts about authentication