Search in sources :

Example 1 with ProxiedAuthz

use of org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz in project directory-ldap-api by apache.

the class ProxiedAuthzControlTest method testEncodeProxiedDnAuthzControl.

/**
 * Test encoding of a ProxiedAuthzControl.
 */
@Test
public void testEncodeProxiedDnAuthzControl() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x14);
    bb.put(new byte[] { // ProxiedAuthzNotification ::= dn:dc=example,dc=com
    'd', 'n', ':', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm' });
    String expected = Strings.dumpBytes(bb.array());
    bb.flip();
    ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator(codec);
    ProxiedAuthz proxiedAuthz = (ProxiedAuthz) decorator.getDecorated();
    proxiedAuthz.setAuthzId("dn:dc=example,dc=com");
    bb = decorator.encode(ByteBuffer.allocate(decorator.computeLength()));
    String decoded = Strings.dumpBytes(bb.array());
    assertEquals(expected, decoded);
}
Also used : ProxiedAuthz(org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz) ByteBuffer(java.nio.ByteBuffer) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest) Test(org.junit.Test)

Example 2 with ProxiedAuthz

use of org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz in project directory-ldap-api by apache.

the class ProxiedAuthzControlTest method testEncodeProxiedUserAuthzControl.

/**
 * Test encoding of a ProxiedAuthzControl.
 */
@Test
public void testEncodeProxiedUserAuthzControl() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0C);
    bb.put(new byte[] { // ProxiedAuthzNotification ::= u:elecharny
    'u', ':', 'e', 'l', (byte) 0xc3, (byte) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' });
    String expected = Strings.dumpBytes(bb.array());
    bb.flip();
    ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator(codec);
    ProxiedAuthz proxiedAuthz = (ProxiedAuthz) decorator.getDecorated();
    proxiedAuthz.setAuthzId("u:el\u00e9charny");
    bb = decorator.encode(ByteBuffer.allocate(decorator.computeLength()));
    String decoded = Strings.dumpBytes(bb.array());
    assertEquals(expected, decoded);
}
Also used : ProxiedAuthz(org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz) ByteBuffer(java.nio.ByteBuffer) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest) Test(org.junit.Test)

Example 3 with ProxiedAuthz

use of org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz in project directory-ldap-api by apache.

the class ProxiedAuthzControlTest method testDecodeProxiedAuthzControlUSuccess.

/**
 * Test the decoding of a ProxiedAuthzControl with a normal user
 */
@Test
public void testDecodeProxiedAuthzControlUSuccess() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0C);
    bb.put(new byte[] { // ProxiedAuthzNotification ::= u:elecharny
    'u', ':', 'e', 'l', (byte) 0xc3, (byte) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' });
    bb.flip();
    ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator(codec);
    ProxiedAuthz proxiedAuthz = (ProxiedAuthz) decorator.decode(bb.array());
    assertEquals("u:el\u00e9charny", proxiedAuthz.getAuthzId());
}
Also used : ProxiedAuthz(org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz) ByteBuffer(java.nio.ByteBuffer) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest) Test(org.junit.Test)

Example 4 with ProxiedAuthz

use of org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz in project directory-ldap-api by apache.

the class ProxiedAuthzControlTest method testEncodeProxiedAnonymousAuthzControl.

/**
 * Test encoding of a ProxiedAuthzControl.
 */
@Test
public void testEncodeProxiedAnonymousAuthzControl() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x00);
    bb.put(new byte[] {// ProxiedAuthzNotification ::= anonymous
    });
    String expected = Strings.dumpBytes(bb.array());
    bb.flip();
    ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator(codec);
    ProxiedAuthz proxiedAuthz = (ProxiedAuthz) decorator.getDecorated();
    proxiedAuthz.setAuthzId("");
    bb = decorator.encode(ByteBuffer.allocate(decorator.computeLength()));
    String decoded = Strings.dumpBytes(bb.array());
    assertEquals(expected, decoded);
}
Also used : ProxiedAuthz(org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz) ByteBuffer(java.nio.ByteBuffer) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest) Test(org.junit.Test)

Example 5 with ProxiedAuthz

use of org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz in project directory-ldap-api by apache.

the class ProxiedAuthzControlTest method testDecodeProxiedAuthzControlAnonymousSuccess.

/**
 * Test the decoding of a ProxiedAuthzControl with a anonymous user
 */
@Test
public void testDecodeProxiedAuthzControlAnonymousSuccess() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x00);
    bb.put(new byte[] {// ProxiedAuthzNotification ::= anonymous
    });
    bb.flip();
    ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator(codec);
    ProxiedAuthz proxiedAuthz = (ProxiedAuthz) decorator.decode(bb.array());
    assertEquals("", proxiedAuthz.getAuthzId());
}
Also used : ProxiedAuthz(org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz) ByteBuffer(java.nio.ByteBuffer) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest) Test(org.junit.Test)

Aggregations

ProxiedAuthz (org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz)7 ByteBuffer (java.nio.ByteBuffer)6 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)6 Test (org.junit.Test)6 CompareRequest (org.apache.directory.api.ldap.model.message.CompareRequest)1 CompareRequestImpl (org.apache.directory.api.ldap.model.message.CompareRequestImpl)1 CompareResponse (org.apache.directory.api.ldap.model.message.CompareResponse)1 ProxiedAuthzImpl (org.apache.directory.api.ldap.model.message.controls.ProxiedAuthzImpl)1 Dn (org.apache.directory.api.ldap.model.name.Dn)1