use of org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf in project syncope by apache.
the class DefaultPasswordGenerator method merge.
private DefaultPasswordRuleConf merge(final List<DefaultPasswordRuleConf> defaultRuleConfs) {
DefaultPasswordRuleConf result = new DefaultPasswordRuleConf();
result.setMinLength(VERY_MIN_LENGTH);
result.setMaxLength(VERY_MAX_LENGTH);
defaultRuleConfs.forEach(ruleConf -> {
if (ruleConf.getMinLength() > result.getMinLength()) {
result.setMinLength(ruleConf.getMinLength());
}
if ((ruleConf.getMaxLength() != 0) && ((ruleConf.getMaxLength() < result.getMaxLength()))) {
result.setMaxLength(ruleConf.getMaxLength());
}
result.getPrefixesNotPermitted().addAll(ruleConf.getPrefixesNotPermitted());
result.getSuffixesNotPermitted().addAll(ruleConf.getSuffixesNotPermitted());
if (!result.isNonAlphanumericRequired()) {
result.setNonAlphanumericRequired(ruleConf.isNonAlphanumericRequired());
}
if (!result.isAlphanumericRequired()) {
result.setAlphanumericRequired(ruleConf.isAlphanumericRequired());
}
if (!result.isDigitRequired()) {
result.setDigitRequired(ruleConf.isDigitRequired());
}
if (!result.isLowercaseRequired()) {
result.setLowercaseRequired(ruleConf.isLowercaseRequired());
}
if (!result.isUppercaseRequired()) {
result.setUppercaseRequired(ruleConf.isUppercaseRequired());
}
if (!result.isMustStartWithDigit()) {
result.setMustStartWithDigit(ruleConf.isMustStartWithDigit());
}
if (!result.isMustntStartWithDigit()) {
result.setMustntStartWithDigit(ruleConf.isMustntStartWithDigit());
}
if (!result.isMustEndWithDigit()) {
result.setMustEndWithDigit(ruleConf.isMustEndWithDigit());
}
if (result.isMustntEndWithDigit()) {
result.setMustntEndWithDigit(ruleConf.isMustntEndWithDigit());
}
if (!result.isMustStartWithAlpha()) {
result.setMustStartWithAlpha(ruleConf.isMustStartWithAlpha());
}
if (!result.isMustntStartWithAlpha()) {
result.setMustntStartWithAlpha(ruleConf.isMustntStartWithAlpha());
}
if (!result.isMustStartWithNonAlpha()) {
result.setMustStartWithNonAlpha(ruleConf.isMustStartWithNonAlpha());
}
if (!result.isMustntStartWithNonAlpha()) {
result.setMustntStartWithNonAlpha(ruleConf.isMustntStartWithNonAlpha());
}
if (!result.isMustEndWithNonAlpha()) {
result.setMustEndWithNonAlpha(ruleConf.isMustEndWithNonAlpha());
}
if (!result.isMustntEndWithNonAlpha()) {
result.setMustntEndWithNonAlpha(ruleConf.isMustntEndWithNonAlpha());
}
if (!result.isMustEndWithAlpha()) {
result.setMustEndWithAlpha(ruleConf.isMustEndWithAlpha());
}
if (!result.isMustntEndWithAlpha()) {
result.setMustntEndWithAlpha(ruleConf.isMustntEndWithAlpha());
}
if (!result.isUsernameAllowed()) {
result.setUsernameAllowed(ruleConf.isUsernameAllowed());
}
});
if (result.getMinLength() == 0) {
result.setMinLength(result.getMaxLength() < MIN_LENGTH_IF_ZERO ? result.getMaxLength() : MIN_LENGTH_IF_ZERO);
}
return result;
}
use of org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf in project syncope by apache.
the class PasswordGeneratorTest method issueSYNCOPE678.
@Test
public void issueSYNCOPE678() {
String password = null;
try {
password = passwordGenerator.generate(Collections.<PasswordPolicy>emptyList());
} catch (InvalidPasswordRuleConf e) {
fail(e.getMessage());
}
assertNotNull(password);
DefaultPasswordRuleConf pwdRuleConf1 = createBaseDefaultPasswordRuleConf();
pwdRuleConf1.setMinLength(0);
TestImplementation passwordRule1 = new TestImplementation();
passwordRule1.setBody(POJOHelper.serialize(pwdRuleConf1));
TestPasswordPolicy policy1 = new TestPasswordPolicy();
password = null;
try {
password = passwordGenerator.generate(Collections.<PasswordPolicy>singletonList(policy1));
} catch (InvalidPasswordRuleConf e) {
fail(e.getMessage());
}
assertNotNull(password);
}
use of org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf in project syncope by apache.
the class PasswordGeneratorTest method startWithDigitAndWithAlpha.
@Test
public void startWithDigitAndWithAlpha() 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.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(Character.isDigit(generatedPassword.charAt(0)));
assertTrue(Character.isLetter(generatedPassword.charAt(generatedPassword.length() - 1)));
}
use of org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf in project syncope by apache.
the class UserIssuesITCase method issueSYNCOPE626.
@Test
public void issueSYNCOPE626() {
DefaultPasswordRuleConf ruleConf = new DefaultPasswordRuleConf();
ruleConf.setUsernameAllowed(false);
ImplementationTO rule = new ImplementationTO();
rule.setKey("DefaultPasswordRuleConf" + getUUIDString());
rule.setEngine(ImplementationEngine.JAVA);
rule.setType(ImplementationType.PASSWORD_RULE);
rule.setBody(POJOHelper.serialize(ruleConf));
Response response = implementationService.create(rule);
rule.setKey(response.getHeaderString(RESTHeaders.RESOURCE_KEY));
PasswordPolicyTO passwordPolicy = new PasswordPolicyTO();
passwordPolicy.setDescription("Password Policy for SYNCOPE-626");
passwordPolicy.getRules().add(rule.getKey());
passwordPolicy = createPolicy(PolicyType.PASSWORD, passwordPolicy);
assertNotNull(passwordPolicy);
RealmTO realm = realmService.list("/even/two").get(0);
String oldPasswordPolicy = realm.getPasswordPolicy();
realm.setPasswordPolicy(passwordPolicy.getKey());
realmService.update(realm);
try {
UserTO user = UserITCase.getUniqueSampleTO("syncope626@syncope.apache.org");
user.setRealm(realm.getFullPath());
user.setPassword(user.getUsername());
try {
createUser(user);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidUser, e.getType());
assertTrue(e.getElements().iterator().next().startsWith("InvalidPassword"));
}
user.setPassword("password123");
user = createUser(user).getEntity();
assertNotNull(user);
} finally {
realm.setPasswordPolicy(oldPasswordPolicy);
realmService.update(realm);
policyService.delete(PolicyType.PASSWORD, passwordPolicy.getKey());
}
}
use of org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf in project syncope by apache.
the class PolicyITCase method update.
@Test
public void update() {
PasswordPolicyTO globalPolicy = policyService.read(PolicyType.PASSWORD, "ce93fcda-dc3a-4369-a7b0-a6108c261c85");
PasswordPolicyTO policy = SerializationUtils.clone(globalPolicy);
policy.setDescription("A simple password policy");
// create a new password policy using the former as a template
policy = createPolicy(PolicyType.PASSWORD, policy);
assertNotNull(policy);
assertNotEquals("ce93fcda-dc3a-4369-a7b0-a6108c261c85", policy.getKey());
ImplementationTO rule = implementationService.read(ImplementationType.PASSWORD_RULE, policy.getRules().get(0));
assertNotNull(rule);
DefaultPasswordRuleConf ruleConf = POJOHelper.deserialize(rule.getBody(), DefaultPasswordRuleConf.class);
ruleConf.setMaxLength(22);
rule.setBody(POJOHelper.serialize(ruleConf));
// update new password policy
policyService.update(PolicyType.PASSWORD, policy);
policy = policyService.read(PolicyType.PASSWORD, policy.getKey());
assertNotNull(policy);
ruleConf = POJOHelper.deserialize(rule.getBody(), DefaultPasswordRuleConf.class);
assertEquals(22, ruleConf.getMaxLength());
assertEquals(8, ruleConf.getMinLength());
}
Aggregations