org.apache.directory.api.ldap.model.entry.DefaultAttribute Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.entry.DefaultAttribute. 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: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the conversion method
 */
@Test
public void testToClientAttribute() throws LdapException
{
    Attribute attribute = new DefaultAttribute( atCN, "test", "test2" );

    Attribute clientAttribute = attribute.clone();

    assertTrue( clientAttribute instanceof Attribute );

    assertTrue( clientAttribute.contains( "test", "test2" ) );
    assertEquals( "2.5.4.3", clientAttribute.getId() );

    attribute.remove( "test", "test2" );
    assertTrue( clientAttribute.contains( "test", "test2" ) );
}
 
Example #2
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method contains( String... )
 */
@Test
public void testContainsStringArray() throws LdapException
{
    Attribute attr1 = new DefaultAttribute( atEMail );

    assertEquals( 0, attr1.size() );
    assertFalse( attr1.contains( "a" ) );
    assertFalse( attr1.contains( ( String ) null ) );

    attr1.add( ( String ) null );
    assertEquals( 1, attr1.size() );
    assertTrue( attr1.contains( ( String ) null ) );

    attr1.remove( ( String ) null );
    assertFalse( attr1.contains( ( String ) null ) );
    assertEquals( 0, attr1.size() );

    attr1.add( "a", "b", "c" );
    assertEquals( 3, attr1.size() );
    assertTrue( attr1.contains( "a" ) );
    assertTrue( attr1.contains( "b" ) );
    assertTrue( attr1.contains( "c" ) );
    assertFalse( attr1.contains( "e" ) );
    assertFalse( attr1.contains( ( String ) null ) );
}
 
Example #3
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method getUpId
 */
@Test
public void testGetUpId()
{
    Attribute attr = new DefaultAttribute( atCN );

    assertNotNull( attr.getUpId() );
    assertEquals( "cn", attr.getUpId() );

    attr.setUpId( "CN" );
    assertEquals( "CN", attr.getUpId() );

    attr.setUpId( "  Cn  " );
    assertEquals( "  Cn  ", attr.getUpId() );

    attr.setUpId( "  2.5.4.3  " );
    assertEquals( "  2.5.4.3  ", attr.getUpId() );
}
 
Example #4
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method clear()
 */
@Test
public void testClear() throws LdapException
{
    Attribute attr = new DefaultAttribute( "email", atEMail );

    assertEquals( 0, attr.size() );

    attr.add( ( String ) null, "a", "b" );
    assertEquals( 3, attr.size() );

    attr.clear();
    assertTrue( attr.isHumanReadable() );
    assertEquals( 0, attr.size() );
    assertEquals( atEMail, attr.getAttributeType() );
}
 
Example #5
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAttribute() throws Exception
{
    AttributeType at = TestEntryUtils.getIA5StringAttributeType();

    DefaultAttribute attr = new DefaultAttribute( at );

    attr.add( "Test1" );
    attr.add( "Test2" );
    attr.add( "Test3" );

    assertEquals( "1.1", attr.getId() );
    assertEquals( 3, attr.size() );
    assertTrue( attr.contains( "Test1" ) );
    assertTrue( attr.contains( "Test2" ) );
    assertTrue( attr.contains( "Test3" ) );
}
 
Example #6
Source File: ModificationTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateServerModification() throws LdapException
{
    Attribute attribute = new DefaultAttribute( "cn" );
    attribute.add( "test1", "test2" );

    Modification mod = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attribute );
    Modification clone = mod.clone();

    attribute.remove( "test2" );

    Attribute clonedAttribute = clone.getAttribute();

    assertEquals( 1, mod.getAttribute().size() );
    assertTrue( mod.getAttribute().contains( "test1" ) );

    assertEquals( 2, clonedAttribute.size() );
    assertTrue( clone.getAttribute().contains( "test1" ) );
    assertTrue( clone.getAttribute().contains( "test2" ) );
}
 
Example #7
Source File: SchemaEntityFactory.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Process the ByteCode attribute
 * 
 * @param description The SchemaObject description
 * @param objectType The SchemaObject type
 * @return The Attribute containing the byteCode
 */
private Attribute getByteCode( LoadableSchemaObject description, String objectType )
{
    String byteCodeString = description.getBytecode();

    if ( byteCodeString == null )
    {
        String msg = I18n.err( I18n.ERR_16034_ENTRY_WITHOUT_VALID_AT, objectType, MetaSchemaConstants.M_BYTECODE_AT );
        
        if ( LOG.isWarnEnabled() )
        {
            LOG.warn( msg );
        }
        
        throw new IllegalArgumentException( msg );
    }

    byte[] bytecode = Base64.decode( byteCodeString.toCharArray() );
    
    return new DefaultAttribute( MetaSchemaConstants.M_BYTECODE_AT, bytecode );
}
 
Example #8
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method iterator()
 */
@Test
public void testIterator() throws LdapException
{
    Attribute attr1 = new DefaultAttribute( atCN );
    attr1.add( "a", "b", "c" );

    Iterator<Value> iter = attr1.iterator();

    assertTrue( iter.hasNext() );

    String[] values = new String[]
        { "a", "b", "c" };
    int pos = 0;

    for ( Value val : attr1 )
    {
        assertTrue( val instanceof Value );
        assertEquals( values[pos++], val.getString() );
    }
}
 
Example #9
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method toString
 */
@Test
public void testToString() throws LdapException
{
    Attribute attr = new DefaultAttribute( atEMail );

    assertEquals( "email: (null)", attr.toString() );

    attr.setUpId( "EMail" );
    assertEquals( "EMail: (null)", attr.toString() );

    attr.add( ( String ) null );
    assertEquals( "EMail: ''", attr.toString() );

    attr.clear();
    attr.add( "a", "b" );
    assertEquals( "EMail: a\nEMail: b", attr.toString() );
}
 
Example #10
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method setAttributeType( AttributeType )
 */
@Test
public void testSetAttributeType() throws Exception
{
    Attribute attr = new DefaultAttribute( atCN );

    try
    {
        attr.apply( null );
        fail();
    }
    catch ( IllegalArgumentException iae )
    {
        assertTrue( true );
    }

    attr.apply( atSN );

    assertTrue( attr.isInstanceOf( atSN ) );
    assertEquals( "2.5.4.4", attr.getId() );
    assertEquals( "sn", attr.getUpId() );
}
 
Example #11
Source File: AttributeUtilsTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test a addModification applied to an entry 
 */
@Test
public void testApplyAddModificationToEntry() throws LdapException
{
    Entry entry = new DefaultEntry();
    entry.add( "dc", "apache" );
    assertEquals( 1, entry.size() );

    Attribute attr = new DefaultAttribute( "cn", "test" );
    Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );

    AttributeUtils.applyModification( entry, modification );
    assertNotNull( entry.get( "cn" ) );
    assertEquals( 2, entry.size() );
    assertEquals( attr, entry.get( "cn" ) );
}
 
Example #12
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method DefaultEntryAttribute( AttributeType, byte[]... )
 */
@Test
public void testDefaultServerAttributeAttributeTypeByteArray() throws LdapException
{
    Attribute attr1 = new DefaultAttribute( atPwd, BYTES1, BYTES2, ( byte[] ) null );

    assertFalse( attr1.isHumanReadable() );
    assertEquals( 3, attr1.size() );
    assertEquals( "2.5.4.35", attr1.getId() );
    assertEquals( "userPassword", attr1.getUpId() );
    assertEquals( atPwd, attr1.getAttributeType() );
    assertTrue( attr1.contains( BYTES1, BYTES2 ) );
    assertTrue( attr1.contains( nullBinaryValue ) );

    Attribute attr2 = new DefaultAttribute( atPwd, stringValue1, binaryValue2, nullBinaryValue );

    assertFalse( attr2.isHumanReadable() );
    assertEquals( 2, attr2.size() );
    assertEquals( "2.5.4.35", attr2.getId() );
    assertEquals( "userPassword", attr2.getUpId() );
    assertEquals( atPwd, attr2.getAttributeType() );
    assertTrue( attr2.contains( BYTES2 ) );
    assertTrue( attr2.contains( nullBinaryValue ) );
}
 
Example #13
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method DefaultEntryAttribute( String, AttributeType, byte[]... )
 */
@Test
public void testDefaultServerAttributeStringAttributeTypeByteArray() throws LdapException
{
    Attribute attr1 = new DefaultAttribute( "userPassword", atPwd, BYTES1, BYTES2, ( byte[] ) null );

    assertFalse( attr1.isHumanReadable() );
    assertEquals( 3, attr1.size() );
    assertEquals( "2.5.4.35", attr1.getId() );
    assertEquals( "userPassword", attr1.getUpId() );
    assertEquals( atPwd, attr1.getAttributeType() );
    assertTrue( attr1.contains( BYTES1, BYTES2 ) );
    assertTrue( attr1.contains( nullBinaryValue ) );

    Attribute attr2 = new DefaultAttribute( "2.5.4.35", atPwd, stringValue1, binaryValue2, nullBinaryValue );

    assertFalse( attr2.isHumanReadable() );
    assertEquals( 2, attr2.size() );
    assertEquals( "2.5.4.35", attr2.getId() );
    assertEquals( "2.5.4.35", attr2.getUpId() );
    assertEquals( atPwd, attr2.getAttributeType() );
    assertTrue( attr2.contains( BYTES2 ) );
    assertTrue( attr2.contains( nullBinaryValue ) );
}
 
Example #14
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the copy constructor of a EntryAttribute
 */
@Test
public void testCopyConstructorServerAttribute() throws LdapException
{
    Attribute attribute = new DefaultAttribute( atCN );

    Attribute copy = new DefaultAttribute( atCN, attribute );

    assertEquals( copy, attribute );

    Attribute attribute2 = new DefaultAttribute( atCN, "test" );

    Attribute copy2 = new DefaultAttribute( atCN, attribute2 );

    assertEquals( copy2, attribute2 );
    attribute2.add( "test2" );
    assertNotSame( copy2, attribute2 );
    assertEquals( "test", copy2.getString() );
}
 
Example #15
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the copy constructor of a ClientAttribute
 */
@Test
public void testCopyConstructorClientAttribute() throws LdapException
{
    Attribute attribute = new DefaultAttribute( "commonName" );
    attribute.add( "test" );

    Attribute copy = new DefaultAttribute( atCN, attribute );

    assertEquals( atCN, copy.getAttributeType() );
    assertEquals( "test", copy.getString() );
    assertTrue( copy.isHumanReadable() );

    attribute.add( "test2" );
    assertFalse( copy.contains( "test2" ) );
}
 
Example #16
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
private void createContextCsnModList() throws LdapException
{
    Modification contextCsnMod = new DefaultModification();
    contextCsnMod.setOperation( ModificationOperation.REPLACE_ATTRIBUTE );
    DefaultAttribute contextCsnAt = new DefaultAttribute( schemaManager
        .lookupAttributeTypeRegistry( SchemaConstants.CONTEXT_CSN_AT ) );
    contextCsnMod.setAttribute( contextCsnAt );

    mods.add( contextCsnMod );

    Modification timeStampMod = new DefaultModification();
    timeStampMod.setOperation( ModificationOperation.REPLACE_ATTRIBUTE );
    DefaultAttribute timeStampAt = new DefaultAttribute( schemaManager
        .lookupAttributeTypeRegistry( SchemaConstants.MODIFY_TIMESTAMP_AT ) );
    timeStampMod.setAttribute( timeStampAt );

    mods.add( timeStampMod );
}
 
Example #17
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the serialization of a complete server attribute
 */
@Test
public void testSerializeCompleteAttribute() throws LdapException, IOException, ClassNotFoundException
{
    DefaultAttribute dsa = new DefaultAttribute( atCN );
    dsa.setUpId( "CommonName" );
    dsa.add( "test1", "test2" );

    DefaultAttribute dsaSer = deserializeValue( serializeValue( dsa ), atCN );
    assertEquals( dsa.toString(), dsaSer.toString() );
    assertEquals( "2.5.4.3", dsaSer.getId() );
    assertEquals( "CommonName", dsaSer.getUpId() );
    assertEquals( "test1", dsaSer.getString() );
    assertTrue( dsaSer.contains( "test2", "test1" ) );
    assertTrue( dsaSer.isHumanReadable() );
}
 
Example #18
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the serialization of a server attribute with a null value
 */
@Test
public void testSerializeAttributeNullValue() throws LdapException, IOException, ClassNotFoundException
{
    DefaultAttribute dsa = new DefaultAttribute( atDC );
    dsa.setUpId( "DomainComponent" );
    dsa.add( ( String ) null );

    DefaultAttribute dsaSer = deserializeValue( serializeValue( dsa ), atDC );
    assertEquals( dsa.toString(), dsaSer.toString() );
    assertEquals( "0.9.2342.19200300.100.1.25", dsaSer.getId() );
    assertEquals( "DomainComponent", dsaSer.getUpId() );
    assertNull( dsaSer.getString() );
    assertEquals( 1, dsaSer.size() );
    assertTrue( dsaSer.contains( ( String ) null ) );
    assertTrue( dsaSer.isHumanReadable() );
}
 
Example #19
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the serialization of a server attribute with a binary value
 */
@Test
public void testSerializeAttributeBinaryValue() throws LdapException, IOException, ClassNotFoundException
{
    DefaultAttribute dsa = new DefaultAttribute( atPwd );
    byte[] password = Strings.getBytesUtf8( "secret" );
    dsa.add( password );

    DefaultAttribute dsaSer = deserializeValue( serializeValue( dsa ), atPwd );
    assertEquals( dsa.toString(), dsaSer.toString() );
    assertEquals( "2.5.4.35", dsaSer.getId() );
    assertEquals( "userPassword", dsaSer.getUpId() );
    assertTrue( Arrays.equals( dsa.getBytes(), dsaSer.getBytes() ) );
    assertEquals( 1, dsaSer.size() );
    assertTrue( dsaSer.contains( password ) );
    assertFalse( dsaSer.isHumanReadable() );
}
 
Example #20
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method which creates an entry with 4 attributes.
 */
private Entry createEntry()
{
    try
    {
        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 );

        return entry;
    }
    catch ( LdapException ne )
    {
        // Do nothing
        return null;
    }
}
 
Example #21
Source File: SchemaElementImpl.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Return the extensions formated as Ldif lines
 *
 * @param id The attributeId : can be m-objectClassExtension or
 * m-attributeTypeExtension
 * @return The extensions formated as ldif lines
 * @throws org.apache.directory.api.ldap.model.exception.LdapException If the conversion goes wrong
 */
protected String extensionsToLdif( String id ) throws LdapException
{
    StringBuilder sb = new StringBuilder();

    Entry entry = new DefaultEntry();
    Attribute attribute = new DefaultAttribute( id );

    for ( String extension : extensions.keySet() )
    {
        attribute.add( extension );
    }

    sb.append( LdifUtils.convertAttributesToLdif( entry ) );

    return sb.toString();
}
 
Example #22
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for contains( String, byte[]... )
 */
@Test
public void testContainsStringByteArray() throws LdapException
{
    Entry entry = new DefaultEntry( exampleDn );

    assertFalse( entry.containsAttribute( "objectClass" ) );

    Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, ( byte[] ) null, BYTES2 );

    entry.add( attrPWD );

    assertTrue( entry.contains( "  userPASSWORD  ", BYTES1, BYTES2 ) );
    assertTrue( entry.contains( "  userPASSWORD  ", ( byte[] ) null ) );

    // We can search for byte[] using Strings. the strings will be converted to byte[]
    assertTrue( entry.contains( "  userPASSWORD  ", "ab", "b" ) );

    assertFalse( entry.contains( "  userPASSWORD  ", "ab", "b", "d" ) );
}
 
Example #23
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for get( String )
 */
@Test
public void testGet() throws LdapException
{
    Entry entry = new DefaultEntry( exampleDn );

    assertNull( entry.get( "objectClass" ) );

    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.add( attrOC, attrCN, attrSN, attrPWD );

    assertNotNull( entry.get( "  CN  " ) );
    Attribute attribute = entry.get( "cN" );

    assertEquals( attribute, attrCN );

    assertNull( entry.get( ( String ) null ) );
    assertNull( entry.get( "  " ) );
    assertNull( entry.get( "l" ) );
}
 
Example #24
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for hasObjectClass( String )
 */
@Test
public void testHasObjectClass() throws LdapException
{
    Entry entry = new DefaultEntry( exampleDn );

    assertFalse( entry.containsAttribute( "objectClass" ) );
    assertFalse( entry.hasObjectClass( "top" ) );

    entry.add( new DefaultAttribute( "objectClass", "top", "person" ) );

    assertTrue( entry.hasObjectClass( "top" ) );
    assertTrue( entry.hasObjectClass( "person" ) );
    assertFalse( entry.hasObjectClass( "inetorgperson" ) );
    assertFalse( entry.hasObjectClass( ( String ) null ) );
    assertFalse( entry.hasObjectClass( "" ) );
}
 
Example #25
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 #26
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for remove(String, byte[]... )
 */
@Test
public void testRemoveStringByteArrayArray() throws LdapException
{
    Entry entry = new DefaultEntry( exampleDn );

    Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, ( byte[] ) null, BYTES2 );

    entry.put( attrPWD );
    assertTrue( entry.remove( "userPassword", ( byte[] ) null ) );
    assertTrue( entry.remove( "userPassword", BYTES1, BYTES2 ) );
    assertFalse( entry.containsAttribute( "userPassword" ) );

    entry.add( "userPassword", BYTES1, ( byte[] ) null, BYTES2 );
    assertTrue( entry.remove( "userPassword", ( byte[] ) null ) );
    assertEquals( 2, entry.get( "userPassword" ).size() );
    assertTrue( entry.remove( "userPassword", BYTES1, BYTES3 ) );
    assertEquals( 1, entry.get( "userPassword" ).size() );
    assertTrue( Arrays.equals( BYTES2, entry.get( "userPassword" ).getBytes() ) );

    assertFalse( entry.remove( "userPassword", BYTES3 ) );
    assertFalse( entry.remove( "void", "whatever" ) );
}
 
Example #27
Source File: ModifyRequestImplTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test for inequality when only the number of mods are different.
 */
@Test
public void testNotEqualDiffModCount() throws LdapException
{
    ModifyRequestImpl req0 = getRequest();
    Attribute attr = new DefaultAttribute( "attr3" );
    attr.add( "val0" );
    attr.add( "val1" );
    attr.add( "val2" );
    Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
    req0.addModification( item );

    ModifyRequestImpl req1 = getRequest();

    assertFalse( req0.equals( req1 ) );
    assertFalse( req1.equals( req0 ) );
}
 
Example #28
Source File: AttributeUtilsTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the removing by modification of an existing attribute in an .
 * 
 * @throws LdapException
 */
@Test
public void testApplyModifyModificationRemoveAttribute() throws LdapException
{
    Entry entry = new DefaultEntry();
    entry.put( "cn", "test" );
    entry.put( "ou", "apache", "acme corp" );

    Attribute newOu = new DefaultAttribute( "ou" );

    Modification modification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, newOu );

    AttributeUtils.applyModification( entry, modification );

    assertEquals( 1, entry.size() );

    assertNotNull( entry.get( "cn" ) );
    assertNull( entry.get( "ou" ) );
}
 
Example #29
Source File: ApacheLdapProviderImpl.java    From ldapchai with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void writeBinaryAttribute( final String entryDN, final String attributeName, final byte[][] values, final boolean overwrite )
        throws ChaiUnavailableException, ChaiOperationException
{
    activityPreCheck();
    getInputValidator().writeBinaryAttribute( entryDN, attributeName, values, overwrite );

    try
    {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName( new Dn( entryDN ) );
        {
            final Modification modification = new DefaultModification();
            modification.setOperation( overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE );
            modification.setAttribute( new DefaultAttribute( attributeName, values ) );
            modifyRequest.addModification( modification );
        }
        final ModifyResponse response = connection.modify( modifyRequest );
        processResponse( response );
    }
    catch ( LdapException e )
    {
        throw ChaiOperationException.forErrorMessage( e.getMessage() );
    }
}
 
Example #30
Source File: LdifReader.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Parse an AttributeType/AttributeValue
 *
 * @param line The line to parse
 * @return the parsed Attribute
 */
public static Attribute parseAttributeValue( String line )
{
    int colonIndex = line.indexOf( ':' );

    if ( colonIndex != -1 )
    {
        String attributeType = line.substring( 0, colonIndex );
        Object attributeValue = parseSimpleValue( line, colonIndex );

        // Create an attribute
        if ( attributeValue instanceof String )
        {
            return new DefaultAttribute( attributeType, ( String ) attributeValue );
        }
        else
        {
            return new DefaultAttribute( attributeType, ( byte[] ) attributeValue );
        }
    }
    else
    {
        return null;
    }
}