Search in sources :

Example 1 with SaltedSimpleDigestPassword

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"));
}
Also used : PasswordFactory(org.wildfly.security.password.PasswordFactory) IteratedSaltedPasswordAlgorithmSpec(org.wildfly.security.password.spec.IteratedSaltedPasswordAlgorithmSpec) SaltedPasswordAlgorithmSpec(org.wildfly.security.password.spec.SaltedPasswordAlgorithmSpec) EncryptablePasswordSpec(org.wildfly.security.password.spec.EncryptablePasswordSpec) SaltedSimpleDigestPassword(org.wildfly.security.password.interfaces.SaltedSimpleDigestPassword) Test(org.junit.Test)

Example 2 with SaltedSimpleDigestPassword

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);
}
Also used : PasswordFactory(org.wildfly.security.password.PasswordFactory) IteratedSaltedPasswordAlgorithmSpec(org.wildfly.security.password.spec.IteratedSaltedPasswordAlgorithmSpec) SaltedPasswordAlgorithmSpec(org.wildfly.security.password.spec.SaltedPasswordAlgorithmSpec) EncryptablePasswordSpec(org.wildfly.security.password.spec.EncryptablePasswordSpec) SaltedSimpleDigestPassword(org.wildfly.security.password.interfaces.SaltedSimpleDigestPassword) Test(org.junit.Test)

Example 3 with SaltedSimpleDigestPassword

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);
}
Also used : PasswordFactory(org.wildfly.security.password.PasswordFactory) IteratedSaltedPasswordAlgorithmSpec(org.wildfly.security.password.spec.IteratedSaltedPasswordAlgorithmSpec) SaltedPasswordAlgorithmSpec(org.wildfly.security.password.spec.SaltedPasswordAlgorithmSpec) EncryptablePasswordSpec(org.wildfly.security.password.spec.EncryptablePasswordSpec) SaltedSimpleDigestPassword(org.wildfly.security.password.interfaces.SaltedSimpleDigestPassword) Test(org.junit.Test)

Example 4 with SaltedSimpleDigestPassword

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());
}
Also used : NamePrincipal(org.wildfly.security.auth.principal.NamePrincipal) PasswordCredential(org.wildfly.security.credential.PasswordCredential) PasswordGuessEvidence(org.wildfly.security.evidence.PasswordGuessEvidence) RealmIdentity(org.wildfly.security.auth.server.RealmIdentity) SaltedSimpleDigestPassword(org.wildfly.security.password.interfaces.SaltedSimpleDigestPassword) PasswordKeyMapper(org.wildfly.security.auth.realm.jdbc.mapper.PasswordKeyMapper)

Example 5 with SaltedSimpleDigestPassword

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;
    }
}
Also used : PasswordFactory(org.wildfly.security.password.PasswordFactory) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) IteratedSaltedPasswordAlgorithmSpec(org.wildfly.security.password.spec.IteratedSaltedPasswordAlgorithmSpec) SaltedPasswordAlgorithmSpec(org.wildfly.security.password.spec.SaltedPasswordAlgorithmSpec) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) EncryptablePasswordSpec(org.wildfly.security.password.spec.EncryptablePasswordSpec) SaltedSimpleDigestPassword(org.wildfly.security.password.interfaces.SaltedSimpleDigestPassword)

Aggregations

SaltedSimpleDigestPassword (org.wildfly.security.password.interfaces.SaltedSimpleDigestPassword)8 PasswordFactory (org.wildfly.security.password.PasswordFactory)6 EncryptablePasswordSpec (org.wildfly.security.password.spec.EncryptablePasswordSpec)6 SaltedPasswordAlgorithmSpec (org.wildfly.security.password.spec.SaltedPasswordAlgorithmSpec)6 IteratedSaltedPasswordAlgorithmSpec (org.wildfly.security.password.spec.IteratedSaltedPasswordAlgorithmSpec)5 Test (org.junit.Test)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 Statement (java.sql.Statement)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 NamePrincipal (org.wildfly.security.auth.principal.NamePrincipal)1 PasswordKeyMapper (org.wildfly.security.auth.realm.jdbc.mapper.PasswordKeyMapper)1 RealmIdentity (org.wildfly.security.auth.server.RealmIdentity)1 PasswordCredential (org.wildfly.security.credential.PasswordCredential)1 PasswordGuessEvidence (org.wildfly.security.evidence.PasswordGuessEvidence)1 SimpleDigestPassword (org.wildfly.security.password.interfaces.SimpleDigestPassword)1 SaltedHashPasswordSpec (org.wildfly.security.password.spec.SaltedHashPasswordSpec)1