为刺尾。
thorntail:
datasources:
data-sources:
myDS:
use-java-context: true
statistics-enabled: true
driver-name: mysql
connection-url: ${db.url}
security-domain: mydbSecure
jndi-name: java:/myDS
check-valid-connection-sql: select 1
valid-connection-checker-class-name: org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker
validate-on-match: false
background-validation: true
background-validation-millis: 10000
use-fast-fail: true
min-pool-size: 5
max-pool-size: 10
prefill: true
flush-strategy: FailingConnectionOnly
exception-sorter-class-name: org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter
security:
security-domains:
mydbSecure:
classic-authentication:
login-modules:
default:
module-options:
username: ${ds.uname}
password: ${ds.pass}
flag: required
code: org.picketbox.datasource.security.SecureIdentityLoginModule
cache-type: default
这就是您对密码进行编码的方式
public class EncodePassword {
public static void main(String[] args) throws Exception
{
String password = "password";
String encode = encode(password);
System.out.println("Encoded password: "+encode);
}
private static String encode(String secret) throws NoSuchPaddingException, NoSuchAlgorithmException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException
{
byte[] kbytes = "jaas is the way".getBytes();
SecretKeySpec key = new SecretKeySpec(kbytes, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encoding = cipher.doFinal(secret.getBytes());
BigInteger n = new BigInteger(encoding);
return n.toString(16);
}
}
以下是您将如何解码密码。
public class DecodePassword {
public static void main(String[] args) throws Exception {
String value = "5dfc52b51bd35553df8592078de921bc";
try {
System.out.println(decode(value));
} catch (Exception io) {
io.printStackTrace();
}
}
public static char[] decode(String secret)
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
byte[] kbytes = "jaas is the way".getBytes();
SecretKeySpec key = new SecretKeySpec(kbytes, "Blowfish");
BigInteger n = new BigInteger(secret, 16);
byte[] encoding = n.toByteArray();
//SECURITY-344: fix leading zeros
if (encoding.length % 8 != 0) {
int length = encoding.length;
int newLength = ((length / 8) + 1) * 8;
int pad = newLength - length; //number of leading zeros
byte[] old = encoding;
encoding = new byte[newLength];
for (int i = old.length - 1; i >= 0; i--) {
encoding[i + pad] = old[i];
}
//SECURITY-563: handle negative numbers
if (n.signum() == -1) {
for (int i = 0; i < newLength - length; i++) {
encoding[i] = (byte) -1;
}
}
}
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] decode = cipher.doFinal(encoding);
return new String(decode).toCharArray();
}
}
了解有关 picketBox 的更多信息。
https://source.jboss.org/browse/PicketBox/trunk/security-jboss-sx/jbosssx/src/main/java/org/picketbox/datasource/security/SecureIdentityLoginModule.java?r=276