Package org.apache.directory.shared.ldap.model.entry

Examples of org.apache.directory.shared.ldap.model.entry.EntryAttribute


            {
                assertEquals( values[0][i][1], entry.getDn().getName() );
            }
            else if ( "jpegphoto".equalsIgnoreCase( values[0][i][0] ) )
            {
                EntryAttribute attr = entry.get( values[0][i][0] );
                assertEquals( Strings.dumpBytes(data), Strings.dumpBytes(attr.getBytes()) );
            }
            else
            {
                EntryAttribute attr = entry.get( values[0][i][0] );

                if ( attr.contains( values[0][i][1] ) )
                {
                    assertTrue( true );
                }
                else
                {
                    assertTrue( attr.contains( values[0][i][1].getBytes( "UTF-8" ) ) );
                }
            }
        }

        // Second entry
View Full Code Here


        LdifEntry entry = entries.get( 0 );

        assertEquals( "ou=Users, dc=example, dc=com", entry.getDn().getName() );

        EntryAttribute attr = entry.get( "objectclass" );
        assertTrue( attr.contains( "top" ) );
        assertTrue( attr.contains( "organizationalunit" ) );

        attr = entry.get( "ou" );
        assertTrue( attr.contains( "Users" ) );
    }
View Full Code Here

        reader.close();

        LdifEntry entry = entries.get( 0 );

        assertEquals( "cn=browseRootAci,dc=example,dc=com", entry.getDn().getName() );
        EntryAttribute attr = entry.get( "objectClass" );
        assertTrue( attr.contains( "top" ) );
        assertTrue( attr.contains( SchemaConstants.SUBENTRY_OC ) );
        assertTrue( attr.contains( "accessControlSubentry" ) );

        attr = entry.get( "subtreeSpecification" );
        assertTrue( attr.contains( "{ maximum 1 }" ) );

        attr = entry.get( "prescriptiveACI" );
        assertTrue( attr
            .contains( "{ identificationTag \"browseRoot\", precedence 100, authenticationLevel none, itemOrUserFirst userFirst: { userClasses { allUsers }, userPermissions { { protectedItems {entry}, grantsAndDenials { grantReturnDN, grantBrowse } } } } }" ) );
    }
View Full Code Here

        assertTrue( entry.isLdifChange() );
        assertTrue( entry.isChangeAdd() );

        assertEquals( 1, entry.getEntry().size() );

        EntryAttribute attr = entry.get( "attr1" );
        assertTrue( attr.contains( "ATTR1" ) );
    }
View Full Code Here

        assertTrue( entry.isLdifChange() );
        assertTrue( entry.isChangeAdd() );

        assertEquals( 1, entry.getEntry().size() );

        EntryAttribute attr = entry.get( "attr1" );
        assertEquals( 2, attr.size() );
        assertTrue( attr.contains( "ATTR1" ) );
        assertTrue( attr.contains( "ATTR2" ) );
    }
View Full Code Here

        assertTrue( entry.isLdifChange() );
        assertTrue( entry.isChangeAdd() );

        assertEquals( 2, entry.getEntry().size() );

        EntryAttribute attr = entry.get( "attr1" );
        assertEquals( 2, attr.size() );
        assertTrue( attr.contains( "ATTR1" ) );
        assertTrue( attr.contains( "ATTR2" ) );

        EntryAttribute attr2 = entry.get( "attr2" );
        assertEquals( 1, attr2.size() );
        assertTrue( attr2.contains( "ATTR1" ) );
    }
View Full Code Here

    private void parseModify( LdifEntry entry, Iterator<String> iter ) throws LdapLdifException
    {
        int state = MOD_SPEC;
        String modified = null;
        ModificationOperation modificationType = ModificationOperation.ADD_ATTRIBUTE;
        EntryAttribute attribute = null;

        // The following flag is used to deal with empty modifications
        boolean isEmptyValue = true;

        while ( iter.hasNext() )
        {
            String line = iter.next();
            String lowerLine = line.toLowerCase();

            if ( lowerLine.startsWith( "-" ) )
            {
                if ( state != ATTRVAL_SPEC_OR_SEP )
                {
                    LOG.error( I18n.err( I18n.ERR_12040_BAD_MODIFY_SEPARATOR ) );
                    throw new LdapLdifException( I18n.err( I18n.ERR_12040_BAD_MODIFY_SEPARATOR ) );
                }
                else
                {
                    if ( isEmptyValue )
                    {
                        // Update the entry
                        entry.addModificationItem( modificationType, modified, null );
                    }
                    else
                    {
                        // Update the entry with the attribute
                        entry.addModificationItem( modificationType, attribute );
                    }

                    state = MOD_SPEC;
                    isEmptyValue = true;
                }
            }
            else if ( lowerLine.startsWith( "add:" ) )
            {
                if ( ( state != MOD_SPEC ) && ( state != ATTRVAL_SPEC ) )
                {
                    LOG.error( I18n.err( I18n.ERR_12042_BAD_MODIFY_SEPARATOR_2 ) );
                    throw new LdapLdifException( I18n.err( I18n.ERR_12042_BAD_MODIFY_SEPARATOR_2 ) );
                }

                modified = Strings.trim(line.substring("add:".length()));
                modificationType = ModificationOperation.ADD_ATTRIBUTE;
                attribute = new DefaultEntryAttribute( modified );

                state = ATTRVAL_SPEC;
            }
            else if ( lowerLine.startsWith( "delete:" ) )
            {
                if ( ( state != MOD_SPEC ) && ( state != ATTRVAL_SPEC ) )
                {
                    LOG.error( I18n.err( I18n.ERR_12042_BAD_MODIFY_SEPARATOR_2 ) );
                    throw new LdapLdifException( I18n.err( I18n.ERR_12042_BAD_MODIFY_SEPARATOR_2 ) );
                }

                modified = Strings.trim(line.substring("delete:".length()));
                modificationType = ModificationOperation.REMOVE_ATTRIBUTE;
                attribute = new DefaultEntryAttribute( modified );

                state = ATTRVAL_SPEC_OR_SEP;
            }
            else if ( lowerLine.startsWith( "replace:" ) )
            {
                if ( ( state != MOD_SPEC ) && ( state != ATTRVAL_SPEC ) )
                {
                    LOG.error( I18n.err( I18n.ERR_12042_BAD_MODIFY_SEPARATOR_2 ) );
                    throw new LdapLdifException( I18n.err( I18n.ERR_12042_BAD_MODIFY_SEPARATOR_2 ) );
                }

                modified = Strings.trim(line.substring("replace:".length()));
                modificationType = ModificationOperation.REPLACE_ATTRIBUTE;
                attribute = new DefaultEntryAttribute( modified );

                state = ATTRVAL_SPEC_OR_SEP;
            }
            else
            {
                if ( ( state != ATTRVAL_SPEC ) && ( state != ATTRVAL_SPEC_OR_SEP ) )
                {
                    LOG.error( I18n.err( I18n.ERR_12040_BAD_MODIFY_SEPARATOR ) );
                    throw new LdapLdifException( I18n.err( I18n.ERR_12040_BAD_MODIFY_SEPARATOR ) );
                }

                // A standard AttributeType/AttributeValue pair
                int colonIndex = line.indexOf( ':' );

                String attributeType = line.substring( 0, colonIndex );

                if ( !attributeType.equalsIgnoreCase( modified ) )
                {
                    LOG.error( I18n.err( I18n.ERR_12044 ) );
                    throw new LdapLdifException( I18n.err( I18n.ERR_12045 ) );
                }

                // We should *not* have a Dn twice
                if ( attributeType.equalsIgnoreCase( "dn" ) )
                {
                    LOG.error( I18n.err( I18n.ERR_12002_ENTRY_WITH_TWO_DNS ) );
                    throw new LdapLdifException( I18n.err( I18n.ERR_12003_LDIF_ENTRY_WITH_TWO_DNS ) );
                }

                Object attributeValue = parseValue( line, colonIndex );

                if ( attributeValue instanceof String )
                {
                    attribute.add( ( String ) attributeValue );
                }
                else
                {
                    attribute.add( ( byte[] ) attributeValue );
                }

                isEmptyValue = false;

                state = ATTRVAL_SPEC_OR_SEP;
View Full Code Here

        }

        Object attributeValue = parseValue( line, colonIndex );

        // Update the entry
        EntryAttribute attribute = null;

        if ( schemaManager == null )
        {
            attribute = entry.get( attributeName );
        }
        else
        {
            attribute = entry.get( attributeType );
        }

        if ( attribute == null )
        {
            if ( schemaManager == null )
            {
                if ( attributeValue instanceof String )
                {
                    entry.put( attributeName, ( String ) attributeValue );
                }
                else
                {
                    entry.put( attributeName, ( byte[] ) attributeValue );
                }
            }
            else
            {
                try
                {
                    if ( attributeValue instanceof String )
                    {
                        entry.put( attributeName, attributeType, ( String ) attributeValue );
                    }
                    else
                    {
                        entry.put( attributeName, attributeType, ( byte[] ) attributeValue );
                    }
                }
                catch ( LdapException le )
                {
                    throw new LdapLdifException( I18n.err( I18n.ERR_12057_BAD_ATTRIBUTE ) );
                }
            }
        }
        else
        {
            if ( attributeValue instanceof String )
            {
                attribute.add( ( String ) attributeValue );
            }
            else
            {
                attribute.add( ( byte[] ) attributeValue );
            }
        }
    }
View Full Code Here

    @Test
    public void testReverseModifyDeleteOU() throws LdapException
    {
        Entry modifiedEntry = buildEntry();
       
        EntryAttribute ou = new DefaultEntryAttribute( "ou" );
        ou.add( "apache", "acme corp" );
        modifiedEntry.put( ou );

        Dn dn = new Dn( "cn=test, ou=system" );

        Modification mod = new DefaultModification(
            ModificationOperation.REMOVE_ATTRIBUTE,
            new DefaultEntryAttribute( "ou" ) );

        LdifEntry reversed = LdifRevertor.reverseModify( dn,
                Collections.<Modification>singletonList( mod ), modifiedEntry );


        assertNotNull( reversed );
        assertEquals( dn.getName(), reversed.getDn().getName() );
        assertEquals( ChangeType.Modify, reversed.getChangeType() );
        assertNull( reversed.getEntry() );
       
        List<Modification> mods = reversed.getModificationItems();
       
        assertNotNull( mods );
        assertEquals( 1, mods.size() );
       
        Modification modif = mods.get( 0 );
       
        assertEquals( ModificationOperation.ADD_ATTRIBUTE, modif.getOperation() );

        EntryAttribute attr = modif.getAttribute();
       
        assertNotNull( attr );
        assertEquals( "ou", attr.getId() );
       
        assertEquals( ou, attr );
    }
View Full Code Here

    @Test
    public void testReverseModifyDelExistingOuWithAllValues() throws LdapException
    {
        Entry modifiedEntry = buildEntry();

        EntryAttribute ou = new DefaultEntryAttribute( "ou", "apache", "acme corp" );
        modifiedEntry.put( ou );
       
        Dn dn = new Dn( "cn=test, ou=system" );
       
        Modification mod = new DefaultModification(
            ModificationOperation.REMOVE_ATTRIBUTE, ou );

        LdifEntry reversed = LdifRevertor.reverseModify( dn,
                Collections.<Modification>singletonList( mod ), modifiedEntry );


        assertNotNull( reversed );
        assertEquals( dn.getName(), reversed.getDn().getName() );
        assertEquals( ChangeType.Modify, reversed.getChangeType() );
        assertNull( reversed.getEntry() );
       
        List<Modification> mods = reversed.getModificationItems();
       
        assertNotNull( mods );
        assertEquals( 1, mods.size() );
       
        Modification modif = mods.get( 0 );
       
        assertEquals( ModificationOperation.ADD_ATTRIBUTE, modif.getOperation() );

        EntryAttribute attr = modif.getAttribute();
       
        assertNotNull( attr );
        assertEquals( "ou", attr.getId() );
       
        assertEquals( ou, attr );
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.model.entry.EntryAttribute

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.