Skip to content

Instantly share code, notes, and snippets.

@chenrui333
Last active May 12, 2016 19:23
Show Gist options
  • Save chenrui333/cd886797d18c2241c1be3fd3a309dd51 to your computer and use it in GitHub Desktop.
Save chenrui333/cd886797d18c2241c1be3fd3a309dd51 to your computer and use it in GitHub Desktop.

The script is used for encrypting the datasource passwords on jboss servers ref.

The flow is as follows:

  1. Encrypt the plain texts of passwords
  2. Change the *-ds.xml files, like
<!-- REPLACED WITH security-domain BELOW
<user-name>admin</user-name>
<password>password</password>
-->
<security-domain>EncryptDBPassword</security-domain>
  1. Change the login-config.xml

a. if local-tx-datasource, then add policy entry

<policy>
    <!-- Example usage of the SecureIdentityLoginModule -->
    <application-policy name="EncryptDBPassword">
        <authentication>
            <login-module code="org.jboss.resource.security.SecureIdentityLoginModule" flag="required">
                <module-option name="username">admin</module-option>
                <module-option name="password">5dfc52b51bd35553df8592078de921bc</module-option>
                <module-option name="managedConnectionFactoryName">jboss.jca:name=PostgresDS,service=LocalTxCM</module-option>
            </login-module>
        </authentication>
    </application-policy>
</policy>

b. if xa-datasource, then the module-option name="managedConnectionFactoryName" should be:

<module-option name="managedConnectionFactoryName">jboss.jca:name=PostgresDS,service=XATxCM</module-option>
#! /usr/bin/sh
pws=("$@")
# test if JBOSS_HOME set or not
[ -z "$JBOSS_HOME" ] && echo "Need to set JBOSS_HOME" && exit 1;
# encrypt the passwords
for arg in "${pws[@]}"; do
echo "*******************"
echo "Encrypting $arg..."
java -cp $JBOSS_HOME/client/jboss-logging.jar:$JBOSS_HOME/lib/jbosssx.jar org.jboss.resource.security.SecureIdentityLoginModule $arg
done
@chenrui333
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment