Package org.apache.directory.shared.ldap.message.internal

Examples of org.apache.directory.shared.ldap.message.internal.InternalLdapResult


                 ((BindRequestImpl)message).isSimple() ||
                 ldapSession.isSimpleAuthPending() )
            {
                LOG.error( I18n.err( I18n.ERR_732 ) );
                InternalBindResponse bindResponse = new BindResponseImpl( message.getMessageId() );
                InternalLdapResult bindResult = bindResponse.getLdapResult();
                bindResult.setResultCode( ResultCodeEnum.UNWILLING_TO_PERFORM );
                bindResult.setErrorMessage( I18n.err( I18n.ERR_732 ) );
                ldapSession.getIoSession().write( bindResponse );
                return;
            }
        }
       
View Full Code Here


    /**
     * Handles processing with referrals without ManageDsaIT control.
     */
    public void handleException( LdapSession session, InternalResultResponseRequest req, Exception e )
    {
        InternalLdapResult result = req.getResultResponse().getLdapResult();

        /*
         * Set the result code or guess the best option.
         */
        ResultCodeEnum code;
        if ( e instanceof LdapException )
        {
            code = ( ( LdapException ) e ).getResultCode();
        }
        else
        {
            code = ResultCodeEnum.getBestEstimate( e, req.getType() );
        }
       
        result.setResultCode( code );

        /*
         * Setup the error message to put into the request and put entire
         * exception into the message if we are in debug mode.  Note we
         * embed the result code name into the message.
         */
        String msg = code.toString() + ": failed for " + req + ": " + e.getLocalizedMessage();

        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( msg, e );
       
            msg += ":\n" + ExceptionUtils.getStackTrace( e );
        }
       
        result.setErrorMessage( msg );

        if ( e instanceof NamingException )
        {
            NamingException ne = ( NamingException ) e;

            // Add the matchedDN if necessary
            boolean setMatchedDn =
                code == ResultCodeEnum.NO_SUCH_OBJECT             ||
                code == ResultCodeEnum.ALIAS_PROBLEM              ||
                code == ResultCodeEnum.INVALID_DN_SYNTAX          ||
                code == ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM;
           
            if ( ( ne.getResolvedName() != null ) && setMatchedDn )
            {
                result.setMatchedDn( ( DN ) ne.getResolvedName() );
            }
           
            // Add the referrals if necessary
            if ( e instanceof LdapReferralException )
            {
                InternalReferral referrals = new ReferralImpl();
               
                do
                {
                    String ref = ((LdapReferralException)e).getReferralInfo();
                    referrals.addLdapUrl( ref );
                }
                while ( ((LdapReferralException)e).skipReferral() );
               
                result.setReferral( referrals );
            }
        }

        session.getIoSession().write( req.getResultResponse() );
    }
View Full Code Here

    /**
     * Handles processing with referrals without ManageDsaIT control.
     */
    public void handleException( LdapSession session, InternalResultResponseRequest req, Exception e )
    {
        InternalLdapResult result = req.getResultResponse().getLdapResult();

        /*
         * Set the result code or guess the best option.
         */
        ResultCodeEnum code;
       
        if ( e instanceof LdapException )
        {
            code = ( ( LdapException ) e ).getResultCode();
        }
        else
        {
            code = ResultCodeEnum.getBestEstimate( e, req.getType() );
        }
       
        result.setResultCode( code );

        /*
         * Setup the error message to put into the request and put entire
         * exception into the message if we are in debug mode.  Note we
         * embed the result code name into the message.
         */
        String msg = code.toString() + ": failed for " + req + ": " + e.getLocalizedMessage();
        LOG.debug( msg, e );
       
        if ( IS_DEBUG )
        {
            msg += ":\n" + ExceptionUtils.getStackTrace( e );
        }
       
        result.setErrorMessage( msg );

        if ( e instanceof NamingException )
        {
            NamingException ne = ( NamingException ) e;

            // Add the matchedDN if necessary
            boolean setMatchedDn =
                code == ResultCodeEnum.NO_SUCH_OBJECT             ||
                code == ResultCodeEnum.ALIAS_PROBLEM              ||
                code == ResultCodeEnum.INVALID_DN_SYNTAX          ||
                code == ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM;
           
            if ( ( ne.getResolvedName() != null ) && setMatchedDn )
            {
                result.setMatchedDn( ( DN ) ne.getResolvedName() );
            }
        }

        session.getIoSession().write( req.getResultResponse() );
    }
View Full Code Here

        if ( handler == null )
        {
            // As long as no extended operations are implemented, send appropriate
            // error back to the client.
            String msg = "Unrecognized extended operation EXTENSION_OID: " + req.getOid();
            InternalLdapResult result = req.getResultResponse().getLdapResult();
            result.setResultCode( ResultCodeEnum.PROTOCOL_ERROR );
            result.setErrorMessage( msg );
            session.getIoSession().write( req.getResultResponse() );
            return;
        }
       
        try
        {
            handler.handleExtendedOperation( session, req );
        }
        catch ( Exception e )
        {
            InternalLdapResult result = req.getResultResponse().getLdapResult();
            result.setResultCode( ResultCodeEnum.OTHER );
            result.setErrorMessage( ResultCodeEnum.OTHER 
                + ": Extended operation handler for the specified EXTENSION_OID (" + req.getOid()
                + ") has failed to process your request:\n" + ExceptionUtils.getStackTrace( e ) );
            InternalExtendedResponse resp = ( InternalExtendedResponse ) req.getResultResponse();
            resp.setResponse( new byte[0] );
            session.getIoSession().write( req.getResultResponse() );
View Full Code Here

            }

            if ( principalEntry == null )
            {
                LOG.info( "The {} principalDN cannot be found in the server : bind failure.", bindRequest.getName() );
                InternalLdapResult result = bindRequest.getResultResponse().getLdapResult();
                result.setErrorMessage( "cannot bind the principalDn." );
                result.setResultCode( ResultCodeEnum.INVALID_CREDENTIALS );
                ldapSession.getIoSession().write( bindRequest.getResultResponse() );
                return;
            }

            if ( principalEntry.getOriginalEntry().contains( SchemaConstants.OBJECT_CLASS_AT,
                SchemaConstants.REFERRAL_OC ) )
            {
                LOG.info( "Bind principalDn points to referral." );
                InternalLdapResult result = bindRequest.getResultResponse().getLdapResult();
                result.setErrorMessage( "Bind principalDn points to referral." );
                result.setResultCode( ResultCodeEnum.INVALID_CREDENTIALS );
                ldapSession.getIoSession().write( bindRequest.getResultResponse() );
                return;
            }

            // TODO - might cause issues since lookups are not returning all
            // attributes right now - this is an optimization that can be
            // enabled later after determining whether or not this will cause
            // issues.
            // reuse the looked up entry so we don't incur another lookup
            // opContext.setEntry( principalEntry );

            // And call the OperationManager bind operation.
            getLdapServer().getDirectoryService().getOperationManager().bind( opContext );

            // As a result, store the created session in the Core Session
            ldapSession.setCoreSession( opContext.getSession() );

            // And set the current state accordingly
            if ( !ldapSession.getCoreSession().isAnonymous() )
            {
                ldapSession.setAuthenticated();
            }
            else
            {
                ldapSession.setAnonymous();
            }
           
            // Return the successful response
            sendBindSuccess( ldapSession, bindRequest, null );
        }
        catch ( Exception e )
        {
            // Something went wrong. Write back an error message
            // For BindRequest, it should be an InvalidCredentials,
            // no matter what kind of exception we got.
            ResultCodeEnum code = null;
            InternalLdapResult result = bindRequest.getResultResponse().getLdapResult();

            if ( e instanceof LdapOperationNotSupportedException )
            {
                code = ResultCodeEnum.UNWILLING_TO_PERFORM;
                result.setResultCode( code );
            }
            else if ( e instanceof LdapInvalidNameException )
            {
                code = ResultCodeEnum.INVALID_DN_SYNTAX;
                result.setResultCode( code );
            }
            else
            {
                code = ResultCodeEnum.INVALID_CREDENTIALS;
                result.setResultCode( code );
            }

            String msg = code.toString() + ": Bind failed: " + e.getLocalizedMessage();

            if ( LOG.isDebugEnabled() )
            {
                msg += ":\n" + ExceptionUtils.getStackTrace( e );
                msg += "\n\nBindRequest = \n" + bindRequest.toString();
            }

            Name name = null;

            if ( e instanceof LdapAuthenticationException )
            {
                name = ( ( LdapAuthenticationException ) e ).getResolvedName();
            }

            if ( ( name != null )
                && ( ( code == ResultCodeEnum.NO_SUCH_OBJECT ) || ( code == ResultCodeEnum.ALIAS_PROBLEM )
                    || ( code == ResultCodeEnum.INVALID_DN_SYNTAX ) || ( code == ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM ) ) )
            {
                result.setMatchedDn( new DN( name ) );
            }

            result.setErrorMessage( msg );
            ldapSession.getIoSession().write( bindRequest.getResultResponse() );
        }
    }
View Full Code Here

        }
        catch ( Exception e )
        {
            // Something went wrong. Write back an error message           
            ResultCodeEnum code = null;
            InternalLdapResult result = bindRequest.getResultResponse().getLdapResult();

            if ( e instanceof LdapException )
            {
                code = ( ( LdapException ) e ).getResultCode();
                result.setResultCode( code );
            }
            else
            {
                code = ResultCodeEnum.getBestEstimate( e, bindRequest.getType() );
                result.setResultCode( code );
            }

            String msg = "Bind failed: " + e.getLocalizedMessage();

            if ( LOG.isDebugEnabled() )
            {
                msg += ":\n" + ExceptionUtils.getStackTrace( e );
                msg += "\n\nBindRequest = \n" + bindRequest.toString();
            }

            Name name = null;
           
            if ( e instanceof LdapAuthenticationException )
            {
                name = ((LdapAuthenticationException)e).getResolvedName();
            }
           
            if ( ( name != null )
                && ( ( code == ResultCodeEnum.NO_SUCH_OBJECT ) || ( code == ResultCodeEnum.ALIAS_PROBLEM )
                    || ( code == ResultCodeEnum.INVALID_DN_SYNTAX ) || ( code == ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM ) ) )
            {
                result.setMatchedDn( new DN( name ) );
            }

            result.setErrorMessage( msg );
            ldapSession.getIoSession().write( bindRequest.getResultResponse() );
        }
       
        return null;
    }
View Full Code Here

            pagedResultsControl.setCritical( true );
        }
       
        // and return
        // DO NOT WRITE THE RESPONSE - JUST RETURN IT
        InternalLdapResult ldapResult = req.getResultResponse().getLdapResult();
        ldapResult.setResultCode( ResultCodeEnum.SUCCESS );
        req.getResultResponse().add( pagedResultsControl );
        return ( InternalSearchResponseDone ) req.getResultResponse();
    }
View Full Code Here

            return abandonPagedSearch( session, req );
        }
       
        // Now, depending on the cookie, we will deal with case 2, 3, 4 and 5
        byte [] cookie= pagedSearchControl.getCookie();
        InternalLdapResult ldapResult = req.getResultResponse().getLdapResult();
       
        if ( StringTools.isEmpty( cookie ) )
        {
            // This is a new search. We have a special case when the paged size
            // is above the server size limit : in this case, we default to a
            // standard search
            if ( pagedLimit > sizeLimit )
            {
                // Normal search : create the cursor, and set pagedControl to false
                try
                {
                    // No cursor : do a search.
                    cursor = session.getCoreSession().search( req );

                    // Position the cursor at the beginning
                    cursor.beforeFirst();
                   
                    // And read the entries
                    readResults( session, req, ldapResult, cursor, sizeLimit );
                }
                finally
                {
                    try
                    {
                        cursor.close();
                    }
                    catch ( NamingException e )
                    {
                        LOG.error( I18n.err( I18n.ERR_168 ), e );
                    }
                }
               
                // If we had a cookie in the session, remove it
                removeContext( session, pagedContext );
                return ( InternalSearchResponseDone ) req.getResultResponse();
            }
            else
            {
                // Case 2 : create the context
                pagedContext = new PagedSearchContext( req );

                session.addPagedSearchContext( pagedContext );
                cookie = pagedContext.getCookie();
                pagedResultsControl = new PagedResultsControl();
                pagedResultsControl.setCookie( cookie );
                pagedResultsControl.setSize( 0 );
                pagedResultsControl.setCritical( true );


                // No cursor : do a search.
                cursor = session.getCoreSession().search( req );

                // Position the cursor at the beginning
                cursor.beforeFirst();
               
                // And stores the cursor into the session
                pagedContext.setCursor( cursor );
            }
        }
        else
        {
            // We have a cookie
            // Either case 3, 4 or 5
            int cookieValue = pagedSearchControl.getCookieValue();
            pagedContext = session.getPagedSearchContext( cookieValue );
           
            if ( pagedContext == null )
            {
                // We didn't found the cookie into the session : it must be invalid
                // send an error.
                ldapResult.setErrorMessage( "Invalid cookie for this PagedSearch request." );
                ldapResult.setResultCode( ResultCodeEnum.UNWILLING_TO_PERFORM );
               
                return ( InternalSearchResponseDone ) req.getResultResponse();
            }
           
            if ( pagedContext.hasSameRequest( req, session ) )
View Full Code Here

     * @throws Exception if there are failures while processing the request
     */
    private InternalSearchResponseDone doSimpleSearch( LdapSession session, InternalSearchRequest req )
        throws Exception
    {
        InternalLdapResult ldapResult = req.getResultResponse().getLdapResult();
       
        // Check if we are using the Paged Search Control
        Object control = req.getControls().get( PagedResultsControl.CONTROL_OID );
       
        if ( control != null )
View Full Code Here

    /**
     * Handles processing with referrals without ManageDsaIT control.
     */
    public void handleWithReferrals( LdapSession session, DN reqTargetDn, InternalSearchRequest req ) throws NamingException
    {
        InternalLdapResult result = req.getResultResponse().getLdapResult();
        ClonedServerEntry entry = null;
        boolean isReferral = false;
        boolean isparentReferral = false;
        ReferralManager referralManager = session.getCoreSession().getDirectoryService().getReferralManager();
       
        reqTargetDn.normalize( session.getCoreSession().getDirectoryService().
            getSchemaManager().getNormalizerMapping() );
       
        // Check if the entry itself is a referral
        referralManager.lockRead();
       
        isReferral = referralManager.isReferral( reqTargetDn );
       
        if ( !isReferral )
        {
            // Check if the entry has a parent which is a referral
            isparentReferral = referralManager.hasParentReferral( reqTargetDn );
        }
       
        referralManager.unlock();
       
        if ( !isReferral && !isparentReferral )
        {
            // This is not a referral and it does not have a parent which
            // is a referral : standard case, just deal with the request
            LOG.debug( "Entry {} is NOT a referral.", reqTargetDn );
            handleIgnoringReferrals( session, req );
            return;
        }
        else
        {
            // -------------------------------------------------------------------
            // Lookup Entry
            // -------------------------------------------------------------------
           
            // try to lookup the entry but ignore exceptions when it does not  
            // exist since entry may not exist but may have an ancestor that is a
            // referral - would rather attempt a lookup that fails then do check
            // for existence than have to do another lookup to get entry info
            try
            {
                entry = session.getCoreSession().lookup( reqTargetDn );
                LOG.debug( "Entry for {} was found: ", reqTargetDn, entry );
            }
            catch ( NameNotFoundException e )
            {
                /* ignore */
                LOG.debug( "Entry for {} not found.", reqTargetDn );
            }
            catch ( Exception e )
            {
                /* serious and needs handling */
                handleException( session, req, e );
                return;
            }
           
            // -------------------------------------------------------------------
            // Handle Existing Entry
            // -------------------------------------------------------------------
           
            if ( entry != null )
            {
                try
                {
                    LOG.debug( "Entry is a referral: {}", entry );
                   
                    handleReferralEntryForSearch( session, ( InternalSearchRequest ) req, entry );

                    return;
                }
                catch ( Exception e )
                {
                    handleException( session, req, e );
                }
            }
   
            // -------------------------------------------------------------------
            // Handle Non-existing Entry
            // -------------------------------------------------------------------
           
            // if the entry is null we still have to check for a referral ancestor
            // also the referrals need to be adjusted based on the ancestor's ref
            // values to yield the correct path to the entry in the target DSAs
           
            else
            {
                // The entry is null : it has a parent referral.
                ClonedServerEntry referralAncestor = null;
   
                try
                {
                    referralAncestor = getFarthestReferralAncestor( session, reqTargetDn );
                }
                catch ( Exception e )
                {
                    handleException( session, req, e );
                    return;
                }
   
                if ( referralAncestor == null )
                {
                    result.setErrorMessage( "Entry not found." );
                    result.setResultCode( ResultCodeEnum.NO_SUCH_OBJECT );
                    session.getIoSession().write( req.getResultResponse() );
                    return;
                }
                 
                // if we get here then we have a valid referral ancestor
                try
                {
                    InternalReferral referral = getReferralOnAncestorForSearch( session, ( InternalSearchRequest ) req, referralAncestor );
                   
                    result.setResultCode( ResultCodeEnum.REFERRAL );
                    result.setReferral( referral );
                    session.getIoSession().write( req.getResultResponse() );
                }
                catch ( Exception e )
                {
                    handleException( session, req, e );
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.message.internal.InternalLdapResult

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.