You can use the standard JAAS classes for programmatic authentication. Suppose we use our own implementation of LoginModule (or any standard implementation), com.sample.CustomLoginModule . This registration module is configured in the jboss XML configuration.
Step 1: Define the security domain in JBoss. For other servers, the same information can be configured in the JAAS configuration.
<security-domain name="customlogin" cache-type="default"> <authentication> <login-module code="com.sample.CustomLoginModule" flag="required"> </login-module> </authentication> </security-domain>
Step 2: use the user login module for logical login.
public void logInProgrammatically(String username, string password){ CallbackHandler handler =
}
With this solution, you are not tied to specific application APIs. This code is ported to any application server with JAAS configuration changes.
For programmatic authentication using JAAS, see the Oracle manual: http://docs.oracle.com/javase/7/docs/technotes/guides/security/jaas/tutorials/GeneralAcnOnly.html
Mohit source share