You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Glassfish JDBCConnectionPool数据库密码封装示例咨询

Encrypting Database Password for GlassFish JDBC Connection Pool

Got it, since you already know how to handle admin password encryption in GlassFish, let's jump right into securing your database password for JDBC Connection Pools. Here's a hands-on example with all the steps you need:

Step 1: Generate the Encrypted Database Password

First, use GlassFish's built-in asadmin encrypt tool to turn your plaintext database password into an encrypted string. This uses your domain's master password (the same one you use for admin operations) for encryption.

Run this command (replace placeholders with your actual paths/password):

asadmin encrypt --masterpasswordfile /path/to/your/domain-master-password.txt "your-plaintext-db-password"
  • The masterpasswordfile should point to a text file containing your domain's master password (to avoid entering it interactively).
  • After running, you'll get an output like {SSHA256}7ZkX... – this is your encrypted password, keep it handy.

Step 2: Update Your JDBC Connection Pool Configuration

You can do this via the command line or the GlassFish Admin Console – pick whichever you prefer:

Option A: Command Line

Use the asadmin set command to update the connection pool's password property directly:

asadmin set domain.resources.jdbc-connection-pool.Your-Pool-Name.password="{SSHA256}7ZkX..."

Replace Your-Pool-Name with the exact name of your JDBC Connection Pool, and paste the encrypted string you generated.

Option B: Admin Console

  1. Log into the GlassFish Admin Console (default URL: http://localhost:4848)
  2. Navigate to Resources > JDBC > JDBC Connection Pools
  3. Select your target connection pool, then go to the Additional Properties tab
  4. Find the password property, replace the plaintext value with your encrypted password (including the {SSHA256} prefix)
  5. Click Save, then restart your GlassFish domain to apply changes.

Step 3: Verify the Configuration Works

After restarting the domain, test if the connection pool can successfully connect to the database with the encrypted password:

asadmin ping-connection-pool Your-Pool-Name

If you see Command ping-connection-pool executed successfully., you're good to go – the encrypted password is working correctly.

Important Notes

  • Keep your master password safe: GlassFish uses this to decrypt the database password. If you lose it, your connection pool won't be able to connect to the database.
  • Check encryption algorithm: GlassFish defaults to SSHA256, but you can confirm/modify this in your domain.xml under the <security-service> → <password-encoder> node.
  • New pools: When creating a new JDBC Connection Pool, you can directly enter the encrypted password instead of plaintext – no extra steps needed.

内容的提问来源于stack exchange,提问作者Gustavo de Freitas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:46:51