org.apache.directory.api.ldap.model.entry.Attribute Java Examples
The following examples show how to use
org.apache.directory.api.ldap.model.entry.Attribute.
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 |
/** * 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 #2
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 #3
Source File: DefaultSchemaLoader.java From directory-ldap-api with Apache License 2.0 | 6 votes |
private void loadAttributeTypes( Attribute attributeTypes ) throws LdapException { if ( attributeTypes == null ) { return; } for ( Value value : attributeTypes ) { String desc = value.getString(); try { AttributeType attributeType = AT_DESCR_SCHEMA_PARSER.parse( desc ); updateSchemas( attributeType ); } catch ( ParseException pe ) { throw new LdapException( pe ); } } }
Example #4
Source File: ModifyRequestImplTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 #5
Source File: SchemaAwareEntryTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test method for contains( String, String... ) */ @Test public void testContainsStringStringArray() throws LdapException { Entry entry = new DefaultEntry( exampleDn ); assertFalse( entry.containsAttribute( "objectClass" ) ); Attribute attrOC = new DefaultAttribute( "objectClass", "top", "person" ); Attribute attrCN = new DefaultAttribute( "cn", "test1", "test2" ); Attribute attrSN = new DefaultAttribute( "sn", "Test1", "Test2", ( String ) null ); Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, BYTES2 ); entry.add( attrOC, attrCN, attrSN, attrPWD ); assertTrue( entry.contains( "OBJECTCLASS", "top", "person" ) ); assertTrue( entry.contains( " cn ", "test1", "test2" ) ); assertTrue( entry.contains( "Sn", "Test1", "Test2", ( String ) null ) ); assertTrue( entry.contains( " userPASSWORD ", "ab", "b" ) ); assertFalse( entry.contains( "OBJECTCLASS", "PERSON" ) ); assertFalse( entry.contains( " cn ", "test1", "test3" ) ); assertFalse( entry.contains( "Sn", "Test" ) ); assertFalse( entry.contains( " userPASSWORD ", ( String ) null ) ); }
Example #6
Source File: AttributeUtilsTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 #7
Source File: LdapDataProvider.java From directory-fortress-core with Apache License 2.0 | 6 votes |
/** * Given a collection of {@link java.util.Properties}, convert to raw data name-value format and load into ldap * modification set in preparation for ldap add. * * @param props contains {@link java.util.Properties} targeted for adding to ldap. * @param entry contains ldap entry to pull attrs from. * @param attrName contains the name of the ldap attribute to be added. * @throws LdapException If we weren't able to add the properies into the entry */ protected void loadProperties( Properties props, Entry entry, String attrName ) throws LdapException { if ( ( props != null ) && ( props.size() > 0 ) ) { Attribute attr = new DefaultAttribute( attrName ); for ( Enumeration<?> e = props.propertyNames(); e.hasMoreElements(); ) { // This LDAP attr is stored as a name-value pair separated by a ':'. String key = ( String ) e.nextElement(); String val = props.getProperty( key ); String prop = key + GlobalIds.PROP_SEP + val; attr.add( prop ); } if ( attr.size() != 0 ) { entry.add( attr ); } } }
Example #8
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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: LdifReaderTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
private void testReaderAttrIdCaseInsensitive( String ldif ) throws Exception { LdifReader reader = new LdifReader(); List<LdifEntry> entries = reader.parseLdif( ldif ); assertNotNull( entries ); reader.close(); LdifEntry entry = entries.get( 0 ); assertTrue( entry.isChangeModify() ); assertEquals( "dc=example,dc=com", entry.getDn().getName() ); List<Modification> mods = entry.getModifications(); assertTrue( mods.size() == 1 ); Attribute attr = mods.get( 0 ).getAttribute(); assertTrue( attr.getId().equals( "administrativerole" ) ); assertEquals( attr.getString(), "accessControlSpecificArea" ); }
Example #10
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 #11
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 #12
Source File: DefaultSchemaLoader.java From directory-ldap-api with Apache License 2.0 | 6 votes |
private void loadMatchingRuleUses( Attribute matchingRuleUses ) throws LdapException { if ( matchingRuleUses == null ) { return; } for ( Value value : matchingRuleUses ) { String desc = value.getString(); try { MatchingRuleUse matchingRuleUse = MRU_DESCR_SCHEMA_PARSER.parse( desc ); updateSchemas( matchingRuleUse ); } catch ( ParseException pe ) { throw new LdapException( pe ); } } }
Example #13
Source File: LdapBackend.java From mxisd with GNU Affero General Public License v3.0 | 6 votes |
public List<String> getAttributes(Entry entry, String attName) { List<String> values = new ArrayList<>(); javax.naming.directory.Attribute att = AttributeUtils.toAttributes(entry).get(attName); if (att == null) { return values; } try { NamingEnumeration<?> list = att.getAll(); while (list.hasMore()) { values.add(list.next().toString()); } } catch (NamingException e) { log.warn("Error while processing LDAP attribute {}, result could be incomplete!", attName, e); } return values; }
Example #14
Source File: DefaultPartitionNexus.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public void registerSupportedExtensions( Set<String> extensionOids ) throws LdapException { Attribute supportedExtension = rootDse.get( SchemaConstants.SUPPORTED_EXTENSION_AT ); if ( supportedExtension == null ) { rootDse.put( SchemaConstants.SUPPORTED_EXTENSION_AT, ( String ) null ); supportedExtension = rootDse.get( SchemaConstants.SUPPORTED_EXTENSION_AT ); } for ( String extensionOid : extensionOids ) { supportedExtension.add( extensionOid ); } }
Example #15
Source File: ApacheDSUtil.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
public static AttributeType addBinaryAttributeToSchema(Attribute attribute,SchemaManager schemaManager) throws LdapException { String newOID = generateRandomOID(schemaManager); MutableAttributeType at = new MutableAttributeType(newOID); // base new attributes on javaSerializedData AttributeType uidAT = schemaManager.getAttributeType("1.3.6.1.4.1.42.2.27.4.1.8"); at.setNames(attribute.getId()); at.setSyntax(uidAT.getSyntax()); at.setSingleValued(false); at.setSchemaName(uidAT.getSchemaName()); at.setSpecification(uidAT.getSpecification()); at.setUsage(uidAT.getUsage()); LOG.warn("Creating dynamic schema entry : '{}' {}", at.getName(), at.getOid()); schemaManager.add(at); return at; }
Example #16
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 #17
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 #18
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Creates a new attribute which contains the values representing the union * of two attributes. If one attribute is null then the resultant attribute * returned is a copy of the non-null attribute. If both are null then we * cannot determine the attribute ID and an {@link IllegalArgumentException} * is raised. * * @param attr0 the first attribute * @param attr1 the second attribute * @return a new attribute with the union of values from both attribute * arguments * @throws LdapException if there are problems accessing attribute values */ public static Attribute getUnion( Attribute attr0, Attribute attr1 ) throws LdapException { if ( attr0 == null && attr1 == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_465 ) ); } else if ( attr0 == null ) { return attr1.clone(); } else if ( attr1 == null ) { return attr0.clone(); } else if ( !attr0.getAttributeType().equals( attr1.getAttributeType() ) ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_466 ) ); } Attribute attr = attr0.clone(); for ( Value<?> value : attr1 ) { attr.add( value ); } return attr; }
Example #19
Source File: AddRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with an Attr elements with value */ @Test public void testRequestWith1AttrWithValue() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_with_value.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest(); Entry entry = addRequest.getEntry(); assertEquals( 1, entry.size() ); // Getting the Attribute Iterator<Attribute> attributeIterator = entry.iterator(); Attribute attribute = attributeIterator.next(); assertEquals( "objectclass", attribute.getUpId() ); // Getting the Value Iterator<Value> valueIterator = attribute.iterator(); assertTrue( valueIterator.hasNext() ); Value value = valueIterator.next(); assertEquals( "top", value.getString() ); }
Example #20
Source File: SearchResultEntryTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a response with 1 Attr 2 Value */ @Test public void testResponseWith1Attr2Value() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( SearchResultEntryTest.class.getResource( "response_with_1_attr_2_value.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } SearchResultEntry searchResultEntry = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse() .getDecorated() ) .getCurrentSearchResultEntry(); Entry entry = searchResultEntry.getEntry(); assertEquals( 1, entry.size() ); Iterator<Attribute> attributeIterator = entry.iterator(); Attribute attribute = attributeIterator.next(); assertEquals( "objectclass", attribute.getUpId() ); assertEquals( 2, attribute.size() ); Iterator<Value> valueIterator = attribute.iterator(); assertTrue( valueIterator.hasNext() ); Value value = valueIterator.next(); assertEquals( "top", value.getString() ); assertTrue( valueIterator.hasNext() ); value = valueIterator.next(); assertEquals( "domain", value.getString() ); assertFalse( valueIterator.hasNext() ); }
Example #21
Source File: AttributeUtilsTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * test the addition by modification of an attribute in an empty entry. * * As we are replacing a non existing attribute, it should be added. * * @throws LdapException */ @Test public void testApplyModifyModificationFromEmptyEntry() throws LdapException { Entry entry = new DefaultEntry(); Attribute attr = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attr ); AttributeUtils.applyModification( entry, modification ); assertNotNull( entry.get( "cn" ) ); assertEquals( 1, entry.size() ); }
Example #22
Source File: SchemaAwareLdifReaderTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
@Test public void testLdifParserBase64() throws Exception { String ldif = "#comment\n" + "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" + "cn:: RW1tYW51ZWwgTMOpY2hhcm55\n" + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1\n" + "serviceType: http\n" + "userPassword:\n" + "httpHeaders:\n" + "startupOptions:"; LdifReader reader = new LdifReader( schemaManager ); List<LdifEntry> entries = reader.parseLdif( ldif ); reader.close(); assertNotNull( entries ); LdifEntry entry = entries.get( 0 ); assertTrue( entry.isLdifContent() ); assertEquals( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", entry.getDn().getName() ); Attribute attr = entry.get( "cn" ); assertTrue( attr.contains( "Emmanuel L\u00e9charny" ) ); attr = entry.get( "objectclass" ); assertTrue( attr.contains( "top" ) ); assertTrue( attr.contains( "apApplication" ) ); attr = entry.get( "displayname" ); assertTrue( attr.contains( "app1" ) ); attr = entry.get( "userPassword" ); assertEquals( "", attr.get().getString() ); }
Example #23
Source File: SchemaAwareEntryTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test method for hashcode() */ @Test public void testHashCode() throws LdapException, LdapException { Entry entry1 = new DefaultEntry( exampleDn ); Entry entry2 = new DefaultEntry( exampleDn ); assertEquals( entry1.hashCode(), entry2.hashCode() ); entry2.setDn( new Dn( "ou=system,dc=com" ) ); assertNotSame( entry1.hashCode(), entry2.hashCode() ); entry2.setDn( exampleDn ); assertEquals( entry1.hashCode(), entry2.hashCode() ); 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.add( attrOC, attrCN, attrSN, attrPWD ); entry2.add( attrOC, attrCN, attrSN, attrPWD ); assertEquals( entry1.hashCode(), entry2.hashCode() ); Entry entry3 = new DefaultEntry( exampleDn ); entry3.add( attrOC, attrSN, attrCN, attrPWD ); assertEquals( entry1.hashCode(), entry3.hashCode() ); }
Example #24
Source File: LdapBackend.java From mxisd with GNU Affero General Public License v3.0 | 5 votes |
public Optional<String> getAttribute(Entry entry, String attName) { Attribute attribute = entry.get(attName); if (attribute == null) { return Optional.empty(); } String value = attribute.get().toString(); if (StringUtils.isBlank(value)) { log.info("DN {}: empty attribute {}, skipping", attName); return Optional.empty(); } return Optional.of(value); }
Example #25
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Check the entry attributes syntax, using the syntaxCheckers */ private void assertSyntaxes( Entry entry ) throws LdapException { // First, loop on all attributes for ( Attribute attribute : entry ) { AttributeType attributeType = attribute.getAttributeType(); SyntaxChecker syntaxChecker = attributeType.getSyntax().getSyntaxChecker(); if ( syntaxChecker instanceof OctetStringSyntaxChecker ) { // This is a speedup : no need to check the syntax of any value // if all the syntaxes are accepted... continue; } // Then loop on all values for ( Value<?> value : attribute ) { if ( value.isSchemaAware() ) { // No need to validate something which is already ok continue; } try { syntaxChecker.assertSyntax( value.getValue() ); } catch ( Exception ne ) { String message = I18n.err( I18n.ERR_280, value.getString(), attribute.getUpId() ); LOG.info( message ); throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, message ); } } } }
Example #26
Source File: SearchResultEntryTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a response with 1 Attr 0 Value */ @Test public void testResponseWith1Attr0Value() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( SearchResultEntryTest.class.getResource( "response_with_1_attr_0_value.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } SearchResultEntry searchResultEntry = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse() .getDecorated() ) .getCurrentSearchResultEntry(); Entry entry = searchResultEntry.getEntry(); assertEquals( 1, entry.size() ); Iterator<Attribute> attributeIterator = entry.iterator(); Attribute attribute = attributeIterator.next(); assertEquals( "dc", attribute.getUpId() ); }
Example #27
Source File: SchemaAwareEntryTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test method for add( EntryAttribute... ) */ @Test public void testAddEntryAttributeArray() throws LdapException { Entry entry = createEntry(); assertEquals( 4, entry.size() ); assertTrue( entry.containsAttribute( "ObjectClass" ) ); assertTrue( entry.containsAttribute( "CN" ) ); assertTrue( entry.containsAttribute( " sn " ) ); assertTrue( entry.containsAttribute( "userPassword" ) ); Attribute attr = entry.get( "objectclass" ); assertEquals( 2, attr.size() ); Attribute attrCN2 = new DefaultAttribute( "cn", "test1", "test3" ); entry.add( attrCN2 ); assertEquals( 4, entry.size() ); attr = entry.get( "cn" ); assertEquals( 3, attr.size() ); assertTrue( attr.contains( "test1", "test2", "test3" ) ); // Check adding some byte[] values (they will not be transformed to Strings) attrCN2.clear(); attrCN2.add( BYTES1, BYTES2 ); entry.add( attrCN2 ); assertEquals( 4, entry.size() ); attr = entry.get( "cn" ); assertEquals( 3, attr.size() ); assertTrue( attr.contains( "test1", "test2", "test3" ) ); assertFalse( attr.contains( "ab", "b" ) ); }
Example #28
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
private void assertRdn( Dn dn, Entry entry ) throws LdapException { for ( Ava atav : dn.getRdn() ) { Attribute attribute = entry.get( atav.getNormType() ); if ( ( attribute == null ) || ( !attribute.contains( atav.getNormValue() ) ) ) { String message = I18n.err( I18n.ERR_62, dn, atav.getType() ); LOG.error( message ); throw new LdapSchemaViolationException( ResultCodeEnum.NOT_ALLOWED_ON_RDN, message ); } } }
Example #29
Source File: SchemaAwareModificationSerializationTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
@Test public void testSerializationModificationADD() throws ClassNotFoundException, IOException, LdapInvalidAttributeValueException { Attribute attribute = new DefaultAttribute( "cn", cnAT ); attribute.add( "test1", "test2" ); DefaultModification mod = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attribute ); Modification modSer = deserializeValue( serializeValue( mod ) ); assertEquals( mod, modSer ); }
Example #30
Source File: LdifAnonymizerTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
@Test public void testAnonymizerModifyBinaryOptionAttribute() throws LdapException, IOException { String ldif = "dn: cn=Acme certificate,o=Acme,c=US,ou=IT Infrastructure,o=acme.com\n" + "changetype: modify\n" + "replace: certificateRevocationList;binary\n" + "certificateRevocationList;binary::YmxhaCBibGFo\n" + "-"; LdifAnonymizer anonymizer = new LdifAnonymizer( schemaManager ); anonymizer.addNamingContext( "o=acme.com" ); String result = anonymizer.anonymize( ldif ); List<LdifEntry> entries = ldifReader.parseLdif( result ); assertEquals( 1, entries.size() ); LdifEntry entry = entries.get( 0 ); assertTrue( entry.isChangeModify() ); assertEquals( 1, entry.getModifications().size() ); Modification modification = entry.getModifications().get( 0 ); assertEquals( ModificationOperation.REPLACE_ATTRIBUTE, modification.getOperation() ); Attribute attribute = modification.getAttribute(); assertEquals( "certificateRevocationList;binary", attribute.getUpId() ); assertEquals( 1, attribute.size() ); for ( Value value : attribute ) { String str = value.getString(); // We can only test the length and the fact the values are not equal (as the vale has been anonymized) assertNotSame( 0, value.length() ); assertEquals( str.length(), value.length() ); } }