Search in sources :

Example 16 with PasswordPolicy

use of org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy in project syncope by apache.

the class JPAUserDAO method getPasswordPolicies.

private List<PasswordPolicy> getPasswordPolicies(final User user) {
    List<PasswordPolicy> policies = new ArrayList<>();
    PasswordPolicy policy;
    // add resource policies
    for (ExternalResource resource : findAllResources(user)) {
        policy = resource.getPasswordPolicy();
        if (policy != null) {
            policies.add(policy);
        }
    }
    // add realm policies
    for (Realm realm : realmDAO().findAncestors(user.getRealm())) {
        policy = realm.getPasswordPolicy();
        if (policy != null) {
            policies.add(policy);
        }
    }
    return policies;
}
Also used : PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ArrayList(java.util.ArrayList) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Example 17 with PasswordPolicy

use of org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy in project syncope by apache.

the class PolicyTest method update.

@Test
public void update() {
    PasswordPolicy policy = policyDAO.find("ce93fcda-dc3a-4369-a7b0-a6108c261c85");
    assertNotNull(policy);
    assertEquals(1, policy.getRules().size());
    DefaultPasswordRuleConf ruleConf = new DefaultPasswordRuleConf();
    ruleConf.setMaxLength(8);
    ruleConf.setMinLength(6);
    Implementation rule = entityFactory.newEntity(Implementation.class);
    rule.setKey("PasswordRule" + UUID.randomUUID().toString());
    rule.setEngine(ImplementationEngine.JAVA);
    rule.setType(ImplementationType.PASSWORD_RULE);
    rule.setBody(POJOHelper.serialize(ruleConf));
    rule = implementationDAO.save(rule);
    policy.add(rule);
    policy = policyDAO.save(policy);
    assertNotNull(policy);
    rule = policy.getRules().get(1);
    DefaultPasswordRuleConf actual = POJOHelper.deserialize(rule.getBody(), DefaultPasswordRuleConf.class);
    assertEquals(actual.getMaxLength(), 8);
    assertEquals(actual.getMinLength(), 6);
}
Also used : DefaultPasswordRuleConf(org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)17 ArrayList (java.util.ArrayList)8 DefaultPasswordRuleConf (org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf)7 AccountPolicy (org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy)7 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)7 Test (org.junit.jupiter.api.Test)7 Implementation (org.apache.syncope.core.persistence.api.entity.Implementation)6 Realm (org.apache.syncope.core.persistence.api.entity.Realm)6 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3 Policy (org.apache.syncope.core.persistence.api.entity.policy.Policy)3 PullPolicy (org.apache.syncope.core.persistence.api.entity.policy.PullPolicy)3 InvalidPasswordRuleConf (org.apache.syncope.core.provisioning.api.utils.policy.InvalidPasswordRuleConf)3 List (java.util.List)2 StringUtils (org.apache.commons.lang3.StringUtils)2 AccountPolicyTO (org.apache.syncope.common.lib.policy.AccountPolicyTO)2 PasswordPolicyTO (org.apache.syncope.common.lib.policy.PasswordPolicyTO)2 PullPolicyTO (org.apache.syncope.common.lib.policy.PullPolicyTO)2 ExternalResourceDAO (org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO)2 OrgUnit (org.apache.syncope.core.persistence.api.entity.resource.OrgUnit)2 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)2