Java Code Examples for org.apache.directory.api.ldap.model.entry.Entry#put()
The following examples show how to use
org.apache.directory.api.ldap.model.entry.Entry#put() .
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: AttributeUtilsTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 2
Source File: DefaultSchemaLoader.java From directory-ldap-api with Apache License 2.0 | 6 votes |
private Entry getEntry( LdapComparatorDescription comparatorDescription ) { Entry entry = new DefaultEntry(); entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_TOP_OC, MetaSchemaConstants.META_COMPARATOR_OC ); entry.put( MetaSchemaConstants.M_OID_AT, comparatorDescription.getOid() ); entry.put( MetaSchemaConstants.M_FQCN_AT, comparatorDescription.getFqcn() ); if ( comparatorDescription.getBytecode() != null ) { entry.put( MetaSchemaConstants.M_BYTECODE_AT, Base64.decode( comparatorDescription.getBytecode().toCharArray() ) ); } if ( comparatorDescription.getDescription() != null ) { entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, comparatorDescription.getDescription() ); } return entry; }
Example 3
Source File: SchemaAwareEntryTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 4
Source File: SchemaAwareEntryTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 5
Source File: SchemaElementImpl.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * @return The description as a ldif line * @throws org.apache.directory.api.ldap.model.exception.LdapException If the conversion goes wrong */ private String descToLdif() throws LdapException { if ( Strings.isEmpty( description ) ) { return ""; } else { Entry entry = new DefaultEntry(); Attribute attribute = new DefaultAttribute( "m-description", description ); entry.put( attribute ); return LdifUtils.convertAttributesToLdif( entry ); } }
Example 6
Source File: AttributeUtilsTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test the deletion of an attribute into an entry which contains the attribute * but without the value to be deleted */ @Test public void testApplyRemoveModificationFromEntryAttributeNotSameValue() throws LdapException { Entry entry = new DefaultEntry(); Attribute cn = new DefaultAttribute( "cn", "apache" ); entry.put( cn ); Attribute attr = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attr ); AttributeUtils.applyModification( entry, modification ); assertNotNull( entry.get( "cn" ) ); assertEquals( 1, entry.size() ); assertEquals( cn, entry.get( "cn" ) ); }
Example 7
Source File: AttributeUtilsTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test the deletion of an attribute into an entry which does not contain the attribute */ @Test public void testApplyRemoveModificationFromEntryAttributeNotPresent() throws LdapException { Entry entry = new DefaultEntry(); Attribute dc = new DefaultAttribute( "dc", "apache" ); entry.put( dc ); Attribute cn = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, cn ); AttributeUtils.applyModification( entry, modification ); assertNull( entry.get( "cn" ) ); assertNotNull( entry.get( "dc" ) ); assertEquals( 1, entry.size() ); assertEquals( dc, entry.get( "dc" ) ); }
Example 8
Source File: AttributesFactory.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Convert a Syntax instance into an Entry * * @param syntax The LdapSytax to convert * @param schema The schema containing this Syntax * @param schemaManager The SchemaManager * @return And entry defining a LdapSyntax * @throws LdapException If the conversion failed */ public Entry convert( LdapSyntax syntax, Schema schema, SchemaManager schemaManager ) throws LdapException { Entry entry = new DefaultEntry( schemaManager ); entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SYNTAX_OC ); entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() ); entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) ); injectCommon( syntax, entry, schemaManager ); return entry; }
Example 9
Source File: AttributesFactory.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * * Converts a NameForm into an Entry * * @param nameForm The NameForm to convert * @param schema The schema containing this NameForm * @param schemaManager The SchemaManager * @return The converted NameForm */ public Entry convert( NameForm nameForm, Schema schema, SchemaManager schemaManager ) { Entry entry = new DefaultEntry( schemaManager ); entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" ); entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() ); entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) ); return entry; }
Example 10
Source File: AttributesFactory.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Converts a DitContentRule into an Entry * * @param dITContentRule The DitContentRule to convert * @param schema The schema containing this DitContentRule * @param schemaManager The SchemaManager * @return The converted DitContentRule */ public Entry convert( DitContentRule dITContentRule, Schema schema, SchemaManager schemaManager ) { Entry entry = new DefaultEntry( schemaManager ); entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" ); entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() ); entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) ); return entry; }
Example 11
Source File: AttributesFactory.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Converts a DitStructureRule into an Entry * * @param ditStructureRule The DitStructureRule to convert * @param schema The schema containing this DitStructureRule * @param schemaManager The SchemaManager * @return The converted DitStructureRule */ public Entry convert( DitStructureRule ditStructureRule, Schema schema, SchemaManager schemaManager ) { Entry entry = new DefaultEntry( schemaManager ); entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" ); entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() ); entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) ); return entry; }
Example 12
Source File: AttributesFactory.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Converts a MatchingRule into an Entry * * @param matchingRule The MatchingRule to convert * @param schema The schema containing this ObjectClass * @param schemaManager The SchemaManager * @return The converted MatchingRule * @throws LdapException If the conversion failed */ public Entry convert( MatchingRule matchingRule, Schema schema, SchemaManager schemaManager ) throws LdapException { Entry entry = new DefaultEntry( schemaManager ); entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_MATCHING_RULE_OC ); entry.put( MetaSchemaConstants.M_SYNTAX_AT, matchingRule.getSyntaxOid() ); entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() ); entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) ); injectCommon( matchingRule, entry, schemaManager ); return entry; }
Example 13
Source File: AttributesFactory.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Convert a LdapComparator instance into an Entry * * @param oid The LdapComparator's OID * @param comparator The LdapComparator to convert * @param schema The schema containing this Comparator * @param schemaManager The SchemaManager * @return An Entry defining a LdapComparator */ public Entry convert( String oid, LdapComparator<? super Object> comparator, Schema schema, SchemaManager schemaManager ) { Entry entry = new DefaultEntry( schemaManager ); entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_COMPARATOR_OC ); entry.put( MetaSchemaConstants.M_OID_AT, oid ); entry.put( MetaSchemaConstants.M_FQCN_AT, comparator.getClass().getName() ); entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() ); entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) ); return entry; }
Example 14
Source File: AttributesFactory.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Convert a Normalizer instance into an Entry * * @param oid The Normalizer's OID * @param normalizer The Normalizer to convert * @param schema The schema containing this Normalizer * @param schemaManager The SchemaManager * @return An Entry defining a Normalizer */ public Entry convert( String oid, Normalizer normalizer, Schema schema, SchemaManager schemaManager ) { Entry entry = new DefaultEntry( schemaManager ); entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_NORMALIZER_OC ); entry.put( MetaSchemaConstants.M_OID_AT, oid ); entry.put( MetaSchemaConstants.M_FQCN_AT, normalizer.getClass().getName() ); entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() ); entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) ); return entry; }
Example 15
Source File: AttributesFactory.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Converts a Schema to an Entry * * @param schema The Schema to convert * @param schemaManager The SchemaManager * @return An Entry containing the converted Schema * @throws LdapException If the conversion failed */ public Entry convert( Schema schema, SchemaManager schemaManager ) throws LdapException { Entry entry = new DefaultEntry( schemaManager ); entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SCHEMA_OC ); entry.put( SchemaConstants.CN_AT, schema.getSchemaName() ); entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() ); entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) ); if ( schema.isDisabled() ) { entry.put( MetaSchemaConstants.M_DISABLED_AT, "TRUE" ); } String[] dependencies = schema.getDependencies(); if ( dependencies != null && dependencies.length > 0 ) { Attribute attr = new DefaultAttribute( schemaManager.getAttributeType( MetaSchemaConstants.M_DEPENDENCIES_AT ) ); for ( String dependency : dependencies ) { attr.add( dependency ); } entry.put( attr ); } return entry; }
Example 16
Source File: SchemaAwareEntryTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test method for remove( EntryAttribute... ) */ @Test public void testRemoveEntryAttributeArray() 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 ); List<Attribute> removed = entry.remove( attrSN, attrPWD ); assertEquals( 2, removed.size() ); assertEquals( 2, entry.size() ); assertTrue( removed.contains( attrSN ) ); assertTrue( removed.contains( attrPWD ) ); assertTrue( entry.contains( "objectClass", "top", "person" ) ); assertTrue( entry.contains( "cn", "test1", "test2" ) ); assertFalse( entry.containsAttribute( "sn" ) ); assertFalse( entry.containsAttribute( "userPassword" ) ); removed = entry.remove( attrSN, attrPWD ); assertEquals( 0, removed.size() ); }
Example 17
Source File: SchemaAwareEntryTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test method for put( EntryAttribute... ) */ @Test public void testPutEntryAttributeArray() 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 ); List<Attribute> removed = entry.put( attrOC, attrCN, attrSN, attrPWD ); assertEquals( 4, entry.size() ); assertEquals( 0, removed.size() ); assertTrue( entry.containsAttribute( "ObjectClass" ) ); assertTrue( entry.containsAttribute( "CN" ) ); assertTrue( entry.containsAttribute( " sn " ) ); assertTrue( entry.containsAttribute( "userPassword" ) ); Attribute attrCN2 = new DefaultAttribute( "cn", "test3", "test4" ); removed = entry.put( attrCN2 ); assertEquals( 4, entry.size() ); assertEquals( 1, removed.size() ); assertTrue( entry.containsAttribute( "CN" ) ); assertTrue( entry.contains( "cn", "test3", "test4" ) ); }
Example 18
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * Check that all the attribute's values which are Human Readable can be transformed * to valid String if they are stored as byte[], and that non Human Readable attributes * stored as String can be transformed to byte[] */ private void assertHumanReadable( Entry entry ) throws LdapException { boolean isModified = false; Entry clonedEntry = null; // Loops on all attributes for ( Attribute attribute : entry ) { AttributeType attributeType = attribute.getAttributeType(); // If the attributeType is H-R, check all of its values if ( attributeType.getSyntax().isHumanReadable() ) { isModified = checkHumanReadable( attribute ); } else { isModified = checkNotHumanReadable( attribute ); } // If we have a returned attribute, then we need to store it // into a new entry if ( isModified ) { if ( clonedEntry == null ) { clonedEntry = entry.clone(); } // Switch the attributes clonedEntry.put( attribute ); isModified = false; } } if ( clonedEntry != null ) { entry = clonedEntry; } }
Example 19
Source File: LdifAttributesReader.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Parse an AttributeType/AttributeValue * * @param schemaManager The SchemaManager * @param entry The entry where to store the value * @param line The line to parse * @param lowerLine The same line, lowercased * @throws LdapLdifException If anything goes wrong */ private void parseEntryAttribute( SchemaManager schemaManager, Entry entry, String line, String lowerLine ) throws LdapLdifException { int colonIndex = line.indexOf( ':' ); String attributeName = lowerLine.substring( 0, colonIndex ); AttributeType attributeType = null; // We should *not* have a Dn twice if ( "dn".equals( attributeName ) ) { LOG.error( I18n.err( I18n.ERR_13400_ENTRY_WITH_TWO_DNS ) ); throw new LdapLdifException( I18n.err( I18n.ERR_13439_LDIF_ENTRY_WITH_TWO_DNS ) ); } if ( schemaManager != null ) { attributeType = schemaManager.getAttributeType( attributeName ); if ( attributeType == null ) { String msg = I18n.err( I18n.ERR_13475_UNKNOWN_ATTRIBUTETYPE, attributeName ); LOG.error( msg ); throw new LdapLdifException( msg ); } } Object attributeValue = parseValue( attributeName, line, colonIndex ); // Update the entry Attribute attribute; 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_13460_BAD_ATTRIBUTE ), le ); } } } else { try { if ( attributeValue instanceof String ) { attribute.add( ( String ) attributeValue ); } else { attribute.add( ( byte[] ) attributeValue ); } } catch ( LdapInvalidAttributeValueException liave ) { throw new LdapLdifException( liave.getMessage(), liave ); } } }
Example 20
Source File: SchemaAwareEntryTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Test method for equals() */ @Test public void testEqualsObject() throws LdapException { Entry entry1 = new DefaultEntry(); Entry entry2 = new DefaultEntry(); assertEquals( entry1, entry2 ); entry1.setDn( exampleDn ); assertNotSame( entry1, entry2 ); entry2.setDn( exampleDn ); assertEquals( entry1, entry2 ); 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 ); entry1.put( attrOC, attrCN, attrSN, attrPWD ); entry2.put( attrOC, attrCN, attrSN ); assertNotSame( entry1, entry2 ); entry2.put( attrPWD ); assertEquals( entry1, entry2 ); Attribute attrL1 = new DefaultAttribute( "l", "Paris", "New-York" ); Attribute attrL2 = new DefaultAttribute( "l", "Paris", "Tokyo" ); entry1.put( attrL1 ); entry2.put( attrL1 ); assertEquals( entry1, entry2 ); entry1.add( "l", "London" ); assertNotSame( entry1, entry2 ); entry2.add( attrL2 ); assertNotSame( entry1, entry2 ); entry1.clear(); entry2.clear(); assertEquals( entry1, entry2 ); }