use of org.apache.syncope.common.lib.types.CipherAlgorithm in project syncope by apache.
the class EncryptorTest method testEncoder.
/**
* Verify all algorithms.
*/
@Test
public void testEncoder() throws Exception {
for (CipherAlgorithm cipherAlgorithm : CipherAlgorithm.values()) {
final String encPassword = encryptor.encode(password, cipherAlgorithm);
assertNotNull(encPassword);
assertTrue(encryptor.verify(password, cipherAlgorithm, encPassword));
assertFalse(encryptor.verify("pass", cipherAlgorithm, encPassword));
// check that same password encoded with BCRYPT or Salted versions results in different digest
if (cipherAlgorithm.equals(CipherAlgorithm.BCRYPT) || cipherAlgorithm.getAlgorithm().startsWith("S-")) {
final String encSamePassword = encryptor.encode(password, cipherAlgorithm);
assertNotNull(encSamePassword);
assertFalse(encSamePassword.equals(encPassword));
assertTrue(encryptor.verify(password, cipherAlgorithm, encSamePassword));
}
}
}
use of org.apache.syncope.common.lib.types.CipherAlgorithm in project syncope by apache.
the class UserDataBinderImpl method setPassword.
private void setPassword(final User user, final String password, final SyncopeClientCompositeException scce) {
try {
String algorithm = confDAO.find("password.cipher.algorithm", CipherAlgorithm.AES.name());
CipherAlgorithm predefined = CipherAlgorithm.valueOf(algorithm);
user.setPassword(password, predefined);
} catch (IllegalArgumentException e) {
SyncopeClientException invalidCiperAlgorithm = SyncopeClientException.build(ClientExceptionType.NotFound);
invalidCiperAlgorithm.getElements().add(e.getMessage());
scce.addException(invalidCiperAlgorithm);
throw scce;
}
}
use of org.apache.syncope.common.lib.types.CipherAlgorithm in project syncope by apache.
the class MigrationPullActions method after.
@Transactional
@Override
public void after(final ProvisioningProfile<?, ?> profile, final SyncDelta delta, final EntityTO entity, final ProvisioningReport result) throws JobExecutionException {
if (entity instanceof UserTO) {
// handles ciphered password import
CipherAlgorithm cipherAlgorithm = null;
Attribute cipherAlgorithmAttr = delta.getObject().getAttributeByName(CIPHER_ALGORITHM_ATTR);
if (cipherAlgorithmAttr != null && cipherAlgorithmAttr.getValue() != null && !cipherAlgorithmAttr.getValue().isEmpty()) {
cipherAlgorithm = CipherAlgorithm.valueOf(cipherAlgorithmAttr.getValue().get(0).toString());
}
GuardedString passwordValue = AttributeUtil.getPasswordValue(delta.getObject().getAttributes());
if (cipherAlgorithm != null && passwordValue != null) {
User user = userDAO.find(entity.getKey());
LOG.debug("Setting encoded password for {}", user);
user.setEncodedPassword(SecurityUtil.decrypt(passwordValue), cipherAlgorithm);
}
} else if (entity instanceof GroupTO) {
// handles group membership
Attribute membershipsAttr = delta.getObject().getAttributeByName(MEMBERSHIPS_ATTR);
if (membershipsAttr != null && membershipsAttr.getValue() != null && !membershipsAttr.getValue().isEmpty()) {
LOG.debug("Found {} for group {}", MEMBERSHIPS_ATTR, entity.getKey());
for (Object membership : membershipsAttr.getValue()) {
User member = userDAO.findByUsername(membership.toString());
if (member == null) {
LOG.warn("Could not find member {} for group {}", membership, entity.getKey());
} else {
Set<String> memb = memberships.get(member.getKey());
if (memb == null) {
memb = new HashSet<>();
memberships.put(member.getKey(), memb);
}
memb.add(entity.getKey());
}
}
}
} else {
super.after(profile, delta, entity, result);
}
}
Aggregations