<!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="https://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;">
JAAS
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/sunil_dixit">Sunil Dixit</a> in <i>JNDI and Naming</i> - <a href="https://community.jboss.org/message/801523#801523">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;"> </p><p>I want to use JAAS ( cofigured on jboss 7) module for authenticate & authrorised client program so that it can use all secured EJBs running inside the container.To configure JASS in JBOSS 7 I have done following things</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>1. Added "security-realm"</p><p>2. Added "security-domain"</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Here are XML snippets</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><security-realm name="MyJAASRealm"></p><p>                    <authentication></p><p>                            <jaas name="MyJAAS"/></p><p>                    </authentication></p><p> </security-realm></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><security-domain name="MyJAAS" cache-type="default"></p><p>                    <authentication></p><p>                            <login-module code="Client" flag="required"></p><p>                                    <module-option name="usersProperties" value="${jboss.server.config.dir}/users.properties"/></p><p>                                    <module-option name="rolesProperties" value="${jboss.server.config.dir}/roles.properties"/></p><p>                            </login-module></p><p>                    </authentication></p><p></security-domain></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Now I have written TestClient which will use "LoginContext" to do authentication</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>public static void test()</p><p>{</p><p>env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");</p><p>env.put(Context.PROVIDER_URL, "remote://localhost:4447");</p><p>env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false");</p><p>env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");</p><p>LoginContext ref = getCLMLoginContext("Sunil", "Dixit");</p><p>ref.login();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>public static LoginContext getCLMLoginContext(final String username,final String password) throws LoginException {</p><p>        final String configurationName = "MyJAAS";</p><p>        CallbackHandler cbh = new CallbackHandler() {</p><p>            public void handle(Callback[] callbacks) throws IOException,</p><p>                    UnsupportedCallbackException {</p><p>                for (Callback current : callbacks) {</p><p>                    if (current instanceof NameCallback) {</p><p>                        ((NameCallback) current).setName(username);</p><p>                    } else if (current instanceof PasswordCallback) {</p><p>                        ((PasswordCallback) current).setPassword(password</p><p>                                .toCharArray());</p><p>                    } else {</p><p>                        throw new UnsupportedCallbackException(current);</p><p>                    }</p><p>                }</p><p>            }</p><p>        };</p><p>        Configuration config = new Configuration() {</p><p>            @Override</p><p>            public AppConfigurationEntry[] getAppConfigurationEntry(String name) {</p><p>                if (configurationName.equals(name) == false) {</p><p>                    throw new IllegalArgumentException(</p><p>                            "Unexpected configuration name '" + name + "'");</p><p>                }</p><p>                Map<String, String> options = new HashMap<String, String>();</p><p>                options.put("multi-threaded", "true");</p><p>                options.put("restore-login-identity", "true");</p><p>                AppConfigurationEntry clmEntry = new AppConfigurationEntry(</p><p>                org.jboss.security.auth.spi.UsersRolesLoginModule.class.getName(),</p><p>                AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,</p><p>                options);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                return new AppConfigurationEntry[] { clmEntry };</p><p>            }</p><p>        };</p><p>        cbh = new AppCallbackHandler("suniul", "assad".toCharArray() );</p><p>        return new LoginContext(configurationName, new Subject(), cbh, config);</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>My porblem is " How should I tell that LoginContext need to use "JAAS configured on server".</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>If anybody know this then plz help me.</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/801523#801523">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JNDI and Naming at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>