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

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


        InputStream is = KerberosServiceStarter.class.getClassLoader().getResourceAsStream("kerberos/kerberos.ldif");
        LdifReader ldifReader = new LdifReader(is);
        for (LdifEntry entry : ldifReader) {
            if (entry.isChangeAdd()) {
                directoryService.getAdminSession().add(new DefaultServerEntry(directoryService.getSchemaManager(), entry.getEntry()));
            } else if (entry.isChangeModify()) {
                directoryService.getAdminSession().modify(entry.getDn(), entry.getModificationItems());
            }
        }
        ldifReader.close();
View Full Code Here


     * Test method for put( String, Value<?>... )
     */
    @Test
    public void testPutStringValueArray()
    {
        Entry entry = new DefaultServerEntry( schemaManager, EXAMPLE_DN );
       
        Value<String> strValue1 = new StringValue( atCN, "test1" );
        Value<String> strValue2 = new StringValue( atCN, "test2" );
        Value<String> strValue3 = new StringValue( atCN, "test3" );
        Value<String> strNullValue = new StringValue( atCN, null);

        Value<byte[]> binValue1 = new BinaryValue( atPwd, BYTES1 );

        try
        {
            entry.put( (String)null, strValue1 );
            fail();
        }
        catch ( IllegalArgumentException iae)
        {
            assertTrue( true );
        }
       
        try
        {
            entry.put( "   ", strValue1 );
            fail();
        }
        catch ( IllegalArgumentException iae)
        {
            assertTrue( true );
        }
       
        try
        {
            entry.put( "cnn", strValue1 );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }
       
        EntryAttribute replaced = entry.put( "description", strNullValue );
        assertNull( replaced );
        assertEquals( 1, entry.size() );
        assertNotNull( entry.get( "description" ) );
        assertEquals( 1, entry.get( "description" ).size() );
        assertNotNull( entry.get( "description" ).get() );
        assertNull( entry.get( "description" ).get().get() );
       
        replaced = entry.put( "CN", strValue3 );
        assertNull( replaced );
        assertEquals( 2, entry.size() );
        assertNotNull( entry.get( "cn" ) );
        assertEquals( 1, entry.get( "cn" ).size() );
        assertNotNull( entry.get( "cn" ).get().get() );
        assertTrue( entry.get( "cn" ).contains( strValue3 ) );
       
        replaced = entry.put"cN", strValue1, strValue2, strValue1 );
        assertNotNull( replaced );
        assertEquals( strValue3, replaced.get() );
       
        assertEquals( 2, entry.size() );
        assertNotNull( entry.get( "cn" ) );
        assertEquals( 2, entry.get( "CN" ).size() );
       
        EntryAttribute attribute = entry.get( "cn" );
        assertTrue( attribute.contains( strValue1 ) );
        assertTrue( attribute.contains( strValue2 ) );
        assertEquals( "cn", attribute.getId() );
        assertEquals( "cN", attribute.getUpId() );
       
        // Bin values are not allowed, so the new CN will be empty
        entry.put( "cn", binValue1 );
        assertNull( entry.get( "cn" ).get() );
    }
View Full Code Here

     * Test the put( SA... ) method
     */
    @Test public void tesPutServerAttributeElipsis() throws Exception
    {
        DN dn = new DN( "cn=test" );
        DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );

        // first test a null SA addition. It should be allowed.
        try
        {
            entry.put( (EntryAttribute)null );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }
       
        // Adding some serverAttributes
        //AttributeType atCo = registries.lookupAttributeTypeRegistry( "countryName" );
        AttributeType atGN = schemaManager.lookupAttributeTypeRegistry( "givenname" );
        AttributeType atStreet = schemaManager.lookupAttributeTypeRegistry( "2.5.4.9" );

        EntryAttribute sa = new DefaultServerAttribute( atL, "france" );
        entry.put( sa );
       
        assertEquals( 1, entry.size() );
        assertNotNull( entry.get( "l" ) );
        assertEquals( "france", entry.get( "l" ).get().getString() );
       
        EntryAttribute sb = new DefaultServerAttribute( atC, "countryTest" );
        EntryAttribute sc = new DefaultServerAttribute( atGN, "test" );
        EntryAttribute sd = new DefaultServerAttribute( atStreet, "testStreet" );
        entry.put( sb, sc, sd );

        assertEquals( 4, entry.size() );
        assertNotNull( entry.get( atC ) );
        assertEquals( "countryTest", entry.get( atC ).get().getString() );
        assertNotNull( entry.get( atGN ) );
        assertEquals( "test", entry.get( atGN ).get().getString() );
        assertNotNull( entry.get( atStreet) );
        assertEquals( "testStreet", entry.get( atStreet ).get().getString() );
       
        // Test a replacement
        EntryAttribute sbb = new DefaultServerAttribute( atC, "countryTestTest" );
        EntryAttribute scc = new DefaultServerAttribute( atGN, "testtest" );
        List<EntryAttribute> result = entry.put( sbb, scc );
       
        assertEquals( 2, result.size() );
        assertEquals( "countryTest", result.get(0).get().getString() );
        assertEquals( "test", result.get(1).get().getString() );
        assertEquals( 4, entry.size() );
        assertNotNull( entry.get( atC ) );
        assertEquals( "countryTestTest", entry.get( atC ).get().getString() );
        assertNotNull( entry.get( atGN ) );
        assertEquals( "testtest", entry.get( atGN ).get().getString() );
        assertNotNull( entry.get( atStreet) );
        assertEquals( "testStreet", entry.get( atStreet ).get().getString() );
       
        // test an ObjectClass replacement
        AttributeType OBJECT_CLASS_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );
        EntryAttribute oc = new DefaultServerAttribute( "OBJECTCLASS", OBJECT_CLASS_AT, "person", "inetorgperson" );
        List<EntryAttribute> oldOc = entry.put( oc );
       
        assertNotNull( oldOc );
        assertEquals( 0, oldOc.size() );
       
        assertNotNull( entry.get( "objectClass" ) );

        EntryAttribute newOc = entry.get( "objectClass" );
       
        assertNotNull( newOc );
        assertEquals( OBJECT_CLASS_AT, newOc.getAttributeType() );
        assertEquals( 2, newOc.size() );
        assertEquals( "OBJECTCLASS", newOc.getUpId() );
View Full Code Here

     * Test the put( AT, String... ) method
     */
    @Test public void tesPutAtStringElipsis() throws Exception
    {
        DN dn = new DN( "cn=test" );
        DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
       
        // Test an empty AT
        entry.put( atCN, (String)null );
        assertEquals( 1, entry.size() );
        assertEquals( "cn", entry.get( atCN ).getUpId() );
        assertNull( entry.get( atCN ).get().get() );
       
        // Check that we can't use invalid arguments
        try
        {
            entry.put( (AttributeType)null, (String)null );
            fail();
        }
        catch( IllegalArgumentException iae )
        {
            assertTrue( true );
        }
       
        // Add a single value
        atCN = schemaManager.lookupAttributeTypeRegistry( "cn" );
        entry.put( atCN, "test" );
       
        assertEquals( 1, entry.size() );
        assertEquals( "cn", entry.get( atCN ).getUpId() );
        assertEquals( 1, entry.get( atCN ).size() );
        assertEquals( "test", entry.get( atCN ).get().getString() );
       
        // Add more than one value
        entry.put( atCN, "test1", "test2", "test3" );
       
        assertEquals( 1, entry.size() );
        assertEquals( "cn", entry.get( atCN ).getUpId() );
        assertEquals( 3, entry.get( atCN ).size() );
        assertTrue( entry.contains( "cn", "test1" ) );
        assertTrue( entry.contains( "cn", "test2" ) );
        assertTrue( entry.contains( "cn", "test3" ) );
       
        // Add twice the same value
        EntryAttribute sa = entry.put( atCN, "test1", "test2", "test1" );
       
        assertEquals( 3, sa.size() );
        assertTrue( sa.contains( "test1", "test2", "test3" ) );
        assertEquals( 1, entry.size() );
        assertEquals( "cn", entry.get( atCN ).getUpId() );
        assertEquals( 2, entry.get( atCN ).size() );
        assertTrue( entry.contains( "cn", "test1" ) );
        assertTrue( entry.contains( "cn", "test2" ) );
    }
View Full Code Here

     * Test the put( AT, Byte[]... ) method
     */
    @Test public void tesPutAtByteElipsis() throws Exception
    {
        DN dn = new DN( "cn=test" );
        DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
       
        // Test an empty AT
        entry.put( atPwd, (byte[])null );
        assertEquals( 1, entry.size() );
        assertEquals( "userPassword", entry.get( atPwd ).getUpId() );
        assertNull( entry.get( atPwd ).get().get() );
       
        // Check that we can't use invalid arguments
        try
        {
            entry.put( (AttributeType)null, (byte[])null );
            fail();
        }
        catch( IllegalArgumentException iae )
        {
            assertTrue( true );
        }
       
        byte[] password = StringTools.getBytesUtf8( "test" );
        byte[] test1 = StringTools.getBytesUtf8( "test1" );
        byte[] test2 = StringTools.getBytesUtf8( "test2" );
        byte[] test3 = StringTools.getBytesUtf8( "test3" );
       
        // Add a single value
        atPwd = schemaManager.lookupAttributeTypeRegistry( "userPassword" );
        entry.put( atPwd, password );
       
        assertEquals( 1, entry.size() );
        assertEquals( "userPassword", entry.get( atPwd ).getUpId() );
        assertEquals( 1, entry.get( atPwd ).size() );
        assertTrue( Arrays.equals( password, entry.get( atPwd ).get().getBytes() ) );
       
        // Add more than one value
        entry.put( atPwd, test1, test2, test3 );
       
        assertEquals( 1, entry.size() );
        assertEquals( "userPassword", entry.get( atPwd ).getUpId() );
        assertEquals( 3, entry.get( atPwd ).size() );
        assertTrue( entry.contains( "userpassword", test1 ) );
        assertTrue( entry.contains( "userpassword", test2 ) );
        assertTrue( entry.contains( "userpassword", test3 ) );
       
        // Add twice the same value
        EntryAttribute sa = entry.put( atPwd, test1, test2, test1 );
       
        assertEquals( 3, sa.size() );
        assertTrue( sa.contains( test1, test2, test3 ) );
        assertEquals( 1, entry.size() );
        assertEquals( "userPassword", entry.get( atPwd ).getUpId() );
        assertEquals( 2, entry.get( atPwd ).size() );
        assertTrue( entry.contains( "userpassword", test1 ) );
        assertTrue( entry.contains( "userpassword", test2 ) );
    }
View Full Code Here

     * Test the put( AT, Value... ) method
     */
    @Test public void tesPutAtSVs() throws Exception
    {
        DN dn = new DN( "cn=test" );
        DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
       
        // Adding a null value to an attribute
        entry.put( atCN, (Value<?>)null );
       
        assertEquals( 1, entry.size() );
        assertEquals( "cn", entry.get( atCN ).getUpId() );
       
        // Check that we can't use invalid arguments
        try
        {
            entry.put( (AttributeType)null, (Value<?>)null );
            fail();
        }
        catch( IllegalArgumentException iae )
        {
            assertTrue( true );
        }
       
        // Add a single value
        atCN = schemaManager.lookupAttributeTypeRegistry( "cn" );
        Value<?> ssv = new StringValue( atCN, "test" );
        entry.put( atCN, ssv );
       
        assertEquals( 1, entry.size() );
        assertEquals( "cn", entry.get( atCN ).getUpId() );
        assertEquals( 1, entry.get( atCN ).size() );
        assertEquals( "test", entry.get( atCN ).get().getString() );
       
        // Add more than one value
        entry.put( atCN, new StringValue( atCN, "test1" ),
                         new StringValue( atCN, "test2" ),
                         new StringValue( atCN, "test3" ));
       
        assertEquals( 1, entry.size() );
        assertEquals( "cn", entry.get( atCN ).getUpId() );
        assertEquals( 3, entry.get( atCN ).size() );
        assertTrue( entry.contains( "cn", "test1" ) );
        assertTrue( entry.contains( "cn", "test2" ) );
        assertTrue( entry.contains( "cn", "test3" ) );
       
        // Add twice the same value
        EntryAttribute sa = entry.put( atCN, new StringValue( atCN, "test1" ),
                         new StringValue( atCN, "test2" ),
                         new StringValue( atCN, "test1" ));
       
        assertEquals( 3, sa.size() );
        assertTrue( sa.contains( "test1", "test2", "test3" ) );
        assertEquals( 1, entry.size() );
        assertEquals( "cn", entry.get( atCN ).getUpId() );
        assertEquals( 2, entry.get( atCN ).size() );
        assertTrue( entry.contains( "cn", "test1" ) );
        assertTrue( entry.contains( "cn", "test2" ) );
    }
View Full Code Here

        userEntry.put( "sn", "elecharny" );
        userEntry.put( "cn", "Emmanuel Lecharny" );
       
        // Core API entry
        DN dn = new DN( "cn=Emmanuel Lecharny, ou=apache, ou=people, o=MNN, c=WW, ou=system" );
        serverEntry = new DefaultServerEntry( service.getSchemaManager(), dn );

        serverEntry.put( "ObjectClass", "top", "person" );
        serverEntry.put( "sn", "elecharny" );
        serverEntry.put( "cn", "Emmanuel Lecharny" );
    }
View Full Code Here

        userEntry.put( "sn", "elecharny" );
        userEntry.put( "cn", "Emmanuel Lecharny" );
       
        // Core API entry
        DN dn = new DN( "cn=Emmanuel Lecharny, ou=apache, ou=people, o=MNN, c=WW, ou=system" );
        serverEntry = new DefaultServerEntry( service.getSchemaManager(), dn );

        serverEntry.put( "ObjectClass", "top", "person" );
        serverEntry.put( "sn", "elecharny" );
        serverEntry.put( "cn", "Emmanuel Lecharny" );
    }
View Full Code Here

    {
        LdapContext sysRoot = getSystemContext( service );
        HashSet<String> set = new HashSet<String>();
        LdifEntry akarasulu = getUserAddLdif();
        service.getAdminSession().add(
            new DefaultServerEntry( service.getSchemaManager(), akarasulu.getEntry() ) );
               

        NamingEnumeration<NameClassPair> list = sysRoot.list( "ou=users" );
       
        while ( list.hasMore() )
View Full Code Here

        userEntry.put( "sn", "elecharny" );
        userEntry.put( "cn", "Emmanuel Lecharny" );
       
        // Core API entry
        DN dn = new DN( "cn=Emmanuel Lecharny, ou=apache, ou=people, o=MNN, c=WW, ou=system" );
        serverEntry = new DefaultServerEntry( service.getSchemaManager(), dn );

        serverEntry.put( "ObjectClass", "top", "person" );
        serverEntry.put( "sn", "elecharny" );
        serverEntry.put( "cn", "Emmanuel Lecharny" );
       
View Full Code Here

TOP

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

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.