Return-Path: Delivered-To: apmail-directory-users-archive@www.apache.org Received: (qmail 10863 invoked from network); 29 Mar 2010 15:27:13 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 29 Mar 2010 15:27:13 -0000 Received: (qmail 7481 invoked by uid 500); 29 Mar 2010 15:27:12 -0000 Delivered-To: apmail-directory-users-archive@directory.apache.org Received: (qmail 6816 invoked by uid 500); 29 Mar 2010 15:27:12 -0000 Mailing-List: contact users-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@directory.apache.org Delivered-To: mailing list users@directory.apache.org Delivered-To: moderator for users@directory.apache.org Received: (qmail 13597 invoked by uid 99); 29 Mar 2010 14:19:09 -0000 X-ASF-Spam-Status: No, hits=-2.3 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) From: "Hammond, Steven" To: "users@directory.apache.org" CC: "matt.doran@papercut.com" Date: Mon, 29 Mar 2010 07:18:38 -0700 Subject: RE: Custom partition - obtaining network connection details Thread-Topic: Custom partition - obtaining network connection details Thread-Index: AcrO2GAMpXdU8lqpTMuv3vdxC3+zdgAcGqwA Message-ID: <09202EBFA13FC04E8D4212D66A2D5785770E872F@CRPMBOXPRD02.polycom.com> References: <4BAEFD4B.9000702@papercut.com> <4BAF45F6.6030204@papercut.com> <4BAF4767.5000304@papercut.com> <4BAF4D0F.8030900@gmail.com> <4BAFF6B1.6000902@papercut.com> In-Reply-To: <4BAFF6B1.6000902@papercut.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 29 Mar 2010 14:18:40.0661 (UTC) FILETIME=[BB133C50:01CACF4A] X-Virus-Checked: Checked by ClamAV on apache.org 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 loo= kup and noticeable slowness. In core\src\main\java\org\apache\directory\server\core\jndi\ServerContext.j= ava I added client_host and client_port: protected NamingEnumeration doSearchOperation( Ldap= DN dn, AliasDerefMode aliasDerefMode, ExprNode filter, SearchControls searchControls, InetSocketAddress c= lientAddress, DirContext dirCtx) throws NamingException { // setup the op context and populate with request controls SearchOperationContext opCtx =3D new SearchOperationContext( regist= ries, 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 results =3D nexusProxy.search= ( opCtx ); // clear the request controls and set the response controls=20 requestControls =3D EMPTY_CONTROLS; responseControls =3D opCtx.getResponseControls(); return results; } Then in the my partition inside public NamingEnumeration search(SearchOperationContext arg0) I have: ob =3D opContext.get("client_host"); if (ob !=3D null) { String hostname =3D (String) ob; ob =3D opContext.get("client_port"); String clientPort =3D (String) ob; -----Original Message----- From: Matt Doran [mailto:matt.doran@papercut.com]=20 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=20 >>>> a peculiar requirement to know the details of the network=20 >>>> connection where the request has come from when I'm processing the=20 >>>> partition requests (i.e. in my custom partition implementation). >>>> >>>> I can't see anything obvious that might give me access to this=20 >>>> information. Is this possible? >>>> >>>> If I wanted to add this info (even as a thread local), is there a=20 >>>> hook point that I could use to collect/save this information? >>>> >>>> >>> >>> I found the "getClientAddress()" method available on the session. =20 >>> e.g. in the following code fragment. >>> >>> public ClonedServerEntry lookup(LookupOperationContext ctx) { >>> >>> if (logger.isDebugEnabled()) { >>> logger.debug("lookup(dn=3D" + ctx.getDn() + "), attrs: = " >>> + ctx.getAttrsId() >>> + " addr: " +=20 >>> ctx.getSession().getClientAddress()); >>> } >>> >>> >>> However it always seems to be null even when making requests to the=20 >>> server over the network. Any ideas? >>> >>> >> I just did some digging ..... and I found it. Looks like it's not=20 >> 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=20 > we are wrong and we should do it. > > Can you fill a JIRA asking for those informations to be added into the=20 > Ldap session ? > > OK, I've raised an issue for this:=20 https://issues.apache.org/jira/browse/DIRSERVER-1489 I'm looking for a short-term (even hacky) way to achieve this ... any=20 suggestions on how I might push the network address into the=20 DefaultCoreSession? Thanks, Matt