You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by André Warnier <aw...@ice-sa.com> on 2009/02/12 14:12:45 UTC

of the different methods to get a user-id

Hi.

I am currently testing/comparing two user authentication methods for 
webapps, in a Windows NTLM context.
Despite my abysmal lack of knowledge in matters Java and Tomcat, I 
notice a difference between the two, and I would like to ask here if it 
matters, and if yes how.
Both authentication methods work as servlet filters. One is/was the 
jCIFS HTTP NTLM filter, the other a commercial product which would 
replace it for NTLMv2. I have asked the same question to the developer 
of both but I'm asking again here, to get a confirmation or additional 
observations.

In both cases below, the web user is authenticated from an HTTP NTLM 
point of view, otherwise the call would not even reach the underlying 
servlet.

In the case of the jCIFS filter, a servlet that is running "under cover 
of" the filter, can obtain the authenticated user-id by a 
request.getUserPrincipal().getName() call.

In the case of the other filter however, the previous call seems to 
return null, and the way to obtain the authenticated user-id is via 
request.getRemoteUser().

 From a practical immediate and personal point of view, it matters 
little to me, as I can adapt my servlet code to either of the above.

But my basic question is : what is the difference, and could that impact 
other servlet code which I did not write ?

For example also, in the case where the user authentication would be 
made at the level of a front-end Apache, connected to this Tomcat via 
mod_jk, and the appropriate parameter has been set so that Tomcat 
accepts the Apache authentication, would either one of the methods above 
return a result different from the other one ?


For convenience, I copied below the Java API doc of both methods.
I see that there is a difference, but my knowledge is too scarce to 
understand the possible implications.

Thanks.

--------------------------

*getUserPrincipal*

public java.security.Principal *getUserPrincipal*()

Returns a java.security.Principal object containing the name of the
current authenticated user. If the user has not been authenticated, the
method returns null.

*Returns:*

a java.security.Principal containing the name of the user making this
request; null if the user has not been authenticatedaw

*getRemoteUser*

public java.lang.String *getRemoteUser*()

Returns the login of the user making this request, if the user has been
authenticated, or null if the user has not been authenticated. Whether
the user name is sent with each subsequent request depends on the
browser and type of authentication. Same as the value of the CGI
variable REMOTE_USER.

*Returns:*

a String specifying the login of the user making this request, or null
if the user login is not known

-----------

Code of a small test servlet which runs under the "coverture" of Jespa's 
or jCIFS's HTTP filter :

package starweb;

import java.io.IOException;
import java.io.PrintWriter;
import java.security.Principal;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public final class DumpUser extends HttpServlet {
   public void doGet(HttpServletRequest request, HttpServletResponse
response)
               throws IOException, ServletException {

// what I was doing with jCIFS HTTP filter
//	Principal user = request.getUserPrincipal();
// 	String userName = (user == null ? "*null*" : user.getName());

// what I'm doing with the Jespa filter
   String userName = request.getRemoteUser();
   if (userName == null) {
     userName = "*null*";
   }

   response.setContentType("text/plain");
   PrintWriter writer = response.getWriter();
   writer.println(userName);

   }
}



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


Re: of the different methods to get a user-id

Posted by Pid <p...@pidster.com>.
André Warnier wrote:
> Tim Funk wrote:
>> Personally -
>>
>> I would expect
>> request.getRemoteUser() == request.getUserPrincipal().getName()
>>
>> But there no literature which says that must be so. 
> 
> And the reality shows it isn't.
> So somehow there must be two distinct underlying "thingies" in Tomcat
> where the two different answers are coming from.

The Tomcat source code would be a reasonable place to look and see what
Tomcat does, but if a Filter is operating on the request, it may be
replacing it with a Servlet[Response/Request]Wrapper that only overrides
one of the two method return values.


p


> So in that absence
>> of that - you'll probably need a RemoteUserHackFilter to unify the
>> various behaviors and then you standardize on one model and
>> RemoteUserHackFilter would adapt to that.
>>
> What worries me is not so much my own code, which I can indeed adapt.
> What worries me more is other webapps which I do not write.
> 
> Somehow it seems to me that there is some inconsistency there.  It seems
> to me that a webapp should have one source it should be able to rely on
> for a user-id, and not have to hack, no ?
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 


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


RE: [OT] of the different methods to get a user-id

Posted by Peter Crowther <Pe...@melandra.com>.
> From: Ken Bowen [mailto:kbowen@als.com]
> The only thing more fiery than "language X is better than language Y"
> is "editor Z is better than editor W"  :-)

To skip a few levels in the inevitable impending debate...

"Well I edited the inodes by hand.  With magnets."  (http://www.userfriendly.org)

                - Peter

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


Re: [OT] of the different methods to get a user-id

Posted by Ken Bowen <kb...@als.com>.
The only thing more fiery than "language X is better than language Y"  
is "editor Z is better than editor W"  :-)

On Feb 17, 2009, at 9:45 AM, André Warnier wrote:

> "language X is better than language Y"


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


Re: [OT] of the different methods to get a user-id

Posted by André Warnier <aw...@ice-sa.com>.
Just in case it was missed in the subsequent conflagration (and I always 
marvel at how easy it is to start a conflagration by saying something 
like "language X is better than language Y"), I would just like to state 
that my blurb was meant to be taken lightly, with ;-) and so on.

Comparing programming languages is a lot like comparing Microsoft 
software to Open Source, or comparing car brands, or (in my younger 
times) comparing stereo brands, etc..

One more thing I would like to add however to all the Java crazies 
around here, at least the open-minded subset of them : perl is fun.  I 
am not saying that it is the ideal language to develop a large 
application with a team of people, and I am not saying that it is faster 
or better or uses less memory or any of these things (though it does, 
really).  But it is, definitely, more /fun/ than Java.  And you can do 
serious things with it too.

And a serious tip : if you are ever in the situation of having to start 
a new project on some theme you know nothing about (say, credit card 
payments, or talking to Amazon, or filtering emails, or reading 
meta-data in photos, or stemming German words, or authenticating against 
OpenId,..), then you could do worse than first having a look at the Perl 
module library (http://kobesearch.cpan.org/), and perusing the perl 
modules documentation. Even if you know nothing of perl and don't want 
to know anything about it, the documentation of these (hundreds of) 
modules, all in one place and searchable, is one of the best sources of 
information I know.  It is like a Wikipedia of everything one can do 
with software.

And if in addition to be a Java fan, you're also an OO fan, search for 
"class".  Don't the names just sound like fun ?

Is there, by the way, any comparable source for Java libraries ?

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


Re: [OT] of the different methods to get a user-id

Posted by Alan Chaney <al...@compulsivecreative.com>.
Chris,

I offer my opinions here as a real "grey beard" (literally). I certainly 
agree with you that people should have
a breath of skills allowing them to use the right tool at the right time.

However, notwithstanding the fact that the other day I worked out that I 
have actually used about 15 different programming languages in anger 
(that is, part of code used by other people) I have to admit that my 
occasional brush with Perl has been unrewarding (for both me and the 
language...)

My biggest problem is that I've never seen a little bit of typing as a 
big issue, but reading and trying to understand something a few 
weeks/months/years later is always fraught with difficulties. The main 
problem with perl is that I can never remember exactly what #@!$% means 
whereas something like getUserPrincipal() works for me!

Regards

Alan Chaney


Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> André,
>
> What the hell.. let's start a holy war?!
>
> On 2/13/2009 10:25 AM, André Warnier wrote:
>   
>> Their merit is all the greater since
>> they work in the obscure non-graphical background, they never get any of
>> the attention, and they have to share machines with some Java programs,
>> which means they get only the usage of a tiny fraction of the RAM and
>> CPU cycles, although they do most of the real work and have to do it
>> with a single thread each.
>>     
>
> Hear, hear!
>
>   
>> Even some of the old-school programmers, mostly in their later years,
>> succumb to the what-the-heck syndrome and come to appreciate the sense
>> of security and comfort provided by strongly-typed and rigidly
>> object-oriented languages
>>     
>
> Heck, lots of folks on this list won't even use cron to schedule jobs.
> Instead, they write web applications wrapped around Quartz because "it's
> just easier to deploy" or some other such nonsense. IMHO, you either
> have control of your production environment yourself (and can do
> whatever you want) or you have an ops team with complete control of your
> production environment (and they ought to be able to handle scary stuff
> like scheduling cron jobs and running shell scripts) or you have no
> control whatsoever and therefore do not have a production environment.
> There, I said it. :p
>
> On the other hand, seeing object-oriented perl really makes me queasy.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkmZ2FIACgkQ9CaO5/Lv0PDOQgCeJno3T9D2GnoWpTFswcvInUCn
> zpcAnijMpytndgIfPe6knYmum47WOj56
> =QFoD
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
> !DSPAM:4999da4713771562881678!
>
>   


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


Re: [OT] of the different methods to get a user-id

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

Peter,

On 2/17/2009 5:08 AM, Peter Crowther wrote:
>> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
>> IMHO, you either have control of your production environment
>> yourself (and can do whatever you want) or you have an ops team
>> with complete control of your production environment (and they
>> ought to be able to handle scary stuff like scheduling cron jobs
>> and running shell scripts) or you have no control whatsoever and
>> therefore do not have a production environment.
> 
> Chris, how would you handle the case of writing software for
> installation by third parties in environments over which you have no
> control?  Those third parties' environments are still "production
> environments", but you have no control over them.

I see that situation as a special case of "you have an OPS team". If
your customers want to control their boxes, they should know how to do
thing like schedule jobs.

Maintaining server software just isn't as simple as babysitting
something like Microsoft Office. Customers have to understand that.
Those customers who aren't qualified to maintain their installations of
your server software should start paying YOU to maintain them properly.
That's another revenue stream for you. Be happy!

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

iEYEARECAAYFAkmcWVcACgkQ9CaO5/Lv0PCu4gCgs/GdyLEtpfatGosImZtlPs5N
uyEAoKxUcaZNt8PnMpWZcEBsovhSrMq9
=y5MR
-----END PGP SIGNATURE-----

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


RE: [OT] of the different methods to get a user-id

Posted by Peter Crowther <Pe...@melandra.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> IMHO, you either
> have control of your production environment yourself (and can do
> whatever you want) or you have an ops team with complete
> control of your
> production environment (and they ought to be able to handle
> scary stuff
> like scheduling cron jobs and running shell scripts) or you have no
> control whatsoever and therefore do not have a production environment.

Chris, how would you handle the case of writing software for installation by third parties in environments over which you have no control?  Those third parties' environments are still "production environments", but you have no control over them.

                - Peter

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


Re: [OT] of the different methods to get a user-id

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

André,

What the hell.. let's start a holy war?!

On 2/13/2009 10:25 AM, André Warnier wrote:
> Their merit is all the greater since
> they work in the obscure non-graphical background, they never get any of
> the attention, and they have to share machines with some Java programs,
> which means they get only the usage of a tiny fraction of the RAM and
> CPU cycles, although they do most of the real work and have to do it
> with a single thread each.

Hear, hear!

> Even some of the old-school programmers, mostly in their later years,
> succumb to the what-the-heck syndrome and come to appreciate the sense
> of security and comfort provided by strongly-typed and rigidly
> object-oriented languages

Heck, lots of folks on this list won't even use cron to schedule jobs.
Instead, they write web applications wrapped around Quartz because "it's
just easier to deploy" or some other such nonsense. IMHO, you either
have control of your production environment yourself (and can do
whatever you want) or you have an ops team with complete control of your
production environment (and they ought to be able to handle scary stuff
like scheduling cron jobs and running shell scripts) or you have no
control whatsoever and therefore do not have a production environment.
There, I said it. :p

On the other hand, seeing object-oriented perl really makes me queasy.

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

iEYEARECAAYFAkmZ2FIACgkQ9CaO5/Lv0PDOQgCeJno3T9D2GnoWpTFswcvInUCn
zpcAnijMpytndgIfPe6knYmum47WOj56
=QFoD
-----END PGP SIGNATURE-----

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


Re: [OT] of the different methods to get a user-id

Posted by André Warnier <aw...@ice-sa.com>.
Peter Crowther wrote:
>> From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com]
>> Hear, hear!  In a past life, a guy I know actually wrote a
>> suite of production programs in APL - which was even more
>> cryptic (but also more logical) than Perl.
> 
> Dedication indeed!  Did he need the custom golfball for the teletype with the special symbols, or was the interface a little more modern than that?
> 
I have to admit that we have several production applications written 
almost entirely in Perl.  They chug along since several years, 
processing several thousand documents a day, from MS-Word through PDFs 
to CAD/CAM drawings and emails, digesting them and making them 
searchable for grateful users.  Their merit is all the greater since 
they work in the obscure non-graphical background, they never get any of 
the attention, and they have to share machines with some Java programs, 
which means they get only the usage of a tiny fraction of the RAM and 
CPU cycles, although they do most of the real work and have to do it 
with a single thread each.
But such is the the deplorable state of our educational systems nowadays 
that one can no longer find real sharp logical young minds capable of 
designing efficient and reliable systems from scratch. So one has to 
depend instead on rigid frameworks and on programming languages like 
Java, which severely constrain the programmer's imagination, but make it 
less likely that one would land in trouble.
Even some of the old-school programmers, mostly in their later years, 
succumb to the what-the-heck syndrome and come to appreciate the sense 
of security and comfort provided by strongly-typed and rigidly 
object-oriented languages, with which one can just dedicate one thread 
to collect the memory garbage left over by sloppy programs, another to 
collect  loose database connections, another to kill off poor abandoned 
objects, another to optimise badly-written lines of code etc.
One has to wonder however if some day, the same kind of meltdown as we 
are currently seeing in the bloated world of finance, will not strike 
these over-engineered monsters, and if there will not be massive thread 
and memory layoffs.

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


RE: [OT] of the different methods to get a user-id

Posted by Peter Crowther <Pe...@melandra.com>.
> From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com]
> Hear, hear!  In a past life, a guy I know actually wrote a
> suite of production programs in APL - which was even more
> cryptic (but also more logical) than Perl.

Dedication indeed!  Did he need the custom golfball for the teletype with the special symbols, or was the interface a little more modern than that?

                - Peter

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


RE: [OT] of the different methods to get a user-id

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Peter Crowther [mailto:Peter.Crowther@melandra.com]
> Subject: RE: [OT] of the different methods to get a user-id
>
> Thank you.  Although I don't need any further reasons to
> avoid that camel of a language whenever I can, it's always
> nice to find another really good reason to avoid it...

Hear, hear!  In a past life, a guy I know actually wrote a suite of production programs in APL - which was even more cryptic (but also more logical) than Perl.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

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


RE: [OT] of the different methods to get a user-id

Posted by Peter Crowther <Pe...@melandra.com>.
> From: André Warnier [mailto:aw@ice-sa.com]
> I was going to let that one pass, but now I'm provoked.
> The expressions above do work differently in Perl.
[...]
> However, the calle sub can be cleverer and anticipate this, by doing :
> return wantarray ? (i++) : i++;
> thus checking in which context it is being called, and returning the
> appropriate form of response.
>
> Perl is great !

Thank you.  Although I don't need any further reasons to avoid that camel of a language whenever I can, it's always nice to find another really good reason to avoid it...

                - Peter

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


Re: [OT] of the different methods to get a user-id

Posted by André Warnier <aw...@ice-sa.com>.
Caldarale, Charles R wrote:
>> From: Christopher Schultz [mailto:chris@christopherschultz.net]
>> Subject: Re: [OT] of the different methods to get a user-id
>>
>> I don't understand that, either. I suppose this works differently in
>> different languages, though:
>>
>> return i++;
>>
>> return (i++);
> 
> Not any that I'm aware of; the value of the i++ expression is the same, regardless of the number of parentheses you wrap it in.
> 
>> I tried in C and Java and got the same result (both
>> return the original value of i), though I would have
>> expected something different.
> 
> Nope; the parentheses in such a statement control only operator precedence, not anything else.  Don't confuse parentheses used in an expression with those used for function calls or if/while statements - they're syntactically different, even if they share the same code point.
> 
I was going to let that one pass, but now I'm provoked.
The expressions above do work differently in Perl.

1) caller side :

a) my $var = getRemoteUser();
sets a /scalar/ context for the call. Means that the caller expects a 
single value in return.

b) my @var = getRemoteUser();
sets a /list/ context for the call.  Indicates that the caller expects a 
list (an array) in return.

2) callee side :

a) return i++;
Returns the value of i prior to the post-increment, as a scalar value.
So it "fits" with 1a.

b) return (i++);
Returns a list composed of 1 element : the value of i before the 
post-increment.
So it "fits" with 1b.

But..
if you combine the call 1a
my $var = getRemoteUser();
with the version 2b : return (i++)
then when you get in $var is 1, always.

That is because since
my $var = getRemoteUser();
expects a scalar, but what it gets is a list, it does an implicit
my $var = (list), which equivalent to
my $var = scalar(list)
which returns the number of elements present in the array/list.

However, the calle sub can be cleverer and anticipate this, by doing :
return wantarray ? (i++) : i++;
thus checking in which context it is being called, and returning the 
appropriate form of response.

Perl is great !



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


RE: [OT] of the different methods to get a user-id

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: [OT] of the different methods to get a user-id

> Do you mean gcc on win32 worked as you expected?

Yes, it produced the same results as Java.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

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


Re: [OT] of the different methods to get a user-id

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

Chuck,

On 2/16/2009 5:19 PM, Caldarale, Charles R wrote:
>> From: Christopher Schultz [mailto:chris@christopherschultz.net]
>> Subject: Re: [OT] of the different methods to get a user-id
>>
>> For instance.
>> i = i++
>>
>> yields different results depending on what language
>> you are using. C and Java produce different outputs
>> (which really surprised me!).
> 
> Java explicitly defines the behavior of the above statement, whereas
> the C standard does not, and leaves it up to the implementation to
> decide what to do. However, on almost every platform I have access to
> right at this moment (Windows, Linux, proprietary), printing the value
> of i after your test statement in both C and Java displayed the original
> value of i (as expected), not the increment thereof.

$ java -version
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05)
Java HotSpot(TM) Client VM (build 1.5.0_13-b05, mixed mode)

$ javac PostIncrementTest.java (see below)
$ java PostIncrementTest
0
0
0
$ cc --version
gcc (GCC) 4.1.2 (Gentoo 4.1.2 p1.1)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cc -o post_increment_test post_increment_test.c  (see below)
$ ./post_increment_test
0 0 1
$

I'm not sure what to say. Here are the sources:

post_increment_test.c:
#include <stdio.h>

int main() {
  printf("%d %d %d\n", test1(), test2(), test3());

  return 0;
}

int test1() {
  int i = 0;

  return i++;
}

int test2() {
  int i = 0;

  return (i++);
}

int test3() {
  int i = 0;

  i = i++;

  return i;
}

PostIncrementTest.java:
public class PostIncrementTest
{
    public static void main(String[] args)
    {
        System.out.println(test1());
        System.out.println(test2());
        System.out.println(test3());
    }

    public static int test1()
    {
        int i=0;

        return i++;
    }

    public static int test2()
    {
        int i=0;

        return (i++);
    }


    public static int test3()
    {
        int i=0;

        i = i++;

        return i;
    }
}

> The one problematic environment that gave the unexpected answer was
> Visual C++ 6.0 on Windows (gee, Microsoft ignores standard practice?
> who would a-thunk it); gcc on Windows worked properly.

Do you mean gcc on win32 worked as you expected? As you said, C does not
define this behavior, so "proper" is in the eye...

- -chris

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

iEYEARECAAYFAkmZ6l4ACgkQ9CaO5/Lv0PB+RQCffUOOV9Lv6tuBfSoG1e5mcvmm
YA4AoJoFhjoMaIbxCwqe6nxyPfh7fhcX
=0Dpi
-----END PGP SIGNATURE-----

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


RE: [OT] of the different methods to get a user-id

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: [OT] of the different methods to get a user-id
>
> For instance.
> i = i++
>
> yields different results depending on what language
> you are using. C and Java produce different outputs
> (which really surprised me!).

Java explicitly defines the behavior of the above statement, whereas the C standard does not, and leaves it up to the implementation to decide what to do.  However, on almost every platform I have access to right at this moment (Windows, Linux, proprietary), printing the value of i after your test statement in both C and Java displayed the original value of i (as expected), not the increment thereof.  The one problematic environment that gave the unexpected answer was Visual C++ 6.0 on Windows (gee, Microsoft ignores standard practice? who would a-thunk it); gcc on Windows worked properly.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

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


Re: [OT] of the different methods to get a user-id

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

Chuck,

On 2/12/2009 10:27 PM, Caldarale, Charles R wrote:
>> From: Christopher Schultz [mailto:chris@christopherschultz.net]
>> Subject: Re: [OT] of the different methods to get a user-id
>>
>> I don't understand that, either. I suppose this works differently in
>> different languages, though:
>>
>> return i++;
>>
>> return (i++);
> 
> Not any that I'm aware of; the value of the i++ expression is the same, regardless of the number of parentheses you wrap it in.

But sometimes the value is surprising.

For instance.

i = i++

yields different results depending on what language you are using. C and
Java produce different outputs (which really surprised me!).

>> What I also don't understand is why userPrincipal is used directly
>> instead of this.getUserPrincipal, which would allow some measure of
>> extensibility of the class.
> 
> Since the userPrincipal field is protected, not private, the subclass
> can just use it to store its Principal object, so I don't see a real
> problem.

I'm not saying it's not legal, I'm just saying it's not extensible. If a
superclass wants to override getUserPrincipal for some reason, the
subclass doesn't benefit (or doesn't work, in certain situations). Thsi
is one of the reasons I hate using protected members: members become
part of the interface, which is ... weird.

- -chris

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

iEYEARECAAYFAkmZ1jkACgkQ9CaO5/Lv0PAu7ACeKb+mqxYgZbHC8VDd+PRQAsvZ
B4MAnRYVo2/2eMA5ILWXGWvZik/2lJDo
=5EcI
-----END PGP SIGNATURE-----

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


RE: [OT] of the different methods to get a user-id

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: [OT] of the different methods to get a user-id
>
> I don't understand that, either. I suppose this works differently in
> different languages, though:
>
> return i++;
>
> return (i++);

Not any that I'm aware of; the value of the i++ expression is the same, regardless of the number of parentheses you wrap it in.

> I tried in C and Java and got the same result (both
> return the original value of i), though I would have
> expected something different.

Nope; the parentheses in such a statement control only operator precedence, not anything else.  Don't confuse parentheses used in an expression with those used for function calls or if/while statements - they're syntactically different, even if they share the same code point.

> What I also don't understand is why userPrincipal is used directly
> instead of this.getUserPrincipal, which would allow some measure of
> extensibility of the class.

Since the userPrincipal field is protected, not private, the subclass can just use it to store its Principal object, so I don't see a real problem.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

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


Re: [OT] of the different methods to get a user-id

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

Chuck,

On 2/12/2009 1:22 PM, Caldarale, Charles R wrote:
> 
> As Pid surmised, it's not Tomcat that is giving you different
> answers.
> Here's Tomcat's implementation of HttpServletRequest.getRemoteUser():
> 
>     public String getRemoteUser() {
>         if (userPrincipal != null) {
>             return (userPrincipal.getName());
>         } else {
>             return (null);
>         }
>     }
> 
> [Aside: Don't know why people think return statements need
> parentheses; maybe they get paid for programming based on the number of
> characters used.]

I don't understand that, either. I suppose this works differently in
different languages, though:

return i++;

return (i++);

I tried in C and Java and got the same result (both return the original
value of i), though I would have expected something different. Not sure
what, though.

What I also don't understand is why userPrincipal is used directly
instead of this.getUserPrincipal, which would allow some measure of
extensibility of the class.

Oh, well.

- -chris

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

iEYEARECAAYFAkmU4hwACgkQ9CaO5/Lv0PB5qACghJ4CDsMAjEuyQ+qDBWc/NwUd
8SEAn284vqUekj//e5wSXD5gUSVvXb4q
=P0xs
-----END PGP SIGNATURE-----

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


RE: of the different methods to get a user-id

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: André Warnier [mailto:aw@ice-sa.com]
> Subject: Re: of the different methods to get a user-id
>
> > I would expect
> > request.getRemoteUser() == request.getUserPrincipal().getName()
> > But there no literature which says that must be so.
>
> And the reality shows it isn't.
> So somehow there must be two distinct underlying "thingies" in Tomcat
> where the two different answers are coming from.

As Pid surmised, it's not Tomcat that is giving you different answers.  Here's Tomcat's implementation of HttpServletRequest.getRemoteUser():

    public String getRemoteUser() {
        if (userPrincipal != null) {
            return (userPrincipal.getName());
        } else {
            return (null);
        }
    }

[Aside: Don't know why people think return statements need parentheses; maybe they get paid for programming based on the number of characters used.]

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

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


Re: of the different methods to get a user-id

Posted by André Warnier <aw...@ice-sa.com>.
Tim Funk wrote:
> Personally -
> 
> I would expect
> request.getRemoteUser() == request.getUserPrincipal().getName()
> 
> But there no literature which says that must be so. 

And the reality shows it isn't.
So somehow there must be two distinct underlying "thingies" in Tomcat 
where the two different answers are coming from.

So in that absence
> of that - you'll probably need a RemoteUserHackFilter to unify the 
> various behaviors and then you standardize on one model and 
> RemoteUserHackFilter would adapt to that.
> 
What worries me is not so much my own code, which I can indeed adapt.
What worries me more is other webapps which I do not write.

Somehow it seems to me that there is some inconsistency there.  It seems 
to me that a webapp should have one source it should be able to rely on 
for a user-id, and not have to hack, no ?


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


Re: of the different methods to get a user-id

Posted by Tim Funk <fu...@joedog.org>.
Personally -

I would expect
request.getRemoteUser() == request.getUserPrincipal().getName()

But there no literature which says that must be so. So in that absence 
of that - you'll probably need a RemoteUserHackFilter to unify the 
various behaviors and then you standardize on one model and 
RemoteUserHackFilter would adapt to that.

-Tim


André Warnier wrote:
> Hi.
> 
> I am currently testing/comparing two user authentication methods for 
> webapps, in a Windows NTLM context.
> Despite my abysmal lack of knowledge in matters Java and Tomcat, I 
> notice a difference between the two, and I would like to ask here if it 
> matters, and if yes how.
> Both authentication methods work as servlet filters. One is/was the 
> jCIFS HTTP NTLM filter, the other a commercial product which would 
> replace it for NTLMv2. I have asked the same question to the developer 
> of both but I'm asking again here, to get a confirmation or additional 
> observations.
> 

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