<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Re: Security propagation from remote EJB clients to AS7
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/rodakr">Radek Rodak</a> in <i>JBoss AS 7 Development</i> - <a href="http://community.jboss.org/message/644551#644551">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>1)</p><p>Can you provide client sample code using SASL Security ( for now PLAIN example would be enought ).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span>( or just add this example to </span><a class="jive-link-external-small" href="https://docs.jboss.org/author/display/AS71/Developer+Guide#DeveloperGuide-EJBinvocationsfromaremoteclientusingJNDI" target="_blank">https://docs.jboss.org/author/display/AS71/Developer+Guide#DeveloperGuide-EJBinvocationsfromaremoteclientusingJNDI</a><span> )</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>2)</p><p>I looked in source code of&#160; org.jboss.sasl.JBossSaslProvider.java&#160; ( jboss-sasl-1.0.0.Beta9.jar )</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Ony SASL MECH I see here are:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>"ANONYMOUS"</p><p>"PLAIN",</p><p>"DIGEST-MD5",</p><p>"JBOSS-LOCAL-USER"</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Could you also add "GSSAPI"&#160; (&#160; here how to from Darran Lofthouse <a class="jive-link-wiki-small" href="http://community.jboss.org/docs/DOC-17302" target="_blank">http://community.jboss.org/wiki/SASLAndKerberos</a> )</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Basically I would like to do this but with AS7.1:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><a class="jive-link-external-small" href="http://community.jboss.org/docs/DOC-16137" target="_blank">http://community.jboss.org/wiki/EJB3AuthenticationWithSPNEGO</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I tried to call remote ejb after sucessfull JAAS Login, but JAAS Login Context seams to not get propagatet to Server over Jboss Remote...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here how I tried ( the same Code but calling Web URL Secured with SPNEGO works, so KRB5 Java Setup is ok)&#160; :</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import java.io.BufferedReader;</p><p>import java.io.IOException;</p><p>import java.io.InputStreamReader;</p><p>import java.security.AccessController;</p><p>import java.security.Principal;</p><p>import java.security.PrivilegedExceptionAction;</p><p>import java.security.Security;</p><p>import java.util.Collections;</p><p>import java.util.Hashtable;</p><p>import java.util.Properties;</p><p>import java.util.Set;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import javax.naming.Context;</p><p>import javax.naming.InitialContext;</p><p>import javax.naming.NamingException;</p><p>import javax.security.auth.Subject;</p><p>import javax.security.auth.callback.Callback;</p><p>import javax.security.auth.callback.CallbackHandler;</p><p>import javax.security.auth.callback.NameCallback;</p><p>import javax.security.auth.callback.PasswordCallback;</p><p>import javax.security.auth.callback.TextInputCallback;</p><p>import javax.security.auth.callback.TextOutputCallback;</p><p>import javax.security.auth.callback.UnsupportedCallbackException;</p><p>import javax.security.auth.login.LoginContext;</p><p>import javax.security.sasl.Sasl;</p><p>import javax.security.sasl.SaslClient;</p><p>import javax.security.sasl.SaslException;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import test.ejb3.TestServiceItf;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public class TestServiceClient {</p><p>&#160;&#160;&#160; static String JAAS_CONFIG_ENTRY = "com.sun.security.jgss.krb5.initiate";</p><p>&#160;&#160;&#160; static BufferedReader br = new BufferedReader( new InputStreamReader (System.in));</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; public static void main(String[] args) throws Exception {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; LoginContext lc = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("\n &gt;&gt; Enter Win user Name : ");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //String callbackUser&#160; = br.readLine ();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String callbackUser&#160; = "rrad";</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("\n &gt;&gt; Enter Win User AD password : ");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //String callbackPwd&#160; = br.readLine ();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String callbackPwd ="radoslaw13";</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // jaas collback might be needed for ticket refresh...</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lc = new LoginContext(JAAS_CONFIG_ENTRY,new NamePasswordCallbackHandler2(callbackUser,callbackPwd ));</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lc.login();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //and get a subject</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Subject mySubject = lc.getSubject();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(" *********??????????********&gt;&gt;&gt;&gt; subject: "+mySubject);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Set&lt;Principal&gt; sp = mySubject.getPrincipals();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ( sp == null ) System.out.println(" 0 principals ");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(+sp.size()+" principals");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; for ( Principal p : sp ) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("principal name :"+p.getName());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // in case if not passed to java as property.. </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.setProperty( "sun.security.krb5.debug", "true");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PrivilegedExceptionAction&lt;String&gt; action = new GetAction( null, null&#160; );</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //jaas call the service</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String aRet = (String)mySubject.doAs(mySubject, action);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // successfuly called, read returned values</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("successfully caled protected Method&#160; : "+aRet);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (Exception e) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.printStackTrace();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.exit(-1);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; /**</p><p>&#160;&#160;&#160;&#160; *&#160; dummy readLine Helper</p><p>&#160;&#160;&#160;&#160; * @return</p><p>&#160;&#160;&#160;&#160; */</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; public static String readLine(String message)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String s = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(message);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; InputStreamReader converter = new InputStreamReader(System.in);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; BufferedReader in = new BufferedReader(converter);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; s = in.readLine();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (Exception e) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Error! Exception: "+e); </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } finally {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return s;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>class GetAction implements PrivilegedExceptionAction&lt;String&gt; {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; private String toke;</p><p>&#160;&#160;&#160; private String user;</p><p>&#160;&#160;&#160; private String testEjbItf="test.ejb3.TestServiceItf";</p><p>&#160;&#160;&#160; // context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);</p><p>&#160;&#160;&#160; private String testEjbJndi="ejb:/sl-securityTestEjb3//TestServiceSLEJB3Bean!test.ejb3.TestServiceItf";</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; public GetAction(String user , String token) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.user = user;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.toke=token;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; static {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Sasl.createSaslClient(new String[]{"PLAIN"}, null, "remoting", "ux2084", Collections.EMPTY_MAP, new NamePasswordCallbackHandler2("rrad","radoslaw13" ) );</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (SaslException e) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // TODO Auto-generated catch block</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.printStackTrace();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; // make shure </p><p>&#160;&#160;&#160; public String run() throws Exception { </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; //Sasl.createSaslClient(new String[]{"GSSAPI"}, null, "remoting", "ux2084", Collections.EMPTY_MAP, new NamePasswordCallbackHandler2("xxx","yyy" ) );</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; //Sasl.createSaslClient(new String[]{"PLAIN"}, null, "remoting", "ux2084", Collections.EMPTY_MAP, new NamePasswordCallbackHandler2("xxx","yyy" ) );</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; javax.security.auth.Subject currentSubject = javax.security.auth.Subject.getSubject( AccessController.getContext());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ( currentSubject == null ) System.out.println(" our Action runs as Subject: null ");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; else System.out.println(" our Action runs as Subject: "+currentSubject.toString());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Context ctx = getInitialContext();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Initial Context created");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("lookup"+testEjbJndi+" @RolesAllowed({\"BackofficeRole\"})");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Class itfClass = Thread.currentThread().getContextClassLoader().loadClass(testEjbItf);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; TestServiceItf testService = (TestServiceItf)&#160; ctx.lookup(testEjbJndi);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("lookup testEjbJndi successful");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(" call unsecured Method permittAllMethod()");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Subject asu = testService.permittAllMethod(" calling unsecured");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(" successfully called, received Subject: "+asu);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(" call secured Method with role "+testService.BACKOFFICE_ROLE);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; asu = testService.pwvAuthenticatorSecuredMethod(" calling secured");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(" successfully called, received Subject: "+asu);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return "Test ok";</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; private static Context getInitialContext() throws NamingException {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; final Hashtable jndiProperties = new Hashtable();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; jndiProperties.put(Context.SECURITY_AUTHENTICATION, "GSSAPI");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; final Context context = new InitialContext(jndiProperties);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return context;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>class NamePasswordCallbackHandler2 implements CallbackHandler</p><p>{</p><p>&#160;&#160;&#160; /**</p><p>&#160;&#160;&#160;&#160; * The username to be provided when prompted.</p><p>&#160;&#160;&#160;&#160; */</p><p>&#160;&#160;&#160; private String username;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; /**</p><p>&#160;&#160;&#160;&#160; * The password to be provided when prompted.</p><p>&#160;&#160;&#160;&#160; */</p><p>&#160;&#160;&#160; private String password;</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; private String url;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; /**</p><p>&#160;&#160;&#160;&#160; * Create a new NamePasswordCallbackHandler (required Cams default </p><p>&#160;&#160;&#160;&#160; * constructor that is dynamically called by the authentication</p><p>&#160;&#160;&#160;&#160; * server).</p><p>&#160;&#160;&#160;&#160; * @param anURL </p><p>&#160;&#160;&#160;&#160; * @param callbackPwd </p><p>&#160;&#160;&#160;&#160; * @param callbackUser </p><p>&#160;&#160;&#160;&#160; */</p><p>&#160;&#160;&#160; public NamePasswordCallbackHandler2(String callbackUser, String callbackPwd)</p><p>&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.username = callbackUser;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.password = callbackPwd;</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; /**</p><p>&#160;&#160;&#160;&#160; * Set the username.</p><p>&#160;&#160;&#160;&#160; *</p><p>&#160;&#160;&#160;&#160; * @param username the username to be provided to a NameCallback.</p><p>&#160;&#160;&#160;&#160; */</p><p>&#160;&#160;&#160; public void setUsername(String username)</p><p>&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (username == null)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.username = "";</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.username = username;</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; /**</p><p>&#160;&#160;&#160;&#160; * Set the password.</p><p>&#160;&#160;&#160;&#160; *</p><p>&#160;&#160;&#160;&#160; * @param password the password to be provided to a PasswordCallback.</p><p>&#160;&#160;&#160;&#160; */</p><p>&#160;&#160;&#160; public void setPassword(String password)</p><p>&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (password == null)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.password = "";</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.password = password;</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; public void handle(Callback[] callbacks)</p><p>&#160;&#160;&#160; throws IOException, UnsupportedCallbackException</p><p>&#160; {</p><p>&#160;&#160;&#160; for(int i = 0; i &lt; callbacks.length; i++)</p><p>&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160; if(callbacks[i] instanceof TextOutputCallback)</p><p>&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Display the message according to the specified type</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; TextOutputCallback toc = (TextOutputCallback)callbacks[i];</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; switch(toc.getMessageType())</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; case TextOutputCallback.INFORMATION:</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log(toc.getMessage());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; case TextOutputCallback.ERROR:</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log("ERROR: " + toc.getMessage());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; case TextOutputCallback.WARNING:</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log("WARNING: " + toc.getMessage());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; default:</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new IOException("Unsupported message type: "+toc.getMessageType());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160; else if(callbacks[i] instanceof NameCallback)</p><p>&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // If username not supplied on cmd line, prompt the user for the username.</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; NameCallback nc = (NameCallback)callbacks[i];</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (username == null || username.isEmpty()) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.err.print(nc.getPrompt());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.err.flush();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; nc.setName((new BufferedReader(new InputStreamReader(System.in))).readLine());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; else {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log("username: "+username);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; nc.setName(username);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160; else if(callbacks[i] instanceof PasswordCallback)</p><p>&#160;&#160;&#160;&#160;&#160; { </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; PasswordCallback pc = (PasswordCallback)callbacks[i];</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // If password not supplied on cmd line, prompt the user for the password.</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (password == null || password.isEmpty()) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.err.print(pc.getPrompt());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.err.flush();</p><p>&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Note: JAAS specifies that the password is a char[] rather than a String</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String tmpPassword = (new BufferedReader(new InputStreamReader(System.in))).readLine();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; int passLen = tmpPassword.length();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; char[] passwordArray = new char[passLen];</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; for(int passIdx = 0; passIdx &lt; passLen; passIdx++)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; passwordArray[passIdx] = tmpPassword.charAt(passIdx);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; pc.setPassword(passwordArray);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; else {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String tPass = new String();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; for(int p = 0; p &lt; password.length(); p++)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; tPass += "*";</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log("password: "+tPass);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; pc.setPassword(password.toCharArray());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160; else if(callbacks[i] instanceof TextInputCallback)</p><p>&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Prompt the user for the username</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; TextInputCallback callback = (TextInputCallback)callbacks[i];</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.err.print(callback.getPrompt());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.err.flush();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; callback.setText((new BufferedReader(new InputStreamReader(System.in))).readLine());</p><p>&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160; else</p><p>&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");</p><p>&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; }</p><p>&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; private void log(String str) { System.out.println(str); }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Happy New Year</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Radek Rodak</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/644551#644551">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss AS 7 Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>