Package org.apache.directory.api.ldap.model.url

Examples of org.apache.directory.api.ldap.model.url.LdapUrl


                referral.addLdapUrl( ref );
                continue;
            }

            // parse the ref value and normalize the Dn
            LdapUrl ldapUrl = null;

            try
            {
                ldapUrl = new LdapUrl( ref );
            }
            catch ( LdapURLEncodingException e )
            {
                LOG.error( I18n.err( I18n.ERR_165, ref, referralAncestor ) );
                ldapUrl = new LdapUrl();
            }

            Dn urlDn = new Dn( session.getCoreSession().getDirectoryService()
                .getSchemaManager(), ldapUrl.getDn().getName() );

            if ( urlDn.getNormName().equals( referralAncestor.getDn().getNormName() ) )
            {
                // according to the protocol there is no need for the dn since it is the same as this request
                StringBuilder buf = new StringBuilder();
                buf.append( ldapUrl.getScheme() );
                buf.append( ldapUrl.getHost() );

                if ( ldapUrl.getPort() > 0 )
                {
                    buf.append( ":" );
                    buf.append( ldapUrl.getPort() );
                }

                referral.addLdapUrl( buf.toString() );
                continue;
            }

            /*
             * If we get here then the Dn of the referral was not the same as the
             * Dn of the ref LDAP URL.  We must calculate the remaining (difference)
             * name past the farthest referral Dn which the target name extends.
             */
            Dn suffix = req.getBase().getDescendantOf( referralAncestor.getDn() );
            urlDn = urlDn.add( suffix );

            StringBuilder buf = new StringBuilder();
            buf.append( ldapUrl.getScheme() );
            buf.append( ldapUrl.getHost() );

            if ( ldapUrl.getPort() > 0 )
            {
                buf.append( ":" );
                buf.append( ldapUrl.getPort() );
            }

            buf.append( "/" );
            buf.append( LdapUrl.urlEncode( urlDn.getName(), false ) );
            referral.addLdapUrl( buf.toString() );
View Full Code Here


                if ( !url.startsWith( "ldap" ) )
                {
                    respRef.getReferral().addLdapUrl( url );
                }

                LdapUrl ldapUrl = null;

                try
                {
                    ldapUrl = new LdapUrl( url );
                    ldapUrl.setForceScopeRendering( true );
                }
                catch ( LdapURLEncodingException e )
                {
                    LOG.error( I18n.err( I18n.ERR_165, url, entry ) );
                }

                switch ( req.getScope() )
                {
                    case SUBTREE:
                        ldapUrl.setScope( SearchScope.SUBTREE.getScope() );
                        break;

                    case ONELEVEL: // one level here is object level on remote server
                        ldapUrl.setScope( SearchScope.OBJECT.getScope() );
                        break;

                    default:
                        throw new IllegalStateException( I18n.err( I18n.ERR_686 ) );
                }

                respRef.getReferral().addLdapUrl( ldapUrl.toString() );
            }

            return respRef;
        }
        else
View Full Code Here

                    public SearchResult next() throws NamingException
                    {
                        try
                        {
                            LdapUrl url = new LdapUrl( urls.remove( 0 ) );
                            SearchResult searchResult = new SearchResult( url.getDn().getName(), null,
                                new BasicAttributes(),
                                false );
                            searchResult.setNameInNamespace( url.getDn().getName() );
                            StudioSearchResult ssr = new StudioSearchResult( searchResult, null, false, url );
                            return ssr;
                        }
                        catch ( LdapURLEncodingException e )
                        {
                            throw new NamingException( e.getMessage() );
                        }
                    }


                    public boolean hasMore() throws NamingException
                    {
                        return !urls.isEmpty();
                    }


                    public void close() throws NamingException
                    {
                        urls.clear();
                        referralsInfo = null;
                    }
                };
            }
            else if ( referralsHandlingMethod == ReferralHandlingMethod.FOLLOW )
            {
                Referral referral = referralsInfo.getNextReferral();
                for ( IJndiLogger logger : ConnectionCorePlugin.getDefault().getJndiLoggers() )
                {
                    logger.logSearchResultReference( connection, referral, referralsInfo, requestNum, null );
                }
                List<String> urls = new ArrayList<String>( referral.getLdapUrls() );
                LdapUrl url = new LdapUrl( urls.get( 0 ) );
                Connection referralConnection = ConnectionWrapperUtils.getReferralConnection( referral, monitor, this );
                if ( referralConnection != null )
                {
                    done = false;
                    String referralSearchBase = url.getDn() != null && !url.getDn().isEmpty() ? url.getDn().getName()
                        : searchBase;
                    String referralFilter = url.getFilter() != null && url.getFilter().length() == 0 ? url.getFilter()
                        : filter;
                    SearchControls referralSearchControls = new SearchControls();
                    referralSearchControls.setSearchScope( url.getScope().getScope() > -1 ? url.getScope().getScope()
                        : searchControls
                            .getSearchScope() );
                    referralSearchControls.setReturningAttributes( url.getAttributes() != null
                        && url.getAttributes().size() > 0 ? url.getAttributes().toArray(
                        new String[url.getAttributes().size()] ) : searchControls.getReturningAttributes() );
                    referralSearchControls.setCountLimit( searchControls.getCountLimit() );
                    referralSearchControls.setTimeLimit( searchControls.getTimeLimit() );
                    referralSearchControls.setDerefLinkFlag( searchControls.getDerefLinkFlag() );
                    referralSearchControls.setReturningObjFlag( searchControls.getReturningObjFlag() );
View Full Code Here

            : aliasesDereferencingMethod == AliasDereferencingMethod.FINDING ? "derefFindingBaseObj (2)" //$NON-NLS-1$
                : aliasesDereferencingMethod == AliasDereferencingMethod.SEARCH ? "derefInSearching (1)" //$NON-NLS-1$
                    : "neverDerefAliases (0)"; //$NON-NLS-1$

        // build LDAP URL
        LdapUrl url = Utils.getLdapURL( connection, searchBase, searchControls.getSearchScope(), filter, searchControls
            .getReturningAttributes() );

        // build command line
        String cmdLine = Utils.getLdapSearchCommandLine( connection, searchBase, searchControls.getSearchScope(),
            aliasesDereferencingMethod, searchControls.getCountLimit(), searchControls.getTimeLimit(), filter,
            searchControls.getReturningAttributes() );

        // build
        Collection<LdifLineBase> lines = new ArrayList<LdifLineBase>();
        lines.add( LdifCommentLine.create( "# LDAP URL     : " + url.toString() ) ); //$NON-NLS-1$
        lines.add( LdifCommentLine.create( "# command line : " + cmdLine.toString() ) ); //$NON-NLS-1$
        lines.add( LdifCommentLine.create( "# baseObject   : " + searchBase ) ); //$NON-NLS-1$
        lines.add( LdifCommentLine.create( "# scope        : " + scopeAsString ) ); //$NON-NLS-1$
        lines.add( LdifCommentLine.create( "# derefAliases : " + aliasAsString ) ); //$NON-NLS-1$
        lines.add( LdifCommentLine.create( "# sizeLimit    : " + searchControls.getCountLimit() ) ); //$NON-NLS-1$
View Full Code Here

                if ( ( referralsList != null ) && ( referralsList.size() > 0 ) )
                {
                    Referral referral = referralsList.remove( 0 );
                    List<String> referralUrls = new ArrayList<String>( referral.getLdapUrls() );
                    LdapUrl url = new LdapUrl( referralUrls.get( 0 ) );

                    Connection referralConnection = ConnectionWrapperUtils.getReferralConnection( referral, monitor,
                        this );
                    if ( referralConnection != null )
                    {
                        String referralSearchBase = url.getDn() != null && !url.getDn().isEmpty() ? url.getDn()
                            .getName()
                            : searchBase;
                        String referralFilter = url.getFilter() != null && url.getFilter().length() == 0 ? url
                            .getFilter()
                            : filter;
                        SearchControls referralSearchControls = new SearchControls();
                        referralSearchControls.setSearchScope( url.getScope().getScope() > -1 ? url.getScope()
                            .getScope()
                            : searchControls.getSearchScope() );
                        referralSearchControls.setReturningAttributes( url.getAttributes() != null
                            && url.getAttributes().size() > 0 ? url.getAttributes().toArray(
                            new String[url.getAttributes().size()] ) : searchControls.getReturningAttributes() );
                        referralSearchControls.setCountLimit( searchControls.getCountLimit() );
                        referralSearchControls.setTimeLimit( searchControls.getTimeLimit() );
                        referralSearchControls.setDerefLinkFlag( searchControls.getDerefLinkFlag() );
                        referralSearchControls.setReturningObjFlag( searchControls.getReturningObjFlag() );
View Full Code Here

                // Checking the current referral's URLs list
                if ( ( currentReferralUrlsList != null ) && ( currentReferralUrlsList.size() > 0 ) )
                {
                    resultEntryCounter++;
                    // Building an LDAP URL from the the url
                    LdapUrl url = new LdapUrl( currentReferralUrlsList.remove( 0 ) );

                    // Building the search result
                    SearchResult searchResult = new SearchResult( url.getDn().getName(), null,
                        new BasicAttributes(),
                        false );
                    searchResult.setNameInNamespace( url.getDn().getName() );

                    return new StudioSearchResult( searchResult, null, false, url );
                }
            }
            // Are we following referrals automatically?
View Full Code Here

                                monitor, this );
                            if ( referralConnection != null )
                            {
                                List<String> urls = new ArrayList<String>( referral.getLdapUrls() );

                                String referralDn = new LdapUrl( urls.get( 0 ) ).getDn().getName();
                                referralConnection.getConnectionWrapper().modifyEntry( referralDn,
                                    modificationItems, controls, monitor, newReferralsInfo );
                            }
                            else
                            {
View Full Code Here

                                monitor, this );
                            if ( referralConnection != null )
                            {
                                List<String> urls = new ArrayList<String>( referral.getLdapUrls() );

                                String referralDn = new LdapUrl( urls.get( 0 ) ).getDn().getName();
                                referralConnection.getConnectionWrapper().createEntry( referralDn, attributes,
                                    controls, monitor, newReferralsInfo );
                            }
                            else
                            {
View Full Code Here

                                monitor, this );
                            if ( referralConnection != null )
                            {
                                List<String> urls = new ArrayList<String>( referral.getLdapUrls() );

                                String referralDn = new LdapUrl( urls.get( 0 ) ).getDn().getName();
                                referralConnection.getConnectionWrapper().deleteEntry( referralDn, controls,
                                    monitor, newReferralsInfo );
                            }
                            else
                            {
View Full Code Here

     * @return the LDAP URL for the given search parameters
     */
    public static LdapUrl getLdapURL( Connection connection, String searchBase, int scope, String filter,
        String[] attributes )
    {
        LdapUrl url = new LdapUrl();
        url.setScheme( connection.getEncryptionMethod() == EncryptionMethod.LDAPS ? LdapUrl.LDAPS_SCHEME
            : LdapUrl.LDAP_SCHEME );
        url.setHost( connection.getHost() );
        url.setPort( connection.getPort() );
        try
        {
            url.setDn( new Dn( searchBase ) );
        }
        catch ( LdapInvalidDnException e )
        {
        }
        if ( attributes != null )
        {
            url.setAttributes( Arrays.asList( attributes ) );
        }
        url.setScope( scope );
        url.setFilter( filter );
        return url;
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.api.ldap.model.url.LdapUrl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.