You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tremal Naik <tr...@gmail.com> on 2007/02/28 17:12:14 UTC

How to retrieve principal

Hello,
I want to retrieve the user principal where I don't have the request
available i.e. I cannot use the method

HttpServletRequest.getUserPrincipal()

I need in particular the user name.

May you suggest something appropriate?

-- 
TREMALNAIK

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to retrieve principal

Posted by Tremal Naik <tr...@gmail.com>.
2007/2/28, Christopher Schultz <ch...@christopherschultz.net>:
> How is it that you have code that needs request-specific information,
> but no access to the request? Are you forced into this situation by
> other components (through a callback mechanism or something like that)?
> Or, is this the result of poor planning?

well, the code has been designed to run into jboss. In a clustered
configuration the request was not available in the Business tier. The
Jboss SecurityAssociations classes where doing the job of propagating
the principal to the BT.
Now we deployed the same code in tomcat, where a subset of the classes
have been included from those componing the BT. Hence, we are
developing the same application for both the environments and we'd
like to mantain the classes as general as possible. Think of a log4j
utility that must be called from either the WT and the BT. We don't
want to introduce a new version of the log helper (we don't want to
make things too complicated). We want to build the some code and it
works wether deployed  in tomcat or jboss. We are there at 99%,

I still need the user principal but I can solve using the ThreadLocal.
And a Valve, maybe...

-- 
TREMALNAIK

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to retrieve principal

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tremal,

Tremal Naik wrote:
> 2007/2/28, Christopher Schultz <ch...@christopherschultz.net>:
>> Well, what /do/ you have available?
> 
> May any of the following be useful?
> 
> Server server = ServerFactory.getServer();
> Service service = server.findService("Catalina");
> Engine engine = (Engine) service.getContainer();
> Host host = (Host) engine.findChild(engine.getDefaultHost());
> String lcName = "myContext";
> Context context = (Context) host.findChild(lcName);
> Realm realm = context.getRealm();

Nope. All of this is generic server stuff. There's nothing specific to
the request a anywhere here.

How is it that you have code that needs request-specific information,
but no access to the request? Are you forced into this situation by
other components (through a callback mechanism or something like that)?
Or, is this the result of poor planning?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5bQY9CaO5/Lv0PARAiRUAKCQMCgt884O/KqBXbIkJv5BoLSQEgCcDR0b
XwJCubKnXB7b/LT9iDK8rVg=
=ikHQ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to retrieve principal

Posted by Tremal Naik <tr...@gmail.com>.
2007/2/28, Christopher Schultz <ch...@christopherschultz.net>:
> Well, what /do/ you have available?

That was my question: "What do I have available?".
May any of the following be useful?
I'm confused, really.

Server server = ServerFactory.getServer();
Service service = server.findService("Catalina");
Engine engine = (Engine) service.getContainer();
Host host = (Host) engine.findChild(engine.getDefaultHost());
String lcName = "myContext";
Context context = (Context) host.findChild(lcName);
Realm realm = context.getRealm();

-- 
TREMALNAIK

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to retrieve principal

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tremal,

Tremal Naik wrote:
> I want to retrieve the user principal where I don't have the request
> available i.e. I cannot use the method
> 
> HttpServletRequest.getUserPrincipal()

Well, what /do/ you have available?

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5a209CaO5/Lv0PARApcLAJ0Wt9TT+zJGThsuNmmDKHBRj4yPngCgp3X5
BnvqT06BnRs/q2AgL42RMhI=
=u7WE
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to retrieve principal

Posted by Tremal Naik <tr...@gmail.com>.
2007/2/28, Peter Crowther <Pe...@melandra.com>:
> We got round this by putting the name into a ThreadLocal variable from a
> place where we *did* have access to it, then reading it later - messy,

I see, you use the same approach as JBoss. So, you mean there is no
way to get the user principal using tomcat security framework.

Ok, thanks

-- 
TREMALNAIK

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: How to retrieve principal

Posted by Peter Crowther <Pe...@melandra.com>.
> From: Tremal Naik [mailto:tremalnaik@gmail.com] 
> I want to retrieve the user principal where I don't have the request
> available i.e. I cannot use the method
> 
> HttpServletRequest.getUserPrincipal()
> 
> I need in particular the user name.
> 
> May you suggest something appropriate?

We got round this by putting the name into a ThreadLocal variable from a
place where we *did* have access to it, then reading it later - messy,
but it works, as Tomcat processes an entire request on the same thread.
Note that threads are re-used between requests, so make sure your code
can deal with that re-use.

There are probably better ways.

		- Peter

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org