use of org.wildfly.security.password.interfaces.SaltedSimpleDigestPassword in project wildfly-elytron by wildfly-security.
the class FileSystemSecurityRealmTest method testCreateIdentityWithSimpleSaltedDigestHexEncodedAndCharset.
@Test
public void testCreateIdentityWithSimpleSaltedDigestHexEncodedAndCharset() throws Exception {
char[] actualPassword = "password密码".toCharArray();
byte[] salt = generateRandomSalt(BCRYPT_SALT_SIZE);
SaltedPasswordAlgorithmSpec spac = new SaltedPasswordAlgorithmSpec(salt);
EncryptablePasswordSpec eps = new EncryptablePasswordSpec(actualPassword, spac, Charset.forName("gb2312"));
PasswordFactory passwordFactory = PasswordFactory.getInstance(SaltedSimpleDigestPassword.ALGORITHM_PASSWORD_SALT_DIGEST_SHA_512, ELYTRON_PASSWORD_PROVIDERS);
SaltedSimpleDigestPassword tsdp = (SaltedSimpleDigestPassword) passwordFactory.generatePassword(eps);
assertCreateIdentityWithPassword(actualPassword, tsdp, Encoding.HEX, Charset.forName("gb2312"));
}
use of org.wildfly.security.password.interfaces.SaltedSimpleDigestPassword in project wildfly-elytron by wildfly-security.
the class FileSystemSecurityRealmTest method testCreateIdentityWithSimpleSaltedDigest.
@Test
public void testCreateIdentityWithSimpleSaltedDigest() throws Exception {
char[] actualPassword = "secretPassword".toCharArray();
byte[] salt = generateRandomSalt(BCRYPT_SALT_SIZE);
SaltedPasswordAlgorithmSpec spac = new SaltedPasswordAlgorithmSpec(salt);
EncryptablePasswordSpec eps = new EncryptablePasswordSpec(actualPassword, spac);
PasswordFactory passwordFactory = PasswordFactory.getInstance(SaltedSimpleDigestPassword.ALGORITHM_PASSWORD_SALT_DIGEST_SHA_512, ELYTRON_PASSWORD_PROVIDERS);
SaltedSimpleDigestPassword tsdp = (SaltedSimpleDigestPassword) passwordFactory.generatePassword(eps);
assertCreateIdentityWithPassword(actualPassword, tsdp);
}
use of org.wildfly.security.password.interfaces.SaltedSimpleDigestPassword in project wildfly-elytron by wildfly-security.
the class FileSystemSecurityRealmTest method testCreateIdentityWithSimpleSaltedDigestHexEncoded.
@Test
public void testCreateIdentityWithSimpleSaltedDigestHexEncoded() throws Exception {
char[] actualPassword = "secretPassword".toCharArray();
byte[] salt = generateRandomSalt(BCRYPT_SALT_SIZE);
SaltedPasswordAlgorithmSpec spac = new SaltedPasswordAlgorithmSpec(salt);
EncryptablePasswordSpec eps = new EncryptablePasswordSpec(actualPassword, spac);
PasswordFactory passwordFactory = PasswordFactory.getInstance(SaltedSimpleDigestPassword.ALGORITHM_PASSWORD_SALT_DIGEST_SHA_512, ELYTRON_PASSWORD_PROVIDERS);
SaltedSimpleDigestPassword tsdp = (SaltedSimpleDigestPassword) passwordFactory.generatePassword(eps);
assertCreateIdentityWithPassword(actualPassword, tsdp, Encoding.HEX, StandardCharsets.UTF_8);
}
use of org.wildfly.security.password.interfaces.SaltedSimpleDigestPassword in project wildfly-elytron by wildfly-security.
the class PasswordSupportTest method assertVerifyAndObtainSaltedDigestPasswordCredential.
public void assertVerifyAndObtainSaltedDigestPasswordCredential(String algorithm) throws Exception {
String userName = "john";
String userPassword = "salted_digest_abcd1234";
SaltedSimpleDigestPassword password = createSaltedDigestPasswordTable(algorithm, userName, userPassword);
PasswordKeyMapper passwordKeyMapper = PasswordKeyMapper.builder().setDefaultAlgorithm(algorithm).setHashColumn(1).setSaltColumn(2).build();
JdbcSecurityRealm securityRealm = JdbcSecurityRealm.builder().principalQuery("SELECT digest, salt FROM user_salted_digest_password where name = ?").withMapper(passwordKeyMapper).from(dataSourceRule.getDataSource()).setProviders(ELYTRON_PASSWORD_PROVIDERS).build();
assertEquals(SupportLevel.POSSIBLY_SUPPORTED, securityRealm.getCredentialAcquireSupport(PasswordCredential.class, algorithm, null));
RealmIdentity realmIdentity = securityRealm.getRealmIdentity(new NamePrincipal(userName));
assertEquals(SupportLevel.SUPPORTED, realmIdentity.getCredentialAcquireSupport(PasswordCredential.class, algorithm, null));
assertTrue(realmIdentity.verifyEvidence(new PasswordGuessEvidence(userPassword.toCharArray())));
SaltedSimpleDigestPassword storedPassword = realmIdentity.getCredential(PasswordCredential.class, algorithm).getPassword(SaltedSimpleDigestPassword.class);
assertNotNull(storedPassword);
assertArrayEquals(password.getDigest(), storedPassword.getDigest());
assertArrayEquals(password.getSalt(), storedPassword.getSalt());
}
use of org.wildfly.security.password.interfaces.SaltedSimpleDigestPassword in project wildfly-elytron by wildfly-security.
the class PasswordSupportTest method createSaltedDigestPasswordTable.
private SaltedSimpleDigestPassword createSaltedDigestPasswordTable(String algorithm, String userName, String userPassword) throws Exception {
try (Connection connection = dataSourceRule.getDataSource().getConnection();
Statement statement = connection.createStatement()) {
statement.executeUpdate("DROP TABLE IF EXISTS user_salted_digest_password");
statement.executeUpdate("CREATE TABLE user_salted_digest_password ( id INTEGER IDENTITY, name VARCHAR(100), digest OTHER, salt OTHER)");
}
try (Connection connection = dataSourceRule.getDataSource().getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO user_salted_digest_password (name, digest, salt) VALUES (?, ?, ?)")) {
byte[] salt = generateRandomSalt(BCRYPT_SALT_SIZE);
SaltedPasswordAlgorithmSpec spac = new SaltedPasswordAlgorithmSpec(salt);
EncryptablePasswordSpec eps = new EncryptablePasswordSpec(userPassword.toCharArray(), spac);
PasswordFactory passwordFactory = PasswordFactory.getInstance(algorithm, ELYTRON_PASSWORD_PROVIDERS);
SaltedSimpleDigestPassword tsdp = (SaltedSimpleDigestPassword) passwordFactory.generatePassword(eps);
preparedStatement.setString(1, userName);
preparedStatement.setBytes(2, tsdp.getDigest());
preparedStatement.setBytes(3, tsdp.getSalt());
preparedStatement.execute();
return tsdp;
}
}
Aggregations