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);
}
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)));
}
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)));
}
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;
}
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);
});
}
Aggregations