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

The following examples show how to use org.apache.directory.api.ldap.model.entry.Entry#setDn() . 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: SimpleLDAPAuthenticationManagerTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private void createPrincipal(final String sn,
                             final String cn,
                             final String uid,
                             final String userPassword,
                             final String kerberosPrincipalName) throws LdapException
{
    final DirectoryService directoryService = LDAP.getDirectoryService();
    final Entry entry = new DefaultEntry(directoryService.getSchemaManager());
    entry.setDn(String.format("uid=%s,%s", uid, USERS_DN));
    entry.add("objectClass", "top", "person", "inetOrgPerson", "krb5principal", "krb5kdcentry");
    entry.add("cn", cn);
    entry.add("sn", sn);
    entry.add("uid", uid);
    entry.add("userPassword", userPassword);
    entry.add("krb5PrincipalName", kerberosPrincipalName);
    entry.add("krb5KeyVersionNumber", "0");
    directoryService.getAdminSession().add(entry);
}
 
Example 2
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for clone()
 */
@Test
public void testClone() throws LdapException
{
    Entry entry1 = new DefaultEntry();

    Entry entry2 = entry1.clone();

    assertEquals( entry1, entry2 );
    entry2.setDn( exampleDn );

    assertEquals( Dn.EMPTY_DN, entry1.getDn() );

    entry1.setDn( exampleDn );
    entry2 = entry1.clone();
    assertEquals( entry1, entry2 );

    entry1.add( "objectClass", "top", "person" );
    entry1.add( "cn", "test1", "test2" );

    entry2 = entry1.clone();
    assertEquals( entry1, entry2 );

    entry1.add( "cn", "test3" );
    assertEquals( 2, entry2.get( "cn" ).size() );
    assertFalse( entry2.contains( "cn", "test3" ) );

    entry1.add( "sn", ( String ) null );
    assertFalse( entry2.containsAttribute( "sn" ) );
}
 
Example 3
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for getDN()
 */
@Test
public void testGetDn() throws LdapException
{
    Entry entry = new DefaultEntry( exampleDn );

    assertEquals( exampleDn, entry.getDn() );

    Dn testDn = new Dn( "cn=test" );
    entry.setDn( testDn );

    assertEquals( testDn, entry.getDn() );
}
 
Example 4
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * 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 5
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for setDN( Dn )
 */
@Test
public void testSetDn()
{
    Entry entry = new DefaultEntry();

    assertEquals( Dn.EMPTY_DN, entry.getDn() );

    entry.setDn( exampleDn );
    assertEquals( exampleDn, entry.getDn() );
}
 
Example 6
Source File: ApacheLdapProviderImpl.java    From ldapchai with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void createEntry( final String entryDN, final Set<String> baseObjectClasses, final Map<String, String> stringAttributes )
        throws ChaiOperationException, ChaiUnavailableException, IllegalStateException
{
    activityPreCheck();
    getInputValidator().createEntry( entryDN, baseObjectClasses, stringAttributes );

    try
    {
        final AddRequest addRequest = new AddRequestImpl();
        final Entry entry = new DefaultEntry();
        entry.setDn( entryDN );
        for ( final String baseObjectClass : baseObjectClasses )
        {
            entry.add( ChaiConstant.ATTR_LDAP_OBJECTCLASS, baseObjectClass );
        }

        for ( final Map.Entry<String, String> entryIter : stringAttributes.entrySet() )
        {
            final String name = entryIter.getKey();
            final String value = entryIter.getValue();
            entry.add( name, value );
        }

        final AddResponse response = connection.add( addRequest );
        processResponse( response );
    }
    catch ( LdapException e )
    {
        throw ChaiOperationException.forErrorMessage( e.getMessage() );
    }
}
 
Example 7
Source File: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * 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 );
}
 
Example 8
Source File: MyVDCursor.java    From MyVirtualDirectory with Apache License 2.0 3 votes vote down vote up
@Override
public Entry get() throws CursorException {
	
	try {
		LDAPEntry nentry = null;
		
		if (buffer != null) {
			nentry = buffer.getEntry();
			buffer = null;
		} else {
			nentry = res.next().getEntry();
		}
		
		Entry entry = new DefaultEntry();
		
		entry.setDn(nentry.getDN());
		LDAPAttributeSet attrs = nentry.getAttributeSet();
		for (Object o : attrs) {
			LDAPAttribute a = (LDAPAttribute) o;
			String oid = "";
			
			AttributeType at;
			
			
			
			
			
			byte[][] vals = a.getByteValueArray();
			DefaultAttribute attr = new DefaultAttribute(a.getName());
			attr.add(vals);
			entry.add(attr);
			
		}
		
		return entry;
	} catch (Exception e) {
		throw new CursorException(e);
	} 
	
}