Java Code Examples for org.apache.directory.api.ldap.model.entry.Entry#removeAttributes()

The following examples show how to use org.apache.directory.api.ldap.model.entry.Entry#removeAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for removeAttributes( String... )
 */
@Test
public void testRemoveAttributesStringArray() throws LdapException
{
    Entry entry = new DefaultEntry( exampleDn );

    Attribute attrOC = new DefaultAttribute( "objectClass", "top", "person" );
    Attribute attrCN = new DefaultAttribute( "cn", "test1", "test2" );
    Attribute attrSN = new DefaultAttribute( "sn", "Test1", "Test2" );
    Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, BYTES2 );

    entry.put( attrOC, attrCN, attrSN, attrPWD );

    entry.removeAttributes( "CN", "SN" );

    assertFalse( entry.containsAttribute( "cn", "sn" ) );
    assertTrue( entry.containsAttribute( "objectclass", "userpassword" ) );

    entry.removeAttributes( "badId" );

    entry.removeAttributes( ( String ) null );
}
 
Example 2
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for userCertificate;binary AT
 */
@Test
public void testUserCertificateBinary() throws LdapException
{
    Entry entry = new DefaultEntry( schemaManager );
    entry.add( "objectClass", "top", "person", "inetorgPerson" );
    entry.add( "cn", "test1", "test2" );
    entry.add( "sn", "Test1", "Test2" );
    entry.add( "userPassword", BYTES1, BYTES2 );

    entry.add( "userCertificate;binary", Strings.getBytesUtf8( "secret" ) );
    assertTrue( entry.containsAttribute( "userCertificate;binary" ) );
    assertTrue( entry.containsAttribute( "userCertificate" ) );

    entry.removeAttributes( "userCertificate;binary" );
    assertFalse( entry.containsAttribute( "userCertificate;binary" ) );
    assertFalse( entry.containsAttribute( "userCertificate" ) );

    entry.add( "userCertificate", Strings.getBytesUtf8( "secret" ) );
    assertTrue( entry.containsAttribute( "userCertificate;binary" ) );
    assertTrue( entry.containsAttribute( "userCertificate" ) );
}
 
Example 3
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 4 votes vote down vote up
/**
 * Adds missing Rdn's attributes and values to the entry.
 *
 * @param dn the Dn
 * @param entry the entry
 */
private void addRdnAttributesToEntry( Dn dn, Entry entry ) throws LdapException
{
    if ( dn == null || entry == null )
    {
        return;
    }

    Rdn rdn = dn.getRdn();

    // Loop on all the AVAs
    for ( Ava ava : rdn )
    {
        Value value = ava.getValue();
        String upValue = ava.getValue().getString();
        String upId = ava.getType();

        // Check that the entry contains this Ava
        if ( !entry.contains( upId, value ) )
        {
            String message = "The Rdn '" + upId + "=" + upValue + "' is not present in the entry";
            LOG.warn( message );

            // We don't have this attribute : add it.
            // Two cases :
            // 1) The attribute does not exist
            if ( !entry.containsAttribute( upId ) )
            {
                entry.add( upId, upValue );
            }
            // 2) The attribute exists
            else
            {
                AttributeType at = schemaManager.lookupAttributeTypeRegistry( upId );

                // 2.1 if the attribute is single valued, replace the value
                if ( at.isSingleValued() )
                {
                    entry.removeAttributes( upId );
                    entry.add( upId, upValue );
                }
                // 2.2 the attribute is multi-valued : add the missing value
                else
                {
                    entry.add( upId, upValue );
                }
            }
        }
    }
}