You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@directory.apache.org by Matt Doran <ma...@papercut.com> on 2010/03/28 08:55:07 UTC

Custom partition - obtaining network connection details

Hi there,

I've been working through implementing a custom partition.  I have a 
peculiar requirement to know the details of the network connection where 
the request has come from when I'm processing the partition requests 
(i.e. in my custom partition implementation).

I can't see anything obvious that might give me access to this 
information.  Is this possible?

If I wanted to add this info (even as a thread local), is there a hook 
point that I could use to collect/save this information?

Regards,
Matt

Re: Custom partition - obtaining network connection details

Posted by Alex Karasulu <ak...@gmail.com>.
On Tue, Mar 30, 2010 at 2:03 AM, Matt Doran <ma...@papercut.com> wrote:

> Hammond, Steven wrote:
>
>> This is how I did it back in 1.5.3 (which I am still on until we get
>> budget to move to the present)
>>
>> A warning, at first I just had getAddress, but this caused a reverseDNS
>> lookup and noticeable slowness.
>>
>> In
>> core\src\main\java\org\apache\directory\server\core\jndi\ServerContext.java
>>  I added  client_host and client_port:
>>
>>
>>    protected NamingEnumeration<ServerSearchResult> doSearchOperation(
>> LdapDN dn, AliasDerefMode aliasDerefMode,
>>        ExprNode filter, SearchControls searchControls, InetSocketAddress
>> clientAddress,
>>        DirContext dirCtx) throws NamingException
>>    {
>>        // setup the op context and populate with request controls
>>        SearchOperationContext opCtx = new SearchOperationContext(
>> registries, dn, aliasDerefMode, filter,
>>            searchControls );
>>
>>        opCtx.put( "client_host",
>> clientAddress.getAddress().getHostAddress() );
>>        opCtx.put( "client_port", String.valueOf( clientAddress.getPort() )
>> );
>>        opCtx.put( "client_JNDI_CXN", dirCtx );
>>        opCtx.addRequestControls( requestControls );
>>
>>        // execute search operation
>>        NamingEnumeration<ServerSearchResult> results = nexusProxy.search(
>> opCtx );
>>
>>        // clear the request controls and set the response controls
>> requestControls = EMPTY_CONTROLS;
>>        responseControls = opCtx.getResponseControls();
>>
>>        return results;
>>    }
>>
>>
>>
>> Then in the my partition inside    public
>> NamingEnumeration<ServerSearchResult> search(SearchOperationContext arg0) I
>> have:
>>
>>            ob = opContext.get("client_host");
>>            if (ob != null)
>>            {
>>               String hostname = (String) ob;
>>               ob = opContext.get("client_port");
>>               String clientPort = (String) ob;
>>
>>
>>
>
> Thanks for letting me know your approach.   It looks like thngs have
> changed a lot since then, the SearchOperationContext doesn't have a put
> method.   It seems that with Apache DS a minor point release means a big
> internal code change. :)
>
>
Hey Matt, take a look at this policy we have about how we change things with
releases:

   http://cwiki.apache.org/DIRxPMGT/version-numbering-scheme.html

Basically with 1.5.x which is considered a feature release branch we have
the luxury to introduce significant changes.  Yeah I know that this is way
better than using the alternative which is 1.0.x.  Also we should have done
a 2.0 a long time ago. Plus this scheme is a bit quirky and not so hmmm
intuitive.  Hopefully we can have a better scheme some day and we do plan on
this once we get 2.0 out the door.

Regards,
Alex

-- 
Alex Karasulu
My Blog :: http://www.jroller.com/akarasulu/
Apache Directory Server :: http://directory.apache.org
Apache MINA :: http://mina.apache.org
To set up a meeting with me: http://tungle.me/AlexKarasulu

Re: Custom partition - obtaining network connection details

Posted by Matt Doran <ma...@papercut.com>.
Hammond, Steven wrote:
> This is how I did it back in 1.5.3 (which I am still on until we get budget to move to the present)
>
> A warning, at first I just had getAddress, but this caused a reverseDNS lookup and noticeable slowness.
>
> In core\src\main\java\org\apache\directory\server\core\jndi\ServerContext.java  I added  client_host and client_port:
>
>
>     protected NamingEnumeration<ServerSearchResult> doSearchOperation( LdapDN dn, AliasDerefMode aliasDerefMode,
>         ExprNode filter, SearchControls searchControls, InetSocketAddress clientAddress,
>         DirContext dirCtx) throws NamingException
>     {
>         // setup the op context and populate with request controls
>         SearchOperationContext opCtx = new SearchOperationContext( registries, dn, aliasDerefMode, filter,
>             searchControls );
>
>         opCtx.put( "client_host", clientAddress.getAddress().getHostAddress() );
>         opCtx.put( "client_port", String.valueOf( clientAddress.getPort() ) );
>         opCtx.put( "client_JNDI_CXN", dirCtx );
>         opCtx.addRequestControls( requestControls );
>
>         // execute search operation
>         NamingEnumeration<ServerSearchResult> results = nexusProxy.search( opCtx );
>
>         // clear the request controls and set the response controls 
>         requestControls = EMPTY_CONTROLS;
>         responseControls = opCtx.getResponseControls();
>
>         return results;
>     }
>
>
>
> Then in the my partition inside    public NamingEnumeration<ServerSearchResult> search(SearchOperationContext arg0) I have:
>
>             ob = opContext.get("client_host");
>             if (ob != null)
>             {
>                String hostname = (String) ob;
>                ob = opContext.get("client_port");
>                String clientPort = (String) ob;
>
>   

Thanks for letting me know your approach.   It looks like thngs have 
changed a lot since then, the SearchOperationContext doesn't have a put 
method.   It seems that with Apache DS a minor point release means a big 
internal code change. :)

My approach has worked *OK* ... but it's not passing the connections 
details down to the authentication layer so I can use it in the bind 
operation.  I'll need to dig further to see if I can get this working.   
I'll update the Jira issue as I progress.

Matt

 

RE: Custom partition - obtaining network connection details

Posted by "Hammond, Steven" <St...@Polycom.com>.
This is how I did it back in 1.5.3 (which I am still on until we get budget to move to the present)

A warning, at first I just had getAddress, but this caused a reverseDNS lookup and noticeable slowness.

In core\src\main\java\org\apache\directory\server\core\jndi\ServerContext.java  I added  client_host and client_port:


    protected NamingEnumeration<ServerSearchResult> doSearchOperation( LdapDN dn, AliasDerefMode aliasDerefMode,
        ExprNode filter, SearchControls searchControls, InetSocketAddress clientAddress,
        DirContext dirCtx) throws NamingException
    {
        // setup the op context and populate with request controls
        SearchOperationContext opCtx = new SearchOperationContext( registries, dn, aliasDerefMode, filter,
            searchControls );

        opCtx.put( "client_host", clientAddress.getAddress().getHostAddress() );
        opCtx.put( "client_port", String.valueOf( clientAddress.getPort() ) );
        opCtx.put( "client_JNDI_CXN", dirCtx );
        opCtx.addRequestControls( requestControls );

        // execute search operation
        NamingEnumeration<ServerSearchResult> results = nexusProxy.search( opCtx );

        // clear the request controls and set the response controls 
        requestControls = EMPTY_CONTROLS;
        responseControls = opCtx.getResponseControls();

        return results;
    }



Then in the my partition inside    public NamingEnumeration<ServerSearchResult> search(SearchOperationContext arg0) I have:

            ob = opContext.get("client_host");
            if (ob != null)
            {
               String hostname = (String) ob;
               ob = opContext.get("client_port");
               String clientPort = (String) ob;

-----Original Message-----
From: Matt Doran [mailto:matt.doran@papercut.com] 
Sent: Sunday, March 28, 2010 6:39 PM
To: users@directory.apache.org
Subject: Re: Custom partition - obtaining network connection details

Emmanuel Lecharny wrote:
> On 3/28/10 2:11 PM, Matt Doran wrote:
>> On 28/03/2010 11:05 PM, Matt Doran wrote:
>>> On 28/03/2010 5:55 PM, Matt Doran wrote:
>>>> Hi there,
>>>>
>>>> I've been working through implementing a custom partition.  I have 
>>>> a peculiar requirement to know the details of the network 
>>>> connection where the request has come from when I'm processing the 
>>>> partition requests (i.e. in my custom partition implementation).
>>>>
>>>> I can't see anything obvious that might give me access to this 
>>>> information.  Is this possible?
>>>>
>>>> If I wanted to add this info (even as a thread local), is there a 
>>>> hook point that I could use to collect/save this information?
>>>>
>>>>
>>>
>>> I found the "getClientAddress()" method available on the session.  
>>> e.g.  in the following code fragment.
>>>
>>>         public ClonedServerEntry lookup(LookupOperationContext ctx) {
>>>
>>>             if (logger.isDebugEnabled()) {
>>>                 logger.debug("lookup(dn=" + ctx.getDn() + "), attrs: "
>>>    + ctx.getAttrsId()
>>>                         + " addr: " + 
>>> ctx.getSession().getClientAddress());
>>>             }
>>>
>>>
>>> However it always seems to be null even when making requests to the 
>>> server over the network.   Any ideas?
>>>
>>>
>> I just did some digging ..... and I found it.  Looks like it's not 
>> implemented on DefaultCoreSession ...
>>
>>         /* (non-Javadoc)
>>          * @see
>>    org.apache.directory.server.core.CoreSession#getClientAddress()
>>          */
>>         public SocketAddress getClientAddress()
>>         {
>>             // TODO Auto-generated method stub
>>             return null;
>>         }
>>
>>
>> Hmmm. :(
>>
>> Any ideas how I might be able to get the client network address?
> Actually,  we don't store networ information at the LDAP level. May be 
> we are wrong and we should do it.
>
> Can you fill a JIRA asking for those informations to be added into the 
> Ldap session ?
>
>
OK, I've raised an issue for this: 
https://issues.apache.org/jira/browse/DIRSERVER-1489

I'm looking for a short-term (even hacky) way to achieve this ... any 
suggestions on how I might push the network address into the 
DefaultCoreSession?

Thanks,
Matt




Re: Custom partition - obtaining network connection details

Posted by Matt Doran <ma...@papercut.com>.
Emmanuel Lecharny wrote:
> On 3/28/10 2:11 PM, Matt Doran wrote:
>> On 28/03/2010 11:05 PM, Matt Doran wrote:
>>> On 28/03/2010 5:55 PM, Matt Doran wrote:
>>>> Hi there,
>>>>
>>>> I've been working through implementing a custom partition.  I have 
>>>> a peculiar requirement to know the details of the network 
>>>> connection where the request has come from when I'm processing the 
>>>> partition requests (i.e. in my custom partition implementation).
>>>>
>>>> I can't see anything obvious that might give me access to this 
>>>> information.  Is this possible?
>>>>
>>>> If I wanted to add this info (even as a thread local), is there a 
>>>> hook point that I could use to collect/save this information?
>>>>
>>>>
>>>
>>> I found the "getClientAddress()" method available on the session.  
>>> e.g.  in the following code fragment.
>>>
>>>         public ClonedServerEntry lookup(LookupOperationContext ctx) {
>>>
>>>             if (logger.isDebugEnabled()) {
>>>                 logger.debug("lookup(dn=" + ctx.getDn() + "), attrs: "
>>>    + ctx.getAttrsId()
>>>                         + " addr: " + 
>>> ctx.getSession().getClientAddress());
>>>             }
>>>
>>>
>>> However it always seems to be null even when making requests to the 
>>> server over the network.   Any ideas?
>>>
>>>
>> I just did some digging ..... and I found it.  Looks like it's not 
>> implemented on DefaultCoreSession ...
>>
>>         /* (non-Javadoc)
>>          * @see
>>    org.apache.directory.server.core.CoreSession#getClientAddress()
>>          */
>>         public SocketAddress getClientAddress()
>>         {
>>             // TODO Auto-generated method stub
>>             return null;
>>         }
>>
>>
>> Hmmm. :(
>>
>> Any ideas how I might be able to get the client network address?
> Actually,  we don't store networ information at the LDAP level. May be 
> we are wrong and we should do it.
>
> Can you fill a JIRA asking for those informations to be added into the 
> Ldap session ?
>
>
OK, I've raised an issue for this: 
https://issues.apache.org/jira/browse/DIRSERVER-1489

I'm looking for a short-term (even hacky) way to achieve this ... any 
suggestions on how I might push the network address into the 
DefaultCoreSession?

Thanks,
Matt




Re: Custom partition - obtaining network connection details

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 3/28/10 2:11 PM, Matt Doran wrote:
> On 28/03/2010 11:05 PM, Matt Doran wrote:
>> On 28/03/2010 5:55 PM, Matt Doran wrote:
>>> Hi there,
>>>
>>> I've been working through implementing a custom partition.  I have a 
>>> peculiar requirement to know the details of the network connection 
>>> where the request has come from when I'm processing the partition 
>>> requests (i.e. in my custom partition implementation).
>>>
>>> I can't see anything obvious that might give me access to this 
>>> information.  Is this possible?
>>>
>>> If I wanted to add this info (even as a thread local), is there a 
>>> hook point that I could use to collect/save this information?
>>>
>>>
>>
>> I found the "getClientAddress()" method available on the session.  
>> e.g.  in the following code fragment.
>>
>>         public ClonedServerEntry lookup(LookupOperationContext ctx) {
>>
>>             if (logger.isDebugEnabled()) {
>>                 logger.debug("lookup(dn=" + ctx.getDn() + "), attrs: "
>>    + ctx.getAttrsId()
>>                         + " addr: " + 
>> ctx.getSession().getClientAddress());
>>             }
>>
>>
>> However it always seems to be null even when making requests to the 
>> server over the network.   Any ideas?
>>
>>
> I just did some digging ..... and I found it.  Looks like it's not 
> implemented on DefaultCoreSession ...
>
>         /* (non-Javadoc)
>          * @see
>    org.apache.directory.server.core.CoreSession#getClientAddress()
>          */
>         public SocketAddress getClientAddress()
>         {
>             // TODO Auto-generated method stub
>             return null;
>         }
>
>
> Hmmm. :(
>
> Any ideas how I might be able to get the client network address?
Actually,  we don't store networ information at the LDAP level. May be 
we are wrong and we should do it.

Can you fill a JIRA asking for those informations to be added into the 
Ldap session ?


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com



Re: Custom partition - obtaining network connection details

Posted by Matt Doran <ma...@papercut.com>.
On 28/03/2010 11:05 PM, Matt Doran wrote:
> On 28/03/2010 5:55 PM, Matt Doran wrote:
>> Hi there,
>>
>> I've been working through implementing a custom partition.  I have a 
>> peculiar requirement to know the details of the network connection 
>> where the request has come from when I'm processing the partition 
>> requests (i.e. in my custom partition implementation).
>>
>> I can't see anything obvious that might give me access to this 
>> information.  Is this possible?
>>
>> If I wanted to add this info (even as a thread local), is there a 
>> hook point that I could use to collect/save this information?
>>
>>
>
> I found the "getClientAddress()" method available on the session.  
> e.g.  in the following code fragment.
>
>         public ClonedServerEntry lookup(LookupOperationContext ctx) {
>
>             if (logger.isDebugEnabled()) {
>                 logger.debug("lookup(dn=" + ctx.getDn() + "), attrs: "
>    + ctx.getAttrsId()
>                         + " addr: " + 
> ctx.getSession().getClientAddress());
>             }
>
>
> However it always seems to be null even when making requests to the 
> server over the network.   Any ideas?
>
>
I just did some digging ..... and I found it.  Looks like it's not 
implemented on DefaultCoreSession ...

         /* (non-Javadoc)
          * @see
    org.apache.directory.server.core.CoreSession#getClientAddress()
          */
         public SocketAddress getClientAddress()
         {
             // TODO Auto-generated method stub
             return null;
         }


Hmmm. :(

Any ideas how I might be able to get the client network address?

Thanks,
Matt

Re: Custom partition - obtaining network connection details

Posted by Matt Doran <ma...@papercut.com>.
On 28/03/2010 5:55 PM, Matt Doran wrote:
> Hi there,
>
> I've been working through implementing a custom partition.  I have a 
> peculiar requirement to know the details of the network connection 
> where the request has come from when I'm processing the partition 
> requests (i.e. in my custom partition implementation).
>
> I can't see anything obvious that might give me access to this 
> information.  Is this possible?
>
> If I wanted to add this info (even as a thread local), is there a hook 
> point that I could use to collect/save this information?
>
>

I found the "getClientAddress()" method available on the session.  e.g.  
in the following code fragment.

         public ClonedServerEntry lookup(LookupOperationContext ctx) {

             if (logger.isDebugEnabled()) {
                 logger.debug("lookup(dn=" + ctx.getDn() + "), attrs: "
    + ctx.getAttrsId()
                         + " addr: " + ctx.getSession().getClientAddress());
             }


However it always seems to be null even when making requests to the 
server over the network.   Any ideas?

Regards,
Matt