| | |
| | | /** The attribute type for the description attribute. */ |
| | | private AttributeType descriptionType; |
| | | |
| | | /** The attribute type for the ds-privilege-name attribute. */ |
| | | private AttributeType privNameType; |
| | | |
| | | /** The attribute type for the ds-pwp-password-policy-dn attribute. */ |
| | | private AttributeType pwPolicyDNType; |
| | | |
| | | |
| | | /** |
| | | * Ensures that the Directory Server is running. |
| | |
| | | TestCaseUtils.startServer(); |
| | | |
| | | descriptionType = CoreSchema.getDescriptionAttributeType(); |
| | | pwPolicyDNType = DirectoryServer.getSchema().getAttributeType("ds-pwp-password-policy-dn"); |
| | | privNameType = DirectoryServer.getSchema().getAttributeType("ds-privilege-name"); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that the user-defined virtual attribute provider can be |
| | | * used to grant a privilege to a user. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test |
| | | public void testVirtualPrivilege() |
| | | throws Exception |
| | | private void testSetupVirtualPasswordPolicyDN(String policyDN, String ruleDN) throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | String policyDN = "cn=Test Policy,cn=Password Policies,cn=config"; |
| | | String ruleDN = "cn=User-Defined Test,cn=Virtual Attributes,cn=config"; |
| | | String userDN = "uid=test.user,o=test"; |
| | | |
| | | TestCaseUtils.addEntries( |
| | | "dn: cn=Test Policy,cn=Password Policies,cn=config", |
| | | "dn: " + policyDN, |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-password-policy", |
| | | "cn: Test Policy", |
| | |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-attribute-type: ds-pwp-password-policy-dn", |
| | | "ds-cfg-conflict-behavior: merge-real-and-virtual", |
| | | "ds-cfg-value: " + policyDN, |
| | | "", |
| | | "ds-cfg-value: " + policyDN); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that the user-defined virtual attribute provider can be |
| | | * used to apply a custom password policy for a user. The custom password |
| | | * policy will reject passwords shorter than six characters, whereas the |
| | | * default policy will not. |
| | | */ |
| | | @Test |
| | | public void testVirtualPasswordPolicyDN() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | String policyDN = "cn=Test Policy,cn=Password Policies,cn=config"; |
| | | String ruleDN = "cn=User-Defined Test,cn=Virtual Attributes,cn=config"; |
| | | String userDN = "uid=test.user,o=test"; |
| | | |
| | | testSetupVirtualPasswordPolicyDN(policyDN, ruleDN); |
| | | try |
| | | { |
| | | assertEquals(TestCaseUtils.addEntryOperation( |
| | | "dn: " + userDN, |
| | | "objectClass: top", |
| | | "objectClass: person", |
| | |
| | | "givenName: Test", |
| | | "sn: User", |
| | | "cn: Test User", |
| | | "userPassword: testtest"); |
| | | "userPassword: testtest"), |
| | | ResultCode.SUCCESS); |
| | | |
| | | try |
| | | { |
| | | String path1 = |
| | | TestCaseUtils.createTempFile("dn: " + userDN, |
| | | "changetype: modify", "replace: userPassword", |
| | |
| | | |
| | | assertEquals(LDAPModify.mainModify(args2, false, null, null), 0); |
| | | assertEquals(LDAPModify.mainModify(args1, false, null, null), 0); |
| | | |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that the user-defined virtual attribute provider can be used to apply a custom password |
| | | * policy for a user. The custom password policy will reject passwords shorter than six characters, |
| | | * whereas the default policy will not. This test verifies that adding a user with a short password fails. |
| | | */ |
| | | @Test |
| | | public void testVirtualPasswordPolicyDNForAdd() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | String policyDN = "cn=Test Policy,cn=Password Policies,cn=config"; |
| | | String ruleDN = "cn=User-Defined Test,cn=Virtual Attributes,cn=config"; |
| | | |
| | | testSetupVirtualPasswordPolicyDN(policyDN, ruleDN); |
| | | try { |
| | | assertEquals(TestCaseUtils.addEntryOperation( |
| | | "dn: uid=test.user,o=test", |
| | | "objectClass: top", |
| | | "objectClass: person", |
| | | "objectClass: organizationalPerson", |
| | | "objectClass: inetOrgPerson", |
| | | "uid: test.user", |
| | | "givenName: Test", |
| | | "sn: User", |
| | | "cn: Test User", |
| | | "userPassword: test" |
| | | ), ResultCode.CONSTRAINT_VIOLATION); |
| | | } |
| | | finally { |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | DeleteOperation deleteOperation = conn.processDelete(DN.valueOf(ruleDN)); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | deleteOperation = conn.processDelete(DN.valueOf(policyDN)); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that the user-defined virtual attribute provider can be |
| | | * used to apply a custom password policy for a user. The custom password |
| | | * policy will reject passwords shorter than six characters, whereas the |
| | | * default policy will not. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | * used to grant a privilege to a user. |
| | | */ |
| | | @Test |
| | | public void testVirtualPasswordPolicyDN() |
| | | throws Exception |
| | | public void testVirtualPrivilege() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | |
| | | "cn: Test User", |
| | | "userPassword: password"); |
| | | |
| | | |
| | | try |
| | | { |
| | | String path1 = |
| | |
| | | |
| | | assertEquals(LDAPModify.mainModify(args2, false, null, null), 0); |
| | | assertEquals(LDAPModify.mainModify(args1, false, null, null), 0); |
| | | |
| | | } |
| | | finally |
| | | { |