Search in sources :

Example 1 with PasswordModifyResponse

use of org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse in project directory-ldap-api by apache.

the class PasswordModifyResponseTest method testDecodePasswordModifyResponseEmpty.

/**
 * Test the decoding of a PasswordModifyResponse with nothing in it
 */
@Test
public void testDecodePasswordModifyResponseEmpty() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x02);
    bb.put(new byte[] { // PasswordModifyResponse ::= SEQUENCE {
    0x30, // PasswordModifyResponse ::= SEQUENCE {
    0x00 });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    PasswordModifyResponseContainer container = new PasswordModifyResponseContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    PasswordModifyResponse pwdModifyResponse = container.getPwdModifyResponse();
    assertNull(pwdModifyResponse.getGenPassword());
    // Check the length
    assertEquals(0x02, ((PasswordModifyResponseDecorator) pwdModifyResponse).computeLengthInternal());
    // Check the encoding
    ByteBuffer bb1 = ((PasswordModifyResponseDecorator) pwdModifyResponse).encodeInternal();
    String encodedPdu = Strings.dumpBytes(bb1.array());
    assertEquals(encodedPdu, decodedPdu);
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) PasswordModifyResponseContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseContainer) PasswordModifyResponse(org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse) PasswordModifyResponseDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with PasswordModifyResponse

use of org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse in project directory-ldap-api by apache.

the class PasswordModifyResponseTest method testDecodePasswordModifyResponseUserIdentityNull.

/**
 * Test the decoding of a PasswordModifyResponse with an empty genPassword
 */
@Test
public void testDecodePasswordModifyResponseUserIdentityNull() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x04);
    bb.put(new byte[] { // PasswordModifyResponse ::= SEQUENCE {
    0x30, // PasswordModifyResponse ::= SEQUENCE {
    0x02, (byte) 0x80, // genPassword    [0]  OCTET STRING OPTIONAL
    0x00 });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    PasswordModifyResponseContainer container = new PasswordModifyResponseContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    PasswordModifyResponse pwdModifyResponse = container.getPwdModifyResponse();
    assertNotNull(pwdModifyResponse.getGenPassword());
    assertEquals(0, pwdModifyResponse.getGenPassword().length);
    // Check the length
    assertEquals(0x04, ((PasswordModifyResponseDecorator) pwdModifyResponse).computeLengthInternal());
    // Check the encoding
    ByteBuffer bb1 = ((PasswordModifyResponseDecorator) pwdModifyResponse).encodeInternal();
    String encodedPdu = Strings.dumpBytes(bb1.array());
    assertEquals(encodedPdu, decodedPdu);
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) PasswordModifyResponseContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseContainer) PasswordModifyResponse(org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse) PasswordModifyResponseDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with PasswordModifyResponse

use of org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse in project directory-ldap-api by apache.

the class PasswordModifyResponseTest method testDecodePasswordModifyResponseUserIdentityValue.

/**
 * Test the decoding of a PasswordModifyResponse with a genPassword
 */
@Test
public void testDecodePasswordModifyResponseUserIdentityValue() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x08);
    bb.put(new byte[] { // PasswordModifyResponse ::= SEQUENCE {
    0x30, // PasswordModifyResponse ::= SEQUENCE {
    0x06, (byte) 0x80, // genPassword    [0]  OCTET STRING OPTIONAL
    0x04, 'a', 'b', 'c', 'd' });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    PasswordModifyResponseContainer container = new PasswordModifyResponseContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    PasswordModifyResponse pwdModifyResponse = container.getPwdModifyResponse();
    assertNotNull(pwdModifyResponse.getGenPassword());
    assertEquals("abcd", Strings.utf8ToString(pwdModifyResponse.getGenPassword()));
    // Check the length
    assertEquals(0x08, ((PasswordModifyResponseDecorator) pwdModifyResponse).computeLengthInternal());
    // Check the encoding
    ByteBuffer bb1 = ((PasswordModifyResponseDecorator) pwdModifyResponse).encodeInternal();
    String encodedPdu = Strings.dumpBytes(bb1.array());
    assertEquals(encodedPdu, decodedPdu);
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) PasswordModifyResponseContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseContainer) PasswordModifyResponse(org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse) PasswordModifyResponseDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with PasswordModifyResponse

use of org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse in project directory-ldap-api by apache.

the class PasswordModifyFactory method decorate.

/**
 * {@inheritDoc}
 */
@Override
public PasswordModifyResponseDecorator decorate(ExtendedResponse decoratedResponse) {
    if (decoratedResponse instanceof PasswordModifyResponseDecorator) {
        return (PasswordModifyResponseDecorator) decoratedResponse;
    }
    if (decoratedResponse instanceof PasswordModifyResponse) {
        return new PasswordModifyResponseDecorator(codec, (PasswordModifyResponse) decoratedResponse);
    }
    // It's an opaque extended operation
    @SuppressWarnings("unchecked") ExtendedResponseDecorator<ExtendedResponse> response = (ExtendedResponseDecorator<ExtendedResponse>) decoratedResponse;
    // Decode the response, as it's an opaque operation
    Asn1Decoder decoder = new Asn1Decoder();
    byte[] value = response.getResponseValue();
    PasswordModifyResponseContainer container = new PasswordModifyResponseContainer();
    PasswordModifyResponse pwdModifyResponse;
    if (value != null) {
        ByteBuffer buffer = ByteBuffer.wrap(value);
        try {
            decoder.decode(buffer, container);
            pwdModifyResponse = container.getPwdModifyResponse();
            // Now, update the created response with what we got from the extendedResponse
            pwdModifyResponse.getLdapResult().setResultCode(response.getLdapResult().getResultCode());
            pwdModifyResponse.getLdapResult().setDiagnosticMessage(response.getLdapResult().getDiagnosticMessage());
            pwdModifyResponse.getLdapResult().setMatchedDn(response.getLdapResult().getMatchedDn());
            pwdModifyResponse.getLdapResult().setReferral(response.getLdapResult().getReferral());
        } catch (DecoderException de) {
            StringWriter sw = new StringWriter();
            de.printStackTrace(new PrintWriter(sw));
            String stackTrace = sw.toString();
            // Error while decoding the value.
            pwdModifyResponse = new PasswordModifyResponseImpl(decoratedResponse.getMessageId(), ResultCodeEnum.OPERATIONS_ERROR, stackTrace);
        }
    } else {
        pwdModifyResponse = new PasswordModifyResponseImpl();
        // Now, update the created response with what we got from the extendedResponse
        pwdModifyResponse.getLdapResult().setResultCode(response.getLdapResult().getResultCode());
        pwdModifyResponse.getLdapResult().setDiagnosticMessage(response.getLdapResult().getDiagnosticMessage());
        pwdModifyResponse.getLdapResult().setMatchedDn(response.getLdapResult().getMatchedDn());
        pwdModifyResponse.getLdapResult().setReferral(response.getLdapResult().getReferral());
    }
    PasswordModifyResponseDecorator decorated = new PasswordModifyResponseDecorator(codec, pwdModifyResponse);
    Control ppolicyControl = response.getControl(PasswordPolicy.OID);
    if (ppolicyControl != null) {
        decorated.addControl(ppolicyControl);
    }
    return decorated;
}
Also used : ByteBuffer(java.nio.ByteBuffer) DecoderException(org.apache.directory.api.asn1.DecoderException) Control(org.apache.directory.api.ldap.model.message.Control) PasswordModifyResponse(org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse) StringWriter(java.io.StringWriter) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) PasswordModifyResponseImpl(org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponseImpl) PrintWriter(java.io.PrintWriter)

Aggregations

ByteBuffer (java.nio.ByteBuffer)4 DecoderException (org.apache.directory.api.asn1.DecoderException)4 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)4 PasswordModifyResponse (org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse)4 PasswordModifyResponseContainer (org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseContainer)3 PasswordModifyResponseDecorator (org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseDecorator)3 Test (org.junit.Test)3 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ExtendedResponseDecorator (org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator)1 PasswordModifyResponseImpl (org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponseImpl)1 Control (org.apache.directory.api.ldap.model.message.Control)1 ExtendedResponse (org.apache.directory.api.ldap.model.message.ExtendedResponse)1