Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Basically (as far as I know) the client app security in EJB 3.1 is still like the one in 2.x so you should find examples.</p> <p>What you need to set up:</p> <ul> <li>jaas login module on the server side (as you have seen for web apps)</li> <li>client properties file that determines how to handle authentication</li> <li>client side callback, that provides the client-side auth process with the credentials</li> <li>start the client with the property file on the class path</li> </ul> <p>This is an example for jboss-as, but I think you can translate that to other servers, as the idea is generic:</p> <pre><code># file auth.conf on the client adb { // jBoss LoginModule org.jboss.security.ClientLoginModule required ; }; </code></pre> <p>This basically says that for the login context <code>adb</code> the client login module needs to succeed. This context <code>adb</code> is linked to the respective application jaas context on the server side.</p> <p>In the code you set up the login like this:</p> <pre><code>CallbackHandler cbh = new LoginCallbackHandler(user,pass.toCharArray()); try { LoginContext lc = new LoginContext("adb",cbh); lc.login(); // &lt;--- triggers the show in the client } catch (LoginException e) { System.err.println("Login failed: "+e.getMessage()); } </code></pre> <p>In the LoginContext you give the context <code>adb</code> from the auth.conf file above.</p> <p>The <code>LoginCallbackHandler</code> could look like this:</p> <pre><code>package de.bsd.adb.client; import java.io.IOException; import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.NameCallback; import javax.security.auth.callback.PasswordCallback; import javax.security.auth.callback.UnsupportedCallbackException; public class LoginCallbackHandler implements CallbackHandler { private String user; private char[] pass; // Konstruktor LoginCallbackHandler(String username,char[] password) { user=username; pass=password; } // handle() does the real work and is invoked from the client container public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { // Iterate over the call backs for (int i =0 ; i&lt; callbacks.length; i++) { // NameCallback -&gt; pass Login-Name if (callbacks[i] instanceof NameCallback) { System.out.println("NameCallback"); NameCallback nc = (NameCallback)callbacks[i]; nc.setName(user); } // PasswordCallback -&gt; pass Password else if (callbacks[i] instanceof PasswordCallback) { System.out.println("PasswordCallback"); PasswordCallback pc = (PasswordCallback)callbacks[i]; pc.setPassword(pass); } else { // unknown callback throw new UnsupportedCallbackException(callbacks[i],"Ouch"); }}} </code></pre> <p>Now you can start your client program with</p> <pre><code>java -Djava.security.auth.login.config=/path/to/auth.conf -cp bla my.Main </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload