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

The following examples show how to use org.apache.directory.api.ldap.model.name.Dn#getRdns() . 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 5 votes vote down vote up
/**
 * Tells if there is a parent for a given Dn,. This parent should be a
 * subset of the given dn.<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
 * <br>For the Dn ou=apache, dc=org, there is no parent, so false will be returned.
 *
 * @param dn the normalized distinguished name to resolve to a parent
 * @return true if there is a parent associated with the normalized dn
 */
public synchronized boolean hasParent( Dn dn )
{
    List<Rdn> rdns = dn.getRdns();

    DnNode<N> currentNode = this;
    DnNode<N> parentNode = null;

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

        if ( rdn.equals( currentNode.nodeRdn ) )
        {
            parentNode = currentNode;
        }
        else if ( currentNode.hasChildren() )
        {
            currentNode = currentNode.children.get( rdn.getNormName() );

            if ( currentNode == null )
            {
                break;
            }

            parentNode = currentNode;
        }
        else
        {
            break;
        }
    }

    return parentNode != null;
}
 
Example 2
Source File: DnNode.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Removes a node from the tree.
 *
 * @param dn the node's Dn
 * @throws LdapException if the Dn is null or empty
 */
public synchronized void remove( Dn dn ) throws LdapException
{
    checkDn( dn );

    // Find the parent first : we won't be able to remove
    // a node if it's not present in the tree !
    DnNode<N> parentNode = getNode( dn );

    if ( parentNode == null )
    {
        return;
    }

    // Now, check that this parent has the same Dn than the one
    // we gave and that there is no children
    if ( ( dn.size() != parentNode.depth ) || parentNode.hasChildren() )
    {
        return;
    }

    // Ok, no children, same Dn, let's remove what we can.
    parentNode = parentNode.getParent();

    for ( Rdn rdn : dn.getRdns() )
    {
        parentNode.children.remove( rdn.getNormName() );

        if ( parentNode.children.size() > 0 )
        {
            // We have to stop here, because the parent's node is shared with other Node.
            break;
        }

        parentNode = parentNode.getParent();
    }
}
 
Example 3
Source File: DnNode.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Get the closest Node for a given Dn which has an element, 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 if it has an associated element.
 * <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 boolean hasParentElement( Dn dn )
{
    List<Rdn> rdns = dn.getRdns();

    DnNode<N> currentNode = this;
    boolean hasElement = false;

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

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

            if ( currentNode == null )
            {
                break;
            }

            if ( currentNode.hasElement() )
            {
                hasElement = true;
            }

            parent = currentNode;
        }
        else
        {
            break;
        }
    }

    return hasElement;
}
 
Example 4
Source File: DnNode.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Get the closest Node for a given Dn which has an element, 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 if it has an associated element.
 * <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> getParentWithElement( Dn dn )
{
    List<Rdn> rdns = dn.getRdns();

    DnNode<N> currentNode = this;
    DnNode<N> element = null;

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

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

            if ( currentNode == null )
            {
                break;
            }

            if ( currentNode.hasElement() )
            {
                element = currentNode;
            }

            parent = currentNode;
        }
        else
        {
            break;
        }
    }

    return element;
}
 
Example 5
Source File: AuditMgrConsole.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * Break the authZ eqDn attribute into 1. permission object name, 2. op name and 3. object id (optional).
 *
 * @param authZ contains the raw dn format from openldap slapo access log data
 * @return Permisison containing objName, opName and optionally the objId populated from the raw data.
 */
public static Permission getAuthZPerm(AuthZ authZ) throws LdapInvalidDnException
{
    // This will be returned to the caller:
    Permission pOp = new Permission();
    // Break dn into rdns for leaf and parent.  Use the 'type' field in rdn.
    // The objId value is optional.  If present it will be part of the parent's relative distinguished name..
    // Here the sample reqDN=ftOpNm=TOP2_2+ftObjId=002,ftObjNm=TOB2_1,ou=Permissions,ou=RBAC,dc=example,dc=com
    // Will be mapped to objName=TOB2_1, opName=TOP2_2, objId=002, in the returned permission object.
    Dn dn = new Dn( authZ.getReqDN() );
    if( dn.getRdns() != null && CollectionUtils.isNotEmpty( dn.getRdns() ) )
    {
        for( Rdn rdn : dn.getRdns() )
        {
            // The rdn type attribute will be mapped to objName, opName and objId fields.
            switch ( rdn.getType() )
            {
                case GlobalIds.POP_NAME:
                    pOp.setOpName( rdn.getType() );
                    break;
                case GlobalIds.POBJ_NAME:
                    pOp.setObjName( rdn.getType() );
                    break;
                case GlobalIds.POBJ_ID:
                    pOp.setObjId( rdn.getType() );
                    break;
            }
        }
    }
    return pOp;
}