Java Code Examples for org.apache.directory.api.ldap.model.name.Dn#getRdn()

The following examples show how to use org.apache.directory.api.ldap.model.name.Dn#getRdn() . 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: DnNode.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * rename the DnNode's Dn
 * 
 * @param newRdn the new Rdn of this node
 * @throws LdapException If the rename failed
 */
public synchronized void rename( Rdn newRdn ) throws LdapException
{
    Dn temp = nodeDn.getParent();
    temp = temp.add( newRdn );

    Rdn oldRdn = nodeRdn;

    nodeRdn = temp.getRdn();
    nodeDn = temp;

    if ( parent != null )
    {
        parent.children.remove( oldRdn.getNormName() );
        parent.children.put( nodeRdn.getNormName(), this );
    }

    updateAfterModDn( nodeDn );
}
 
Example 2
Source File: Runner.java    From aws-iam-ldap-bridge with Apache License 2.0 6 votes vote down vote up
public void createStructure() throws Exception {
    String rootDN = AWSIAMAuthenticator.getConfig().rootDN;
    Dn dnIAM = service.getDnFactory().create(rootDN);
    if (!utils.exists(dnIAM)) {
        IAM_LOG.info("Creating partition " + rootDN);
        Partition iamPartition = utils.addPartition("iam", rootDN, service.getDnFactory());

        // Index some attributes on the apache partition
        utils.addIndex(iamPartition, "objectClass", "ou", "uid", "gidNumber", "uidNumber", "cn");

        if (!utils.exists(dnIAM)) {
            IAM_LOG.info("Creating root node " + rootDN);
            Rdn rdn = dnIAM.getRdn(0);
            Entry entryIAM = new DefaultEntry(service.getSchemaManager(), dnIAM, "objectClass: top", "objectClass: domain",
                    "entryCsn: " + service.getCSN(), SchemaConstants.ENTRY_UUID_AT + ": " + UUID.randomUUID().toString(),
                    rdn.getType() + ": " + rdn.getValue());
            service.getAdminSession().add(entryIAM);
            checkErrors();
        }
    }
    service.sync();
}
 
Example 3
Source File: LdifRevertor.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Compute a reverse LDIF for a forward change which if in LDIF format
 * would represent a Move operation. Hence there is no newRdn in the
 * picture here.
 *
 * @param newSuperiorDn the new parent dn to be (must not be null)
 * @param modifiedDn the dn of the entry being moved (must not be null)
 * @return a reverse LDIF
 * @throws LdapException if something went wrong
 */
public static LdifEntry reverseMove( Dn newSuperiorDn, Dn modifiedDn ) throws LdapException
{
    LdifEntry entry = new LdifEntry();
    Dn currentParent;
    Rdn currentRdn;
    Dn newDn;

    if ( newSuperiorDn == null )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_13466_NEW_SUPERIOR_DN_NULL ) );
    }

    if ( modifiedDn == null )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_13467_NULL_MODIFIED_DN ) );
    }

    if ( modifiedDn.size() == 0 )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_13468_DONT_MOVE_ROOTDSE ) );
    }

    currentParent = modifiedDn;
    currentRdn = currentParent.getRdn();
    currentParent = currentParent.getParent();

    newDn = newSuperiorDn;
    newDn = newDn.add( modifiedDn.getRdn() );

    entry.setChangeType( ChangeType.ModDn );
    entry.setDn( newDn );
    entry.setNewRdn( currentRdn.getName() );
    entry.setNewSuperior( currentParent.getName() );
    entry.setDeleteOldRdn( false );
    return entry;
}
 
Example 4
Source File: DnNode.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Get the Node for a given Dn, if present in the tree.<br>
 * For instance, if we have stored dc=acme, dc=org into the tree,
 * the Dn: ou=example, dc=acme, dc=org will have a parent, and
 * dc=acme, dc=org will be returned.
 * <br>For the Dn ou=apache, dc=org, there is no parent, so null will be returned.
 *
 * @param dn the normalized distinguished name to resolve to a parent
 * @return the Node associated with the normalized dn
 */
public synchronized DnNode<N> getNode( Dn dn )
{
    DnNode<N> currentNode = this;
    DnNode<N> parentNode = null;

    // Iterate through all the Rdn until we find the associated partition
    for ( int i = dn.size() - 1; i >= 0; i-- )
    {
        Rdn rdn = dn.getRdn( i );

        if ( currentNode.hasChildren() )
        {
            currentNode = currentNode.children.get( rdn.getNormName() );

            if ( currentNode == null )
            {
                break;
            }

            parentNode = currentNode;
        }
        else
        {
            break;
        }
    }

    return parentNode;
}
 
Example 5
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private String getSchemaName( Dn dn ) throws LdapException
{
    int size = dn.size();

    if ( size < 2 )
    {
        throw new LdapException( I18n.err( I18n.ERR_276 ) );
    }

    Rdn rdn = dn.getRdn( size - 2 );

    return rdn.getNormValue().getString();
}
 
Example 6
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
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 7
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private String getSchemaName( Dn dn ) throws LdapException
{
    int size = dn.size();

    if ( size < 2 )
    {
        throw new LdapException( I18n.err( I18n.ERR_276 ) );
    }

    Rdn rdn = dn.getRdn( size - 2 );

    return rdn.getNormValue().getString();
}
 
Example 8
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
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 9
Source File: LDAPIAMPoller.java    From aws-iam-ldap-bridge with Apache License 2.0 5 votes vote down vote up
private void createEntry(String dn, String clazz) throws LdapException {
    Dn dnObj = directory.getDnFactory().create(dn);
    Rdn rdn = dnObj.getRdn(0);
    DefaultEntry entry = new DefaultEntry(directory.getSchemaManager(), dn);
    entry.put(rdn.getType(), rdn.getValue());
    entry.put(SchemaConstants.ENTRY_CSN_AT, directory.getCSN().toString());
    entry.put(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
    entry.put("objectclass", clazz);
    add(entry);
}
 
Example 10
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 4 votes vote down vote up
/**
 * Adds missing Rdn's attributes and values to the entry.
 *
 * @param dn the Dn
 * @param entry the entry
 */
private void addRdnAttributesToEntry( Dn dn, Entry entry ) throws LdapException
{
    if ( dn == null || entry == null )
    {
        return;
    }

    Rdn rdn = dn.getRdn();

    // Loop on all the AVAs
    for ( Ava ava : rdn )
    {
        Value value = ava.getValue();
        String upValue = ava.getValue().getString();
        String upId = ava.getType();

        // Check that the entry contains this Ava
        if ( !entry.contains( upId, value ) )
        {
            String message = "The Rdn '" + upId + "=" + upValue + "' is not present in the entry";
            LOG.warn( message );

            // We don't have this attribute : add it.
            // Two cases :
            // 1) The attribute does not exist
            if ( !entry.containsAttribute( upId ) )
            {
                entry.add( upId, upValue );
            }
            // 2) The attribute exists
            else
            {
                AttributeType at = schemaManager.lookupAttributeTypeRegistry( upId );

                // 2.1 if the attribute is single valued, replace the value
                if ( at.isSingleValued() )
                {
                    entry.removeAttributes( upId );
                    entry.add( upId, upValue );
                }
                // 2.2 the attribute is multi-valued : add the missing value
                else
                {
                    entry.add( upId, upValue );
                }
            }
        }
    }
}