Ok, this is how I accomplished this (I'm working on JBOSS 4.2.1 GA and Oracle so some stuff may differ between versions and DB vendors):
You need to extend AbstractPasswordCredentialLoginModule.
I based mine (Called PGPLoginModule) on the out of the box implementation called SecureIdentityLoginModule the only difference between that and mine is the decode and encode methods which use a different encryption algorithm and process (mine is using a PGP certificate to decrypt a properties file where the password is stored) similar to what is explained in this article, but you can use whatever method you prefer.
You'll require to add the following jars located on jboss library folders in order to resolve dependencies:
- [JBOSS_HOME]/lib/jboss-common.jar
- [JBOSS_HOME]/lib/jboss-jmx.jar
- [JBOSS_HOME]/server/default/lib/jbosssx.jar
- [JBOSS_HOME]/server/default/lib/jboss-jca.jar
You need to JAR your class and place the jar on either:
- [JBOSS_HOME]/server/default/lib
or
When you have that you need to configure it on the Security Domain you defined on jboss's login-config.xml so that it uses your class (mine is org.company.resource.security.PGPLoginModule) instead of using the default one so it will look something like:
<application-policy name="PGPDomain">
<authentication>
<login-module code="org.company.resource.security.PGPLoginModule" flag="required">
<module-option name="username">[DB_USER]</module-option>
<module-option name="password">[ENCTRYPTED_PASSWORD]</module-option>
<module-option name="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=OracleDS</module-option>
</login-module>
</authentication>
</application-policy>
Please notice that depending on the strength and algorithm you decide to use you may need to install the Java Cryptography Extension Unlimited Strength Policy Files to your JRE.
I hope someone finds it useful.