Search in sources :

Example 6 with DefaultPasswordRuleConf

use of org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf in project syncope by apache.

the class DefaultPasswordGenerator method generate.

@Override
public String generate(final List<PasswordPolicy> policies) throws InvalidPasswordRuleConf {
    List<DefaultPasswordRuleConf> defaultRuleConfs = new ArrayList<>();
    policies.stream().forEach(policy -> policy.getRules().forEach(impl -> {
        try {
            Optional<PasswordRule> rule = ImplementationManager.buildPasswordRule(impl);
            if (rule.isPresent() && rule.get().getConf() instanceof DefaultPasswordRuleConf) {
                defaultRuleConfs.add((DefaultPasswordRuleConf) rule.get().getConf());
            }
        } catch (Exception e) {
            LOG.error("Invalid {}, ignoring...", impl, e);
        }
    }));
    DefaultPasswordRuleConf ruleConf = merge(defaultRuleConfs);
    check(ruleConf);
    return generate(ruleConf);
}
Also used : Logger(org.slf4j.Logger) PolicyPattern(org.apache.syncope.core.provisioning.api.utils.policy.PolicyPattern) LoggerFactory(org.slf4j.LoggerFactory) InvalidPasswordRuleConf(org.apache.syncope.core.provisioning.api.utils.policy.InvalidPasswordRuleConf) StringUtils(org.apache.commons.lang3.StringUtils) PasswordRule(org.apache.syncope.core.persistence.api.dao.PasswordRule) ImplementationManager(org.apache.syncope.core.spring.ImplementationManager) ArrayList(java.util.ArrayList) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) DefaultPasswordRuleConf(org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf) Optional(java.util.Optional) Transactional(org.springframework.transaction.annotation.Transactional) DefaultPasswordRuleConf(org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf) Optional(java.util.Optional) ArrayList(java.util.ArrayList)

Example 7 with DefaultPasswordRuleConf

use of org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf in project syncope by apache.

the class PasswordGeneratorTest method startEndWithDigit.

@Test
public void startEndWithDigit() throws InvalidPasswordRuleConf {
    DefaultPasswordRuleConf pwdRuleConf1 = createBaseDefaultPasswordRuleConf();
    pwdRuleConf1.setMustStartWithDigit(true);
    TestImplementation passwordRule1 = new TestImplementation();
    passwordRule1.setBody(POJOHelper.serialize(pwdRuleConf1));
    TestPasswordPolicy policy1 = new TestPasswordPolicy();
    policy1.add(passwordRule1);
    DefaultPasswordRuleConf pwdRuleConf2 = createBaseDefaultPasswordRuleConf();
    pwdRuleConf2.setMustEndWithDigit(true);
    TestImplementation passwordRule2 = new TestImplementation();
    passwordRule2.setBody(POJOHelper.serialize(pwdRuleConf2));
    TestPasswordPolicy policy2 = new TestPasswordPolicy();
    policy2.add(passwordRule2);
    List<PasswordPolicy> policies = new ArrayList<>();
    policies.add(policy1);
    policies.add(policy2);
    String generatedPassword = passwordGenerator.generate(policies);
    assertTrue(Character.isDigit(generatedPassword.charAt(0)));
    assertTrue(Character.isDigit(generatedPassword.charAt(generatedPassword.length() - 1)));
}
Also used : DefaultPasswordRuleConf(org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 8 with DefaultPasswordRuleConf

use of org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf in project syncope by apache.

the class PasswordGeneratorTest method passwordWithNonAlpha.

@Test
public void passwordWithNonAlpha() throws InvalidPasswordRuleConf {
    DefaultPasswordRuleConf pwdRuleConf1 = createBaseDefaultPasswordRuleConf();
    pwdRuleConf1.setNonAlphanumericRequired(true);
    TestImplementation passwordRule1 = new TestImplementation();
    passwordRule1.setBody(POJOHelper.serialize(pwdRuleConf1));
    TestPasswordPolicy policy1 = new TestPasswordPolicy();
    policy1.add(passwordRule1);
    DefaultPasswordRuleConf pwdRuleConf2 = createBaseDefaultPasswordRuleConf();
    pwdRuleConf2.setMustEndWithAlpha(true);
    TestImplementation passwordRule2 = new TestImplementation();
    passwordRule2.setBody(POJOHelper.serialize(pwdRuleConf2));
    TestPasswordPolicy policy2 = new TestPasswordPolicy();
    policy2.add(passwordRule2);
    List<PasswordPolicy> policies = new ArrayList<>();
    policies.add(policy1);
    policies.add(policy2);
    String generatedPassword = passwordGenerator.generate(policies);
    assertTrue(PolicyPattern.NON_ALPHANUMERIC.matcher(generatedPassword).matches());
    assertTrue(Character.isLetter(generatedPassword.charAt(generatedPassword.length() - 1)));
}
Also used : DefaultPasswordRuleConf(org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 9 with DefaultPasswordRuleConf

use of org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf in project syncope by apache.

the class PasswordGeneratorTest method createBaseDefaultPasswordRuleConf.

private DefaultPasswordRuleConf createBaseDefaultPasswordRuleConf() {
    DefaultPasswordRuleConf baseDefaultPasswordRuleConf = new DefaultPasswordRuleConf();
    baseDefaultPasswordRuleConf.setAlphanumericRequired(false);
    baseDefaultPasswordRuleConf.setDigitRequired(false);
    baseDefaultPasswordRuleConf.setLowercaseRequired(false);
    baseDefaultPasswordRuleConf.setMaxLength(1000);
    baseDefaultPasswordRuleConf.setMinLength(8);
    baseDefaultPasswordRuleConf.setMustEndWithAlpha(false);
    baseDefaultPasswordRuleConf.setMustEndWithDigit(false);
    baseDefaultPasswordRuleConf.setMustEndWithNonAlpha(false);
    baseDefaultPasswordRuleConf.setMustStartWithAlpha(false);
    baseDefaultPasswordRuleConf.setMustStartWithDigit(false);
    baseDefaultPasswordRuleConf.setMustStartWithNonAlpha(false);
    baseDefaultPasswordRuleConf.setMustntEndWithAlpha(false);
    baseDefaultPasswordRuleConf.setMustntEndWithDigit(false);
    baseDefaultPasswordRuleConf.setMustntEndWithNonAlpha(false);
    baseDefaultPasswordRuleConf.setMustntStartWithAlpha(false);
    baseDefaultPasswordRuleConf.setMustntStartWithDigit(false);
    baseDefaultPasswordRuleConf.setMustntStartWithNonAlpha(false);
    baseDefaultPasswordRuleConf.setNonAlphanumericRequired(false);
    baseDefaultPasswordRuleConf.setUppercaseRequired(false);
    return baseDefaultPasswordRuleConf;
}
Also used : DefaultPasswordRuleConf(org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf)

Example 10 with DefaultPasswordRuleConf

use of org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf in project syncope by apache.

the class PasswordGeneratorTest method incopatiblePolicies.

@Test
public void incopatiblePolicies() {
    assertThrows(InvalidPasswordRuleConf.class, () -> {
        DefaultPasswordRuleConf pwdRuleConf1 = createBaseDefaultPasswordRuleConf();
        pwdRuleConf1.setMinLength(12);
        TestImplementation passwordRule1 = new TestImplementation();
        passwordRule1.setBody(POJOHelper.serialize(pwdRuleConf1));
        TestPasswordPolicy policy1 = new TestPasswordPolicy();
        policy1.add(passwordRule1);
        DefaultPasswordRuleConf pwdRuleConf2 = createBaseDefaultPasswordRuleConf();
        pwdRuleConf2.setMaxLength(10);
        TestImplementation passwordRule2 = new TestImplementation();
        passwordRule2.setBody(POJOHelper.serialize(pwdRuleConf2));
        TestPasswordPolicy policy2 = new TestPasswordPolicy();
        policy2.add(passwordRule2);
        List<PasswordPolicy> policies = new ArrayList<>();
        policies.add(policy1);
        policies.add(policy2);
        passwordGenerator.generate(policies);
    });
}
Also used : DefaultPasswordRuleConf(org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultPasswordRuleConf (org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf)11 Test (org.junit.jupiter.api.Test)8 PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)7 ArrayList (java.util.ArrayList)5 PasswordPolicyTO (org.apache.syncope.common.lib.policy.PasswordPolicyTO)2 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)2 InvalidPasswordRuleConf (org.apache.syncope.core.provisioning.api.utils.policy.InvalidPasswordRuleConf)2 List (java.util.List)1 Optional (java.util.Optional)1 Response (javax.ws.rs.core.Response)1 StringUtils (org.apache.commons.lang3.StringUtils)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 RealmTO (org.apache.syncope.common.lib.to.RealmTO)1 UserTO (org.apache.syncope.common.lib.to.UserTO)1 PasswordRule (org.apache.syncope.core.persistence.api.dao.PasswordRule)1 Implementation (org.apache.syncope.core.persistence.api.entity.Implementation)1 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)1 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)1 PolicyPattern (org.apache.syncope.core.provisioning.api.utils.policy.PolicyPattern)1 ImplementationManager (org.apache.syncope.core.spring.ImplementationManager)1