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

The following examples show how to use org.apache.directory.api.ldap.model.entry.Entry#getDn() . 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: LdifRevertor.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * A small helper class to compute the simple revert.
 * 
 * @param entry The entry to revert
 * @param newDn The new Dn
 * @param newSuperior The new superior, if it has changed (null otherwise)
 * @param oldRdn The old Rdn
 * @param newRdn The new RDN if the RDN has changed
 * @return The reverted entry
 * @throws LdapInvalidDnException If the Dn is invalid
 */
private static LdifEntry revertEntry( Entry entry, Dn newDn, Dn newSuperior, Rdn oldRdn, Rdn newRdn )
    throws LdapInvalidDnException
{
    LdifEntry reverted = new LdifEntry();

    // We have a composite old Rdn, something like A=a+B=b
    // It does not matter if the RDNs overlap
    reverted.setChangeType( ChangeType.ModRdn );

    if ( newSuperior != null )
    {
        Dn restoredDn = newSuperior.add( newRdn );
        reverted.setDn( restoredDn );
    }
    else
    {
        reverted.setDn( newDn );
    }

    reverted.setNewRdn( oldRdn.getName() );

    // Is the newRdn's value present in the entry ?
    // ( case 3, 4 and 5)
    // If keepOldRdn = true, we cover case 4 and 5
    boolean keepOldRdn = entry.contains( newRdn.getNormType(), newRdn.getValue() );

    reverted.setDeleteOldRdn( !keepOldRdn );

    if ( newSuperior != null )
    {
        Dn oldSuperior = entry.getDn();

        oldSuperior = oldSuperior.getParent();
        reverted.setNewSuperior( oldSuperior.getName() );
    }

    return reverted;
}
 
Example 2
Source File: LdifUtils.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Convert an Entry as LDIF
 * 
 * @param entry the Entry to convert
 * @param length the expected line length
 * @return the corresponding LDIF code as a String
 */
public static String convertToLdif( Entry entry, int length )
{
    StringBuilder sb = new StringBuilder();

    if ( entry.getDn() != null )
    {
        // First, dump the Dn
        if ( isLDIFSafe( entry.getDn().getName() ) )
        {
            sb.append( stripLineToNChars( "dn: " + entry.getDn().getName(), length ) );
        }
        else
        {
            sb.append( stripLineToNChars( "dn:: " + encodeBase64( entry.getDn().getName() ), length ) );
        }

        sb.append( '\n' );
    }

    // Then all the attributes
    for ( Attribute attribute : entry )
    {
        sb.append( convertToLdif( attribute, length ) );
    }

    return sb.toString();
}
 
Example 3
Source File: LdifEntry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new LdifEntry object, storing an Entry
 * 
 * @param entry The entry to encapsulate
 */
public LdifEntry( Entry entry )
{
    // Default LDIF content
    changeType = ChangeType.None;
    modificationList = new LinkedList<>();
    modifications = new HashMap<>();
    this.entry = entry;
    entryDn = entry.getDn();
    controls = null;
}
 
Example 4
Source File: LdapLoginManager.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
private static Map.Entry<Dn, Entry> searchAndBind(LdapWorker w, String login, String passwd) throws LdapException, CursorException, OmException, IOException {
	Dn userDn = null;
	Entry entry = null;
	bindAdmin(w.conn, w.options);
	Dn baseDn = new Dn(w.options.searchBase);
	String searchQ = String.format(w.options.searchQuery, login);

	try (EntryCursor cursor = new EntryCursorImpl(w.conn.search(
			new SearchRequestImpl()
				.setBase(baseDn)
				.setFilter(searchQ)
				.setScope(w.options.scope)
				.addAttributes("*")
				.setDerefAliases(w.options.derefMode))))
	{
		while (cursor.next()) {
			try {
				Entry e = cursor.get();
				if (userDn != null) {
					log.error("more than 1 user found in LDAP");
					throw UNKNOWN;
				}
				userDn = e.getDn();
				if (w.options.useAdminForAttrs) {
					entry = e;
				}
			} catch (CursorLdapReferralException cle) {
				log.warn(WARN_REFERRAL);
			}
		}
	}
	if (userDn == null) {
		log.error("NONE users found in LDAP");
		throw BAD_CREDENTIALS;
	}
	w.conn.bind(userDn, passwd);
	return new AbstractMap.SimpleEntry<>(userDn, entry);
}
 
Example 5
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
@Override
public Dn map( Entry entry ) throws LdapException
{
    return entry.getDn();
}