Search in sources :

Example 1 with PasswordPolicyDecorator

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

the class ApiLdapExtrasCodecOsgiTest method useBundleClasses.

@Override
protected void useBundleClasses() throws Exception {
    CodecControl<? extends Control> control = ldapApiService.newControl(PasswordPolicy.OID);
    assertNotNull(control);
    assertTrue(control instanceof PasswordPolicyDecorator);
    ExtendedRequest extendedRequest = ldapApiService.newExtendedRequest(StartTlsRequest.EXTENSION_OID, null);
    assertNotNull(extendedRequest);
    assertTrue(extendedRequest instanceof StartTlsRequestDecorator);
}
Also used : PasswordPolicyDecorator(org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyDecorator) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest) StartTlsRequestDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.startTls.StartTlsRequestDecorator)

Example 2 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 testDecodeRespWithTimeBeforeExpiryWarningOnly.

@Test
public void testDecodeRespWithTimeBeforeExpiryWarningOnly() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(7);
    bb.put(new byte[] { 0x30, 0x05, (byte) 0xA0, 0x03, // timeBeforeExpiration
    (byte) 0x80, // timeBeforeExpiration
    0x01, // timeBeforeExpiration
    0x01 });
    bb.flip();
    PasswordPolicyDecorator control = new PasswordPolicyDecorator(codec, true);
    PasswordPolicy passwordPolicy = (PasswordPolicy) control.decode(bb.array());
    assertTrue(passwordPolicy.hasResponse());
    assertEquals(1, passwordPolicy.getResponse().getTimeBeforeExpiration());
    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 3 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 testDecodeRespWithGraceAuthWarningAndError.

@Test
public void testDecodeRespWithGraceAuthWarningAndError() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0xA);
    bb.put(new byte[] { 0x30, 0x08, // warning
    (byte) 0xA0, // warning
    0x03, (byte) 0x81, 0x01, // graceAuthNsRemaining
    0x01, (byte) 0x81, 0x01, // error
    0x01 });
    bb.flip();
    PasswordPolicyDecorator control = new PasswordPolicyDecorator(codec, true);
    PasswordPolicy passwordPolicy = (PasswordPolicy) control.decode(bb.array());
    assertTrue(passwordPolicy.hasResponse());
    assertEquals(1, passwordPolicy.getResponse().getGraceAuthNRemaining());
    assertEquals(1, passwordPolicy.getResponse().getPasswordPolicyError().getValue());
    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 4 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 testDecodeRespWithErrorOnly.

@Test
public void testDecodeRespWithErrorOnly() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(5);
    bb.put(new byte[] { 0x30, 0x03, // error
    (byte) 0x81, // error
    0x01, // error
    0x01 });
    bb.flip();
    PasswordPolicyDecorator control = new PasswordPolicyDecorator(codec, true);
    PasswordPolicy passwordPolicy = (PasswordPolicy) control.decode(bb.array());
    assertTrue(passwordPolicy.hasResponse());
    assertEquals(1, passwordPolicy.getResponse().getPasswordPolicyError().getValue());
    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 5 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 testDecodeRespWithExpiryWarningAndError.

@Test
public void testDecodeRespWithExpiryWarningAndError() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0xA);
    bb.put(new byte[] { 0x30, 0x08, // timeBeforeExpiration
    (byte) 0xA0, // timeBeforeExpiration
    0x03, (byte) 0x80, 0x01, 0x01, (byte) 0x81, 0x01, // ppolicyError
    0x01 });
    bb.flip();
    PasswordPolicyDecorator control = new PasswordPolicyDecorator(codec, true);
    PasswordPolicy passwordPolicy = (PasswordPolicy) control.decode(bb.array());
    assertTrue(passwordPolicy.hasResponse());
    assertEquals(1, passwordPolicy.getResponse().getTimeBeforeExpiration());
    assertEquals(1, passwordPolicy.getResponse().getPasswordPolicyError().getValue());
    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