本文整理汇总了Java中org.apache.directory.api.ldap.model.entry.Modification.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Modification.getAttribute方法的具体用法?Java Modification.getAttribute怎么用?Java Modification.getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.directory.api.ldap.model.entry.Modification
的用法示例。
在下文中一共展示了Modification.getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateServerModification
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
@Test
public void testCreateServerModification() throws LdapException
{
Attribute attribute = new DefaultAttribute( "cn", cnAT );
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" ) );
}
示例2: testCreateServerModification
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
@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" ) );
}
示例3: processModificationsBeforeUpdate
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
private Modification[] processModificationsBeforeUpdate(List<Modification> modifications) {
Modification[] out = new Modification[modifications.size()];
int i = 0;
for (final Modification modification: modifications) {
if (modification.getAttribute() != null && modification.getAttribute().get() != null) {
Value<?> val = modification.getAttribute().get();
if (val instanceof GuardedStringValue) {
((GuardedStringValue)val).getGuardedStringValue().access(new GuardedString.Accessor() {
@Override
public void access(char[] clearChars) {
DefaultAttribute attr = new DefaultAttribute( modification.getAttribute().getId(), new String(clearChars));
modification.setAttribute(attr);
}
});
}
}
out[i] = modification;
i++;
}
return out;
}
示例4: testRequestWith1Modification
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
/**
* Test parsing of a request with a Modification element
* @throws NamingException
*/
@Test
public void testRequestWith1Modification() throws LdapException
{
Dsmlv2Parser parser = null;
try
{
parser = newParser();
parser.setInput( ModifyRequestTest.class.getResource( "request_with_1_modification.xml" ).openStream(),
"UTF-8" );
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
Collection<Modification> modifications = modifyRequest.getModifications();
assertEquals( 1, modifications.size() );
Modification modification = modifications.iterator().next();
assertEquals( ModificationOperation.ADD_ATTRIBUTE, modification.getOperation() );
Attribute attribute = modification.getAttribute();
assertEquals( "directreport", attribute.getId() );
assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get().getValue() );
}
示例5: testRequestWith1ModificationBase64Value
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
/**
* Test parsing of a request with a Modification element with Base64 Value
* @throws NamingException
*/
@Test
public void testRequestWith1ModificationBase64Value() throws LdapException
{
Dsmlv2Parser parser = null;
try
{
parser = newParser();
parser.setInput( ModifyRequestTest.class.getResource( "request_with_1_modification_base64_value.xml" )
.openStream(), "UTF-8" );
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
Collection<Modification> modifications = modifyRequest.getModifications();
assertEquals( 1, modifications.size() );
Modification modification = modifications.iterator().next();
Attribute attribute = modification.getAttribute();
assertEquals( ModificationOperation.ADD_ATTRIBUTE, modification.getOperation() );
assertEquals( "directreport", attribute.getId() );
String expected = new String( new byte[]
{ 'c', 'n', '=', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', 'L', ( byte ) 0xc3, ( byte ) 0xa9, 'c', 'h',
'a', 'r', 'n', 'y', ',', ' ', 'o', 'u', '=', 'p', 'e', 'o', 'p', 'l', 'e', ',', ' ', 'd', 'c', '=',
'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', ' ', 'd', 'c', '=', 'c', 'o', 'm' }, StandardCharsets.UTF_8 );
assertEquals( expected, attribute.get().getValue() );
}
示例6: testRequestWithModificationWithoutValue
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
/**
* Test parsing of a request with a Modification element without Value element
* @throws NamingException
*/
@Test
public void testRequestWithModificationWithoutValue() throws LdapException
{
Dsmlv2Parser parser = null;
try
{
parser = newParser();
parser.setInput( ModifyRequestTest.class.getResource( "request_with_modification_without_value.xml" )
.openStream(), "UTF-8" );
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
Collection<Modification> modifications = modifyRequest.getModifications();
assertEquals( 1, modifications.size() );
Modification modification = modifications.iterator().next();
assertEquals( ModificationOperation.ADD_ATTRIBUTE, modification.getOperation() );
Attribute attribute = modification.getAttribute();
assertEquals( "directreport", attribute.getId() );
assertEquals( 0, attribute.size() );
}
示例7: testRequestWithModificationWith2Values
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
/**
* Test parsing of a request with a Modification element
* @throws NamingException
*/
@Test
public void testRequestWithModificationWith2Values() throws LdapException
{
Dsmlv2Parser parser = null;
try
{
parser = newParser();
parser.setInput( ModifyRequestTest.class.getResource( "request_with_modification_with_2_values.xml" )
.openStream(), "UTF-8" );
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
Collection<Modification> modifications = modifyRequest.getModifications();
assertEquals( 1, modifications.size() );
Modification modification = modifications.iterator().next();
assertEquals( ModificationOperation.ADD_ATTRIBUTE, modification.getOperation() );
Attribute attribute = modification.getAttribute();
assertEquals( "directreport", attribute.getId() );
assertEquals( 2, attribute.size() );
assertTrue( attribute.contains( "CN=John Smith, DC=microsoft, DC=com" ) );
assertTrue( attribute.contains( "CN=Steve Jobs, DC=apple, DC=com" ) );
}
示例8: testRequestWithModificationWithEmptyValue
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
/**
* Test parsing of a request with a Modification element with an empty value
* @throws NamingException
*/
@Test
public void testRequestWithModificationWithEmptyValue() throws LdapException
{
Dsmlv2Parser parser = null;
try
{
parser = newParser();
parser.setInput( ModifyRequestTest.class.getResource( "request_with_modification_with_empty_value.xml" )
.openStream(), "UTF-8" );
parser.parse();
}
catch ( Exception e )
{
fail( e.getMessage() );
}
ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest();
Collection<Modification> modifications = modifyRequest.getModifications();
assertEquals( 1, modifications.size() );
Modification modification = modifications.iterator().next();
assertEquals( ModificationOperation.ADD_ATTRIBUTE, modification.getOperation() );
Attribute attribute = modification.getAttribute();
assertEquals( "directreport", attribute.getId() );
assertEquals( 1, attribute.size() );
assertEquals( "", attribute.get().getValue() );
}
示例9: testLdifEntryChangeTypeModifySimple
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
/**
* Test a Modify changeType LdifEntry with no control
*/
@Test
public void testLdifEntryChangeTypeModifySimple() throws Exception
{
String ldif =
"changetype: modify\n" +
"add: cn\n" +
"cn: v1\n" +
"cn: v2\n" +
"-";
LdifEntry ldifEntry = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldif );
assertNotNull( ldifEntry );
assertEquals( ChangeType.Modify, ldifEntry.getChangeType() );
assertNull( ldifEntry.getEntry() );
assertEquals( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldifEntry.getDn().getName() );
assertFalse( ldifEntry.hasControls() );
assertTrue( ldifEntry.isLdifChange() );
// Check the modification
assertNotNull( ldifEntry.getModifications() );
for ( Modification modification : ldifEntry.getModifications() )
{
assertEquals( ModificationOperation.ADD_ATTRIBUTE, modification.getOperation() );
Attribute attribute = modification.getAttribute();
assertNotNull( attribute );
assertEquals( "cn", attribute.getId() );
assertTrue( attribute.contains( "v1", "v2" ) );
}
}
示例10: testLdifEntryChangeTypeModifyNoAttribute
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
/**
* Test a Modify changeType LdifEntry with no attributes
*/
@Test
public void testLdifEntryChangeTypeModifyNoAttribute() throws Exception
{
String ldif =
"changetype: modify\n" +
"add: cn\n" +
"-";
LdifEntry ldifEntry = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldif );
assertNotNull( ldifEntry );
assertEquals( ChangeType.Modify, ldifEntry.getChangeType() );
assertNull( ldifEntry.getEntry() );
assertEquals( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldifEntry.getDn().getName() );
assertFalse( ldifEntry.hasControls() );
assertTrue( ldifEntry.isLdifChange() );
// Check the modification
assertNotNull( ldifEntry.getModifications() );
for ( Modification modification : ldifEntry.getModifications() )
{
assertEquals( ModificationOperation.ADD_ATTRIBUTE, modification.getOperation() );
Attribute attribute = modification.getAttribute();
assertNotNull( attribute );
assertEquals( "cn", attribute.getId() );
assertNotNull( attribute.get() );
assertTrue( attribute.get().isNull() );
}
}
示例11: testAnonymizeModify
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
@Test
public void testAnonymizeModify() throws Exception
{
String ldif =
"dn: [email protected],ou=Email,ou=Services,o=acme,dc=com\n" +
"changetype: modify\n" +
"replace: cn\n" +
"cn::QUNNRSBJbmMuIExlZ2FsIFRlYW0=\n" +
"-";
LdifAnonymizer anonymizer = new LdifAnonymizer( schemaManager );
anonymizer.addNamingContext( "o=acm,dc=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( "cn", attribute.getUpId() );
assertEquals( 1, attribute.size() );
String value = attribute.getString();
// We can only test the length and the fact the values are not equal (as the value has been anonymized)
assertEquals( "AAAAAAAAAAAAAAAAAAAA".length(), value.length() );
assertEquals( "AAAAAAAAAAAAAAAAAAAA", value );
}
示例12: testAnonymizerModifyBinaryOptionAttribute
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
@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.getValue();
// 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() );
}
}
示例13: toServerModification
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
/**
* Convert a Modification to an instance of a ServerModification object.
*
* @param modificationImpl the modification instance to convert
* @param attributeType the associated attributeType
* @return a instance of a ServerModification object
*/
private static Modification toServerModification( Modification modification, AttributeType attributeType )
throws LdapException
{
Modification serverModification = new DefaultModification(
modification.getOperation(),
new DefaultAttribute( attributeType, modification.getAttribute() ) );
return serverModification;
}
示例14: getModificationItem
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
/**
* Utility method to extract a modification item from an array of modifications.
*
* @param mods the array of ModificationItems to extract the Attribute from.
* @param type the attributeType spec of the Attribute to extract
* @return the modification item on the attributeType specified
*/
public static final Modification getModificationItem( List<Modification> mods, AttributeType type )
{
for ( Modification modification : mods )
{
Attribute attribute = modification.getAttribute();
if ( attribute.getAttributeType() == type )
{
return modification;
}
}
return null;
}
示例15: getAttribute
import org.apache.directory.api.ldap.model.entry.Modification; //导入方法依赖的package包/类
/**
* Utility method to extract an attribute from a list of modifications.
*
* @param mods the list of ModificationItems to extract the Attribute from.
* @param type the attributeType spec of the Attribute to extract
* @return the extract Attribute or null if no such attribute exists
*/
public static Attribute getAttribute( List<Modification> mods, AttributeType type )
{
Modification mod = getModificationItem( mods, type );
if ( mod != null )
{
return mod.getAttribute();
}
return null;
}