Sunil Dixit
2013-03-08 10:29:54 UTC
Sunil Dixit [https://community.jboss.org/people/sunil_dixit] created the discussion
"JAAS"
To view the discussion, visit: https://community.jboss.org/message/801523#801523
--------------------------------------------------------------
Hi,
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
1. Added "security-realm"
2. Added "security-domain"
Here are XML snippets
<security-realm name="MyJAASRealm">
                   <authentication>
                           <jaas name="MyJAAS"/>
                   </authentication>
</security-realm>
<security-domain name="MyJAAS" cache-type="default">
                   <authentication>
                           <login-module code="Client" flag="required">
                                   <module-option name="usersProperties" value="${jboss.server.config.dir}/users.properties"/>
                                   <module-option name="rolesProperties" value="${jboss.server.config.dir}/roles.properties"/>
                           </login-module>
                   </authentication>
</security-domain>
Now I have written TestClient which will use "LoginContext" to do authentication
public static void test()
{
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
LoginContext ref = getCLMLoginContext("Sunil", "Dixit");
ref.login();
}
public static LoginContext getCLMLoginContext(final String username,final String password) throws LoginException {
       final String configurationName = "MyJAAS";
       CallbackHandler cbh = new CallbackHandler() {
           public void handle(Callback[] callbacks) throws IOException,
                   UnsupportedCallbackException {
               for (Callback current : callbacks) {
                   if (current instanceof NameCallback) {
                       ((NameCallback) current).setName(username);
                   } else if (current instanceof PasswordCallback) {
                       ((PasswordCallback) current).setPassword(password
                               .toCharArray());
                   } else {
                       throw new UnsupportedCallbackException(current);
                   }
               }
           }
       };
       Configuration config = new Configuration() {
           @Override
           public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
               if (configurationName.equals(name) == false) {
                   throw new IllegalArgumentException(
                           "Unexpected configuration name '" + name + "'");
               }
               Map<String, String> options = new HashMap<String, String>();
               options.put("multi-threaded", "true");
               options.put("restore-login-identity", "true");
               AppConfigurationEntry clmEntry = new AppConfigurationEntry(
               org.jboss.security.auth.spi.UsersRolesLoginModule.class.getName(),
               AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
               options);
               return new AppConfigurationEntry[] { clmEntry };
           }
       };
       cbh = new AppCallbackHandler("suniul", "assad".toCharArray() );
       return new LoginContext(configurationName, new Subject(), cbh, config);
   }
My porblem is " How should I tell that LoginContext need to use "JAAS configured on server".
If anybody know this then plz help me.
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/801523#801523]
Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]
"JAAS"
To view the discussion, visit: https://community.jboss.org/message/801523#801523
--------------------------------------------------------------
Hi,
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
1. Added "security-realm"
2. Added "security-domain"
Here are XML snippets
<security-realm name="MyJAASRealm">
                   <authentication>
                           <jaas name="MyJAAS"/>
                   </authentication>
</security-realm>
<security-domain name="MyJAAS" cache-type="default">
                   <authentication>
                           <login-module code="Client" flag="required">
                                   <module-option name="usersProperties" value="${jboss.server.config.dir}/users.properties"/>
                                   <module-option name="rolesProperties" value="${jboss.server.config.dir}/roles.properties"/>
                           </login-module>
                   </authentication>
</security-domain>
Now I have written TestClient which will use "LoginContext" to do authentication
public static void test()
{
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
LoginContext ref = getCLMLoginContext("Sunil", "Dixit");
ref.login();
}
public static LoginContext getCLMLoginContext(final String username,final String password) throws LoginException {
       final String configurationName = "MyJAAS";
       CallbackHandler cbh = new CallbackHandler() {
           public void handle(Callback[] callbacks) throws IOException,
                   UnsupportedCallbackException {
               for (Callback current : callbacks) {
                   if (current instanceof NameCallback) {
                       ((NameCallback) current).setName(username);
                   } else if (current instanceof PasswordCallback) {
                       ((PasswordCallback) current).setPassword(password
                               .toCharArray());
                   } else {
                       throw new UnsupportedCallbackException(current);
                   }
               }
           }
       };
       Configuration config = new Configuration() {
           @Override
           public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
               if (configurationName.equals(name) == false) {
                   throw new IllegalArgumentException(
                           "Unexpected configuration name '" + name + "'");
               }
               Map<String, String> options = new HashMap<String, String>();
               options.put("multi-threaded", "true");
               options.put("restore-login-identity", "true");
               AppConfigurationEntry clmEntry = new AppConfigurationEntry(
               org.jboss.security.auth.spi.UsersRolesLoginModule.class.getName(),
               AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
               options);
               return new AppConfigurationEntry[] { clmEntry };
           }
       };
       cbh = new AppCallbackHandler("suniul", "assad".toCharArray() );
       return new LoginContext(configurationName, new Subject(), cbh, config);
   }
My porblem is " How should I tell that LoginContext need to use "JAAS configured on server".
If anybody know this then plz help me.
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/801523#801523]
Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]