<!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">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;">
    JAAS + EJB3.0 + Jboss unable to propaogate
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/Gauravag">Gaurav Agarwal</a> in <i>EJB 3.0 Development</i> - <a href="http://community.jboss.org/message/548957#548957">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>I have made a application where the user(client) will get authenticated then he/she can call ejb methods for some modifications where it has to be authorised.</p><p>But the problem i''m having is that when my client is getting authenticated then also while calling the ejb module its always showing <strong>Invalid User</strong> althogh the user has been authenticated. The subject and all its principal values are also being propagated.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>So how do i get the same thing done</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>i have a UserServlet(this is client end) as Given below</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java">PasswordCallbackHandler handler = <font color="navy"><b>new</b></font> PasswordCallbackHandler();
LoginContext loginContext = <font color="navy"><b>new</b></font> LoginContext(<font color="red">"PassAuth"</font>,handler);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; loginContext.login();
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; Set&lt;Principal&gt; pricipalSet =
&#160;&#160;&#160;&#160;&#160;&#160;&#160; loginContext.getSubject().getPrincipals();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; Set&lt;Principal&gt; pricipalSet =
&#160;&#160;&#160;&#160;&#160;&#160;&#160; loginContext.getSubject().getPrincipals();
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; Iterator iterator = pricipalSet.iterator();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(<font color="red">"Principal = "</font>);
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>while</b></font>(iterator.hasNext()) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Principal principal = (Principal) iterator.next();
<font color="darkgreen">//&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SecurityAssociation.setPrincipal(principal);</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(<font color="red">""</font>+principal.getName());
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font><font color="darkgreen">//while()</font>
&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(<font color="red">"value of subject is "</font>+loginContext.getSubject());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Subject.doAs(loginContext.getSubject(), <font color="navy"><b>new</b></font> PrivilegedAction() <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>public</b></font> Object run() <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(<font color="red">"in do As PrivilegedAction ................ "</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>try</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Properties properties = <font color="navy"><b>new</b></font> Properties();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; properties.setProperty(<font color="red">"INITIAL_CONTEXT_FACTORY"</font>,<font color="red">"org.jnp.interfaces.NamingContextFactory"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; properties.setProperty(<font color="red">"URL_PKG_PREFIXES"</font>,<font color="red">"org.jboss.naming:org.jnp.interfaces"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; properties.setProperty(<font color="red">"PROVIDER_URL"</font>,<font color="red">"jnp://localhost:1099"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; properties.put(Context.SECURITY_PRINCIPAL, <font color="red">"avril"</font>);
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Context&#160; context = <font color="navy"><b>new</b></font> InitialContext(properties);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Object object = context.lookup(<font color="red">"java/AttributeBI/remote"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(<font color="red">"Object ============="</font>+object);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AttributeBI attributeBI = (AttributeBI) object;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Attribute attribute = <font color="navy"><b>new</b></font> Attribute();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; attribute.setDataType(<font color="red">"test"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(<font color="red">"SecurityAssociation.getSubject :: "</font>+SecurityAssociation.getSubject());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; attributeBI.createAttribute(attribute);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font><font color="navy"><b>catch</b></font>(Exception exception) <font color="navy">{</font>
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; exception.printStackTrace();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> <font color="navy"><b>true</b></font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>);
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; loginContext.logout();
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Now this uses a config file. PassAuth.conf</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java">PassAuth <font color="navy">{</font>
&#160;&#160; <font color="darkgreen">// jBoss LoginModule</font>
&#160;&#160; <font color="darkgreen">//com.mqa.iam.module.PasswordLoginModule required debug="true";</font>
&#160; org.jboss.security.ClientLoginModule required;
<font color="navy">}</font>;
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My PasswordLoginModule is as below.</p><p>Here in this i'm geting credentials of the subject but even then its showing invalid user.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> initialize(Subject subject,
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CallbackHandler callbackHandler,
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Map sharedState,
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Map options) <font color="navy">{</font>
&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(<font color="red">"----------Initialization In Login Module----------"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.subject=subject;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.callbackHandler=callbackHandler;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.sharedState=sharedState;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.option=options;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; vector_principal = <font color="navy"><b>new</b></font> Vector();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; vector_credentials = <font color="navy"><b>new</b></font> Vector();
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; SecurityAssociation.setServer();
&#160;&#160;&#160;&#160;&#160;&#160; 
<font color="darkgreen">//&#160;&#160;&#160;&#160;&#160; SecurityAssociationActions.setServer();</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font>(option.containsKey(<font color="red">"debug"</font>)) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; debug = <font color="red">"true"</font>.equals(option.get(<font color="red">"debug"</font>));
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font><font color="darkgreen">//if</font>
&#160; <font color="navy">}</font><font color="darkgreen">//Initialization</font>
&#160;
&#160;&#160; 
&#160;&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>boolean</b></font> login() <font color="navy"><b>throws</b></font> LoginException <font color="navy">{</font>
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font>( debug ) <font color="navy">{</font>
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Callback[] callbacks = <font color="navy"><b>new</b></font> Callback[2];
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; callbacks[0] = <font color="navy"><b>new</b></font> NameCallback(<font color="red">"UserName :"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; callbacks[1] = <font color="navy"><b>new</b></font> PasswordCallback(<font color="red">"Password :"</font>, <font color="navy"><b>true</b></font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>try</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; callbackHandler.handle(callbacks);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font><font color="navy"><b>catch</b></font>(Exception ex)<font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ex.printStackTrace();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; NameCallback nameCallback = (NameCallback) callbacks[0];
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PasswordCallback passwordCallback = (PasswordCallback) callbacks[1];
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(<font color="red">"userName =========="</font>+nameCallback.getName());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(<font color="red">"pwd ======================"</font>+passwordCallback.getPassword());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">/* set principle as user's username */</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; user_principal=<font color="navy"><b>new</b></font> UserPrincipal(nameCallback.getName());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; vector_principal.add(user_principal);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>boolean</b></font> f = SecurityAssociation.isServer();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(<font color="red">"flag ================="</font>+f);&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font><font color="darkgreen">//if</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> <font color="navy"><b>true</b></font>;
&#160;&#160;&#160; <font color="navy">}</font><font color="darkgreen">//login()</font>
</code></pre><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>Please help me solve it.</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/548957#548957">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB 3.0 Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2030">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


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

</div>

</body>
</html>