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

Examples of org.apache.directory.shared.ldap.entry.DefaultServerAttribute


    {
        DN name = new DN( "uid=akarasulu,ou=users,dc=example,dc=com" );
        ModificationOperation mod = ModificationOperation.REMOVE_ATTRIBUTE;
        AttributeType ocAt = schemaManager.lookupAttributeTypeRegistry( "objectClass" );
       
        EntryAttribute entryObjectClasses = new DefaultServerAttribute( "objectClass", ocAt );
        entryObjectClasses.add( "top", "person", "organizationalPerson" );

        // this should pass
        SchemaChecker.preventStructuralClassRemovalOnModifyRemove(
            schemaManager,
            name,
            mod,
            new DefaultServerAttribute( "cn", schemaManager.lookupAttributeTypeRegistry( "cn" ) ),
            entryObjectClasses );

        // this should succeed since person is left and is structural
        EntryAttribute objectClassesRemoved = new DefaultServerAttribute(
            "objectClass", ocAt );
        objectClassesRemoved.add( "person" );
        SchemaChecker.preventStructuralClassRemovalOnModifyRemove( schemaManager, name, mod, objectClassesRemoved,
            entryObjectClasses );

        // this should fail since only top is left
        objectClassesRemoved = new DefaultServerAttribute( "objectClass", ocAt );
        objectClassesRemoved.add( "person", "organizationalPerson" );
       
        try
        {
            SchemaChecker.preventStructuralClassRemovalOnModifyRemove( schemaManager, name, mod, objectClassesRemoved,
                entryObjectClasses );
            fail( "should never get here due to an LdapSchemaViolationException" );
        }
        catch ( LdapSchemaViolationException e )
        {
            assertEquals( e.getResultCode(), ResultCodeEnum.OBJECT_CLASS_MODS_PROHIBITED );
        }

        // this should fail since the modify operation tries to delete all
        // objectClass attribute values
        objectClassesRemoved = new DefaultServerAttribute( "objectClass", ocAt );

        try
        {
            SchemaChecker.preventStructuralClassRemovalOnModifyRemove( schemaManager, name, mod, objectClassesRemoved,
                entryObjectClasses );
View Full Code Here


        AttributeType ouAt = schemaManager.lookupAttributeTypeRegistry( "ou" );
        AttributeType snAt = schemaManager.lookupAttributeTypeRegistry( "sn" );

        // postive test which should pass
        SchemaChecker.preventRdnChangeOnModifyRemove( name, mod,
            new DefaultServerAttribute( "cn", cnAt, "does not matter" ), schemaManager );

        // test should fail since we are removing the ou attribute
        try
        {
            SchemaChecker.preventRdnChangeOnModifyRemove( name, mod,
                new DefaultServerAttribute( "ou", ouAt ), schemaManager );
            fail( "should never get here due to a LdapSchemaViolationException being thrown" );
        }
        catch ( LdapSchemaViolationException e )
        {
            assertEquals( ResultCodeEnum.NOT_ALLOWED_ON_RDN, e.getResultCode() );
        }

        // test success using more than one attribute for the Rdn but not modifying rdn attribute
        name = new DN( "ou=users+cn=system users,dc=example,dc=com" );
        name.normalize( oidNormalizers );
        SchemaChecker.preventRdnChangeOnModifyRemove( name, mod,
            new DefaultServerAttribute( "sn", snAt, "does not matter" ), schemaManager );

        // test for failure when modifying Rdn attribute in multi attribute Rdn
        try
        {
            SchemaChecker.preventRdnChangeOnModifyRemove( name, mod,
                new DefaultServerAttribute( "cn", cnAt ), schemaManager );
            fail( "should never get here due to a LdapSchemaViolationException being thrown" );
        }
        catch ( LdapSchemaViolationException e )
        {
            assertEquals( ResultCodeEnum.NOT_ALLOWED_ON_RDN, e.getResultCode() );
        }

        // should succeed since the value being deleted from the rdn attribute is
        // is not used when composing the Rdn
        SchemaChecker.preventRdnChangeOnModifyRemove( name, mod,
            new DefaultServerAttribute( "ou", ouAt, "container" ), schemaManager );

        // now let's make it fail again just by providing the right value for ou (users)
        try
        {
            SchemaChecker.preventRdnChangeOnModifyRemove( name, mod,
                new DefaultServerAttribute( "ou", ouAt, "users" ), schemaManager );
            fail( "should never get here due to a LdapSchemaViolationException being thrown" );
        }
        catch ( LdapSchemaViolationException e )
        {
            assertEquals( ResultCodeEnum.NOT_ALLOWED_ON_RDN, e.getResultCode() );
View Full Code Here

    }


    @Test public void testCreateServerModification()
    {
        EntryAttribute attribute = new DefaultServerAttribute( atCN );
        attribute.add( "test1", "test2" );
       
        Modification mod = new ServerModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
        Modification clone = mod.clone();
       
        attribute.remove( "test2" );
       
        EntryAttribute clonedAttribute = clone.getAttribute();
       
        assertEquals( 1, mod.getAttribute().size() );
        assertTrue( mod.getAttribute().contains( "test1" ) );
View Full Code Here

     *
     */
    @Test
    public void testCopyServerModification()
    {
        EntryAttribute attribute = new DefaultServerAttribute( atC );
        attribute.add( "test1", "test2" );
        Modification serverModification = new ServerModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
       
        Modification copy = new ServerModification( schemaManager, serverModification );
       
        assertTrue( copy instanceof ServerModification );
        assertEquals( copy, serverModification );
       
        serverModification.setOperation( ModificationOperation.REMOVE_ATTRIBUTE );
        assertEquals( ModificationOperation.ADD_ATTRIBUTE, copy.getOperation() );
       
        EntryAttribute attribute2 = new DefaultServerAttribute( atCN, "t" );
        serverModification.setAttribute( attribute2 );
        assertNotSame( attribute2, copy.getAttribute() );
    }
View Full Code Here

   
   
    @Test
    public void testSerializationModificationADD() throws ClassNotFoundException, IOException, LdapException
    {
        EntryAttribute attribute = new DefaultServerAttribute( atCN );
        attribute.add( "test1", "test2" );
       
        ServerModification mod = new ServerModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
       
        Modification modSer = deserializeValue( serializeValue( mod ) );
       
View Full Code Here

   
   
    @Test
    public void testSerializationModificationREPLACE() throws ClassNotFoundException, IOException, LdapException
    {
        EntryAttribute attribute = new DefaultServerAttribute( atCN );
        attribute.add( "test1", "test2" );
       
        ServerModification mod = new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute );
       
        Modification modSer = deserializeValue( serializeValue( mod ) );
       
View Full Code Here

   
   
    @Test
    public void testSerializationModificationREMOVE() throws ClassNotFoundException, IOException, LdapException
    {
        EntryAttribute attribute = new DefaultServerAttribute( atCN );
        attribute.add( "test1", "test2" );
       
        ServerModification mod = new ServerModification( ModificationOperation.REMOVE_ATTRIBUTE, attribute );
       
        Modification modSer = deserializeValue( serializeValue( mod ) );
       
View Full Code Here

        SchemaManager schemaManager = session.getDirectoryService().getSchemaManager();
       
        List<Modification> mods = new ArrayList<Modification>(2);
       
        EntryAttribute newPasswordAttribute = new DefaultServerAttribute(
            schemaManager.lookupAttributeTypeRegistry( SchemaConstants.USER_PASSWORD_AT ), StringTools.getBytesUtf8( newPassword ) );
        mods.add( new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE, newPasswordAttribute ) );
       
        EntryAttribute principalAttribute = new DefaultServerAttribute(
            schemaManager.lookupAttributeTypeRegistry( KerberosAttribute.KRB5_PRINCIPAL_NAME_AT ), principal.getName() );
        mods.add( new ServerModification( ModificationOperation.REPLACE_ATTRIBUTE, principalAttribute ) );
       
        //FIXME check if keyderivation is necessary
       
View Full Code Here

    @Test
    public void testAddEntryAttribute() throws Exception
    {
        Entry entry = new DefaultServerEntry( schemaManager, EXAMPLE_DN );
       
        EntryAttribute oc = new DefaultServerAttribute( atObjectClass, "top", "person" );
        EntryAttribute cn = new DefaultServerAttribute( atCN, "test1", "test2" );
        EntryAttribute sn = new DefaultServerAttribute( atSN, "Test1", "Test2" );
        EntryAttribute up = new DefaultServerAttribute( atPwd, BYTES1, BYTES2 );
        EntryAttribute c = new DefaultServerAttribute( atC, "FR", "US" );
       
        entry.add( oc, cn, sn, c );
       
        assertEquals( 4, entry.size() );
        assertTrue( entry.containsAttribute( "ObjectClass" ) );
        assertTrue( entry.containsAttribute( "CN" ) );
        assertTrue( entry.containsAttribute( "  sn  " ) );
        assertTrue( entry.containsAttribute( " countryName  " ) );
   
        EntryAttribute attr = entry.get( "objectclass" );
        assertEquals( 2, attr.size() );
       
        EntryAttribute c2 = new DefaultServerAttribute( atC, "UK", "DE" );
        entry.add( c2, up );
        assertEquals( 5, entry.size() );
       
        assertTrue( entry.containsAttribute( "userPassword" ) );
        assertTrue( entry.containsAttribute( " countryName " ) );
View Full Code Here

        ServerEntry entry = new DefaultServerEntry( schemaManager, EXAMPLE_DN );
       
        assertFalse( entry.contains( (AttributeType )null, BYTES1 ) );
        assertFalse( entry.contains( atPwd, BYTES1 ) );
       
        EntryAttribute attrPWD = new DefaultServerAttribute( atPwd, BYTES1, BYTES2 );

        assertFalse( entry.contains( attrPWD ) );
       
        entry.add( attrPWD );
       
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.entry.DefaultServerAttribute

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.