directory-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hammond, Steven" <Steven.Hamm...@Polycom.com>
Subject RE: Custom partition - obtaining network connection details
Date Mon, 29 Mar 2010 14:18:38 GMT
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




Mime
View raw message