Hi !

Le 09/03/2017 à 10:52, Bikash Srivastava a écrit :
> Hi Team,
>
> I am working on Apache DS, but having a hard time how to code flows and
> request gets process inside the server.

Actually, it depends on what you want to study. If you want to start
from the very moment a request is received by the server, thenn the
startng point is the LdapProtocolHandler.messageReceived() method. That
being said, if you are interested in one specific request (ie, a Search,
an Add, etc), then you have dedicated handler for each operation :

ADD : AddRequestHandler.handle()
DELETE : DeleteRequestHandler.handle()
SEARCH : SearchRequestHandler.handle()
...

But that is again a bit deep in the stack. Enough said that each of
those handler is passing the control to the DefaultCoreSession class,
which has one method per request type : add( AddRequest addRequest ),
delete( DeleteRequest deleteRequest ), search( SearchRequest
searchRequest )...

Those methods create a Context containing all the informations needed to
process the request, and then call the OperationManager instance, which
is stored in the DirectoryService. For instance :

    public void add( AddRequest addRequest, LogChange log ) throws
LdapException
    {
        AddOperationContext addContext = new AddOperationContext( this,
addRequest );

        addContext.setLogChange( log );

        OperationManager operationManager =
directoryService.getOperationManager();
        try
        {
            operationManager.add( addContext );
        }
        catch ( LdapException e )
        {
            addRequest.getResultResponse().addAllControls(
addContext.getResponseControls() );
            throw e;
        }
        addRequest.getResultResponse().addAllControls(
addContext.getResponseControls() );
    }


The OperationManager is now in charge. The code is in the
DefaultOperationManager class, where some pre-processing is done, before
we call the Interceptor chain. Interceptors are snippet of code dealing
with specific aspect of the processing. We have a bit more than 15
interceptors that can be executed, depending on the operations and the
context. They are all linked in a specific order, which is configured :
you don't have to care about it.

All in all, the first interceptor is the Head, the last one is the Nexus
(ie, the facade for the database in use - we may have many), and in the
middle, you have Authent, Authz, etc...

We call the first interceptor this way :

    Interceptor head = directoryService.getInterceptor(
addContext.getNextInterceptor() );

    head.add( addContext );

and in each interceptor, you can do some pre-processing, call the ext
interceptor, and do some post-processing :

    public void add( AddOperationContext addContext ) throws LdapException
    {
        // Pre-processing
        checkAuthenticated( addContext );

        Entry entry = addContext.getEntry();

        if ( !directoryService.isPwdPolicyEnabled() ||
addContext.isReplEvent() )
        {
            // Call the next interceptor, and retirn (no post-processing
in this case
            next( addContext );
            return;
        }
        ...

Setting a Brekpoint in the OperationManager is the way to go.

I hope it helps. Do not hesitate to ask for more if needed !

-- 
Emmanuel Lecharny

Symas.com
directory.apache.org

Reply via email to