Search in sources :

Example 1 with CipherAlgorithm

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));
        }
    }
}
Also used : CipherAlgorithm(org.apache.syncope.common.lib.types.CipherAlgorithm) Test(org.junit.jupiter.api.Test)

Example 2 with CipherAlgorithm

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;
    }
}
Also used : CipherAlgorithm(org.apache.syncope.common.lib.types.CipherAlgorithm) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException)

Example 3 with CipherAlgorithm

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);
    }
}
Also used : CipherAlgorithm(org.apache.syncope.common.lib.types.CipherAlgorithm) User(org.apache.syncope.core.persistence.api.entity.user.User) HashSet(java.util.HashSet) Set(java.util.Set) Attribute(org.identityconnectors.framework.common.objects.Attribute) UserTO(org.apache.syncope.common.lib.to.UserTO) GuardedString(org.identityconnectors.common.security.GuardedString) GroupTO(org.apache.syncope.common.lib.to.GroupTO) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CipherAlgorithm (org.apache.syncope.common.lib.types.CipherAlgorithm)3 HashSet (java.util.HashSet)1 Set (java.util.Set)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 GroupTO (org.apache.syncope.common.lib.to.GroupTO)1 UserTO (org.apache.syncope.common.lib.to.UserTO)1 User (org.apache.syncope.core.persistence.api.entity.user.User)1 GuardedString (org.identityconnectors.common.security.GuardedString)1 Attribute (org.identityconnectors.framework.common.objects.Attribute)1 Test (org.junit.jupiter.api.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1