Search in sources :

Example 1 with ModifyRequest

use of org.apache.directory.api.ldap.model.message.ModifyRequest in project karaf by apache.

the class LdapSpecialCharsInPasswordTest method changeAdminPassword.

@Before
public void changeAdminPassword() throws Exception {
    LdapConnection connection = new LdapNetworkConnection("localhost", getLdapServer().getPort());
    connection.bind("uid=admin,ou=system", "secret");
    Dn adminDn = new Dn("uid=admin,ou=system");
    ModifyRequest modReq = new ModifyRequestImpl();
    modReq.setName(adminDn);
    modReq.replace(SchemaConstants.USER_PASSWORD_AT, NEW_CONNECTION_PASSWORD);
    connection.modify(modReq);
    connection.close();
    // check that we actually changed the admin connection password
    connection = new LdapNetworkConnection("localhost", getLdapServer().getPort());
    connection.bind("uid=admin,ou=system", NEW_CONNECTION_PASSWORD);
    connection.close();
}
Also used : ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapNetworkConnection(org.apache.directory.ldap.client.api.LdapNetworkConnection) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection) Before(org.junit.Before)

Example 2 with ModifyRequest

use of org.apache.directory.api.ldap.model.message.ModifyRequest in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method writeStringAttributes.

public void writeStringAttributes(final String entryDN, final Map<String, String> attributeValueProps, final boolean overwrite) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().writeStringAttributes(entryDN, attributeValueProps, overwrite);
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        for (final Map.Entry<String, String> entry : attributeValueProps.entrySet()) {
            final String name = entry.getKey();
            final String value = entry.getValue();
            final Modification modification = new DefaultModification();
            modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(name, value));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Example 3 with ModifyRequest

use of org.apache.directory.api.ldap.model.message.ModifyRequest in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method replaceAttributeImpl.

private void replaceAttributeImpl(final String entryDN, final String attributeName, final Value oldValue, final Value newValue) throws ChaiOperationException {
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(ModificationOperation.REMOVE_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, oldValue));
            modifyRequest.addModification(modification);
        }
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, newValue));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Example 4 with ModifyRequest

use of org.apache.directory.api.ldap.model.message.ModifyRequest in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method writeBinaryAttribute.

public void writeBinaryAttribute(final String entryDN, final String attributeName, final byte[][] values, final boolean overwrite) throws ChaiUnavailableException, ChaiOperationException {
    activityPreCheck();
    getInputValidator().writeBinaryAttribute(entryDN, attributeName, values, overwrite);
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, values));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Example 5 with ModifyRequest

use of org.apache.directory.api.ldap.model.message.ModifyRequest in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method writeStringAttribute.

public void writeStringAttribute(final String entryDN, final String attributeName, final Set<String> values, final boolean overwrite) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().writeStringAttribute(entryDN, attributeName, values, overwrite);
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, values.toArray(new String[values.size()])));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Aggregations

ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)40 Modification (org.apache.directory.api.ldap.model.entry.Modification)25 Test (org.junit.Test)24 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)22 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)17 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)17 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)14 ModifyRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator)11 ModifyRequestImpl (org.apache.directory.api.ldap.model.message.ModifyRequestImpl)11 ModifyResponse (org.apache.directory.api.ldap.model.message.ModifyResponse)10 Dn (org.apache.directory.api.ldap.model.name.Dn)10 ByteBuffer (java.nio.ByteBuffer)7 DecoderException (org.apache.directory.api.asn1.DecoderException)7 EncoderException (org.apache.directory.api.asn1.EncoderException)7 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)7 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)7 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)7 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)7 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)7 Control (org.apache.directory.api.ldap.model.message.Control)7