Search in sources :

Example 6 with PasswordPolicyDecorator

use of org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyDecorator in project directory-ldap-api by apache.

the class PasswordPolicyTest method testDecodeRespWithGraceAuthWarningOnly.

@Test
public void testDecodeRespWithGraceAuthWarningOnly() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(7);
    bb.put(new byte[] { 0x30, 0x05, (byte) 0xA0, 0x03, // graceAuthNsRemaining
    (byte) 0x81, // graceAuthNsRemaining
    0x01, // graceAuthNsRemaining
    0x01 });
    bb.flip();
    PasswordPolicyDecorator control = new PasswordPolicyDecorator(codec, true);
    PasswordPolicy passwordPolicy = (PasswordPolicy) control.decode(bb.array());
    assertTrue(passwordPolicy.hasResponse());
    assertEquals(1, passwordPolicy.getResponse().getGraceAuthNRemaining());
    ByteBuffer encoded = ((PasswordPolicyDecorator) passwordPolicy).encode(ByteBuffer.allocate(((PasswordPolicyDecorator) passwordPolicy).computeLength()));
    assertEquals(Strings.dumpBytes(bb.array()), Strings.dumpBytes(encoded.array()));
}
Also used : PasswordPolicyDecorator(org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyDecorator) ByteBuffer(java.nio.ByteBuffer) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest) Test(org.junit.Test)

Example 7 with PasswordPolicyDecorator

use of org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyDecorator in project directory-ldap-api by apache.

the class PasswordPolicyTest method testDecodeRespWithoutWarningAndError.

@Test
public void testDecodeRespWithoutWarningAndError() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(2);
    bb.put(new byte[] { 0x30, 0x00 });
    bb.flip();
    PasswordPolicyDecorator control = new PasswordPolicyDecorator(codec, true);
    PasswordPolicy passwordPolicy = (PasswordPolicy) control.decode(bb.array());
    assertNotNull(passwordPolicy);
    assertTrue(passwordPolicy.hasResponse());
    ByteBuffer encoded = ((PasswordPolicyDecorator) passwordPolicy).encode(ByteBuffer.allocate(((PasswordPolicyDecorator) passwordPolicy).computeLength()));
    assertEquals(Strings.dumpBytes(bb.array()), Strings.dumpBytes(encoded.array()));
}
Also used : PasswordPolicyDecorator(org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyDecorator) ByteBuffer(java.nio.ByteBuffer) AbstractCodecServiceTest(org.apache.directory.api.ldap.extras.AbstractCodecServiceTest) Test(org.junit.Test)

Aggregations

PasswordPolicyDecorator (org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyDecorator)7 ByteBuffer (java.nio.ByteBuffer)6 AbstractCodecServiceTest (org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)6 Test (org.junit.Test)6 StartTlsRequestDecorator (org.apache.directory.api.ldap.extras.extended.ads_impl.startTls.StartTlsRequestDecorator)1 ExtendedRequest (org.apache.directory.api.ldap.model.message.ExtendedRequest)1