Package org.apache.directory.api.ldap.model.message

Examples of org.apache.directory.api.ldap.model.message.ModifyRequest


            throw new IllegalArgumentException( msg );
        }

        int newId = messageId.incrementAndGet();

        ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setMessageId( newId );

        modifyRequest.setName( dn );

        for ( Modification modification : modifications )
        {
            modifyRequest.addModification( modification );
        }

        ModifyResponse modifyResponse = modify( modifyRequest );

        processResponse( modifyResponse );
View Full Code Here


            LOG.debug( "received a null entry for modification" );
            throw new IllegalArgumentException( "Entry to be modified cannot be null" );
        }

        int newId = messageId.incrementAndGet();
        ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setMessageId( newId );

        modifyRequest.setName( entry.getDn() );

        Iterator<Attribute> itr = entry.iterator();

        while ( itr.hasNext() )
        {
            modifyRequest.addModification( new DefaultModification( modOp, itr.next() ) );
        }

        ModifyResponse modifyResponse = modify( modifyRequest );

        processResponse( modifyResponse );
View Full Code Here

            if ( verbose )
            {
                System.out.println( "modifying " + personDn + " on the server " + nc.getConfig().getLdapHost() + ":" + nc.getConfig().getLdapPort() );
            }
           
            ModifyRequest modReq = new ModifyRequestImpl();
            modReq.setName( personDn );
            modReq.replace( SchemaConstants.SN_AT, "sn_" + i );
           
            ModifyResponse resp = nc.modify( modReq );
            ResultCodeEnum rc = resp.getLdapResult().getResultCode();
            if( rc != ResultCodeEnum.SUCCESS )
            {
View Full Code Here

     * Adding it via ou=schema partition worked. Adding it via the subschema subentry failed.
     */
    @Test
    public void testAddAttributeTypeWithoutMatchingRule() throws Exception
    {
        ModifyRequest modRequest = new ModifyRequestImpl();
        modRequest.setName( new Dn( GLOBAL_SUBSCHEMA_DN ) );
        modRequest.add( "attributeTypes", "( 2.5.4.58 NAME 'attributeCertificateAttribute' "
            + " DESC 'attribute certificate use ;binary' SYNTAX 1.3.6.1.4.1.1466.115.121.1.8 )" );
        ModifyResponse response = connection.modify( modRequest );
        assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() );
    }
View Full Code Here

        ManageDsaIT manageDSAIT = new ManageDsaITImpl();
        manageDSAIT.setCritical( true );

        // modify success
        ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName( new Dn( "uid=akarasuluref,ou=users,ou=system" ) );
        modifyRequest.add( "description", "referral to akarasulu" );
        modifyRequest.addControl( manageDSAIT );

        conn.modify( modifyRequest );

        assertTrue( conn.compare( "uid=akarasuluref,ou=users,ou=system", "description", "referral to akarasulu" ) );
View Full Code Here

    {
        LdapConnection conn = getWiredConnection( getLdapServer() );

        // referrals failure
        // modify success
        ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName( new Dn( "uid=akarasuluref,ou=users,ou=system" ) );
        modifyRequest.add( "description", "referral to akarasulu" );

        ModifyResponse modifyResponse = conn.modify( modifyRequest );

        assertEquals( ResultCodeEnum.REFERRAL, modifyResponse.getLdapResult().getResultCode() );
View Full Code Here

        LOG.debug( "" );

        LdapConnection conn = getWiredConnection( getLdapServer() );

        // referrals failure
        ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName( new Dn( "ou=Computers,uid=akarasuluref,ou=users,ou=system" ) );
        modifyRequest.add( "ou", "Machines" );

        ModifyResponse modifyResponse = conn.modify( modifyRequest );

        assertEquals( ResultCodeEnum.REFERRAL, modifyResponse.getLdapResult().getResultCode() );
View Full Code Here

            return;
        }

        // We can try to update the userPassword now
        ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName( userDn );

        Control ppolicyControl = req.getControl( PasswordPolicy.OID );
        if( ppolicyControl != null )
        {
            modifyRequest.addControl( ppolicyControl );
        }

        Modification modification = null;

        if ( oldPassword != null )
        {
            modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE,
                SchemaConstants.USER_PASSWORD_AT, oldPassword );

            modifyRequest.addModification( modification );
        }

        if ( newPassword != null )
        {
            if ( oldPassword == null )
            {
                modification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
                    SchemaConstants.USER_PASSWORD_AT, newPassword );
            }
            else
            {
                modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE,
                    SchemaConstants.USER_PASSWORD_AT, newPassword );
            }

            modifyRequest.addModification( modification );
        }
        else
        {
            // In this case, we could either generate a new password, or return an error
            // Atm, we will return an unwillingToPerform error
            LOG.error( "Cannot create a new password for user " + userDn + ", exception : " + userDn );

            // We can't modify the password
            ioPipe.write( new PasswordModifyResponseImpl(
                req.getMessageId(), ResultCodeEnum.UNWILLING_TO_PERFORM, "Cannot generate a new password for user "
                    + userDn ) );

            return;
        }

        ResultCodeEnum errorCode = null;
        String errorMessage = null;

        try
        {
            userSession.modify( modifyRequest );

            LOG.debug( "Password modified for user " + userDn );

            // Ok, all done
            PasswordModifyResponseImpl pmrl = new PasswordModifyResponseImpl(
                req.getMessageId(), ResultCodeEnum.SUCCESS );

            ppolicyControl = modifyRequest.getResultResponse().getControl( PasswordPolicy.OID );

            if( ppolicyControl != null )
            {
                pmrl.addControl( ppolicyControl );
            }

            ioPipe.write( pmrl );

            return;
        }
        catch ( LdapOperationException loe )
        {
            errorCode = loe.getResultCode();
            errorMessage = loe.getMessage();
        }
        catch ( LdapException le )
        {
            // this exception means something else must be wrong
            errorCode = ResultCodeEnum.OTHER;
            errorMessage = le.getMessage();
        }

        // We can't modify the password
        LOG.error( "Cannot modify the password for user " + userDn + ", exception : " + errorMessage );
        PasswordModifyResponseImpl errorPmrl = new PasswordModifyResponseImpl(
            req.getMessageId(), errorCode, "Cannot modify the password for user "
                + userDn + ", exception : " + errorMessage );

        ppolicyControl = modifyRequest.getResultResponse().getControl( PasswordPolicy.OID );

        if( ppolicyControl != null )
        {
            errorPmrl.addControl( ppolicyControl );
        }
View Full Code Here

        assertTrue( providerSession.exists( provUser.getDn() ) );
        assertTrue( checkEntryReplicated( provUser.getDn() ) );

        // modify the entry and check it is replicated
        ModifyRequest modReq = new ModifyRequestImpl();
        modReq.setName( provUser.getDn() );
        modReq.add( "userPassword", "secret" );

        // to test replication of binary data
        modReq.add( "objectClass", "inetOrgPerson" );
        modReq.add( "uid", "uid" );
        TlsKeyGenerator.addKeyPair( provUser );
        modReq.add( "userCertificate", provUser.get( "userCertificate" ).getBytes() );
       
        //System.out.println( ">--------------------------------------- Modifying " + modReq );
        providerSession.modify( modReq );
        //System.out.println( ">--------------------------------------- Modified " );
View Full Code Here

    private ModifyResponse changePassword( Dn userDn, String oldPassword, byte[] newPassword ) throws Exception
    {
        LdapConnection userConnection = null;
        try {
            userConnection = getNetworkConnectionAs( ldapServer, userDn.toString(), oldPassword );
            ModifyRequest modifyRequest = new ModifyRequestImpl();
            modifyRequest.setName( userDn );
            modifyRequest.replace( "userPassword", newPassword );
            return userConnection.modify( modifyRequest );
        }
        finally {
            userConnection.close();
        }
View Full Code Here

TOP

Related Classes of org.apache.directory.api.ldap.model.message.ModifyRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.