Retrieve User Account without the domain name

Aug 27, 2010 at 7:23 PM

I am using request.getRemoteUser value for many of my dynamic SQL statements.  I do not want the domain name.  Are there any configurations that will strip the domain when retrieve user account from the request session?

Coordinator
Aug 27, 2010 at 7:26 PM
Edited Aug 27, 2010 at 7:27 PM

There're not. You can get the user principal object which has methods that give you username and domain separately, but you might as well parse the result from request.getRemoteUser as well. I think dropping the domain name has to be wrong though, you can have a local user Bob and a domain user domain\bob and a domain2\bob and they are all different people.

Update: I'd actually like a patch that lets you specify the principal name in various formats (fqn, sid are already supported, maybe you could add name).

Coordinator
Aug 27, 2010 at 7:28 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Aug 27, 2010 at 7:33 PM

That is a great idea.  I feel this would be very useful.

Coordinator
Aug 27, 2010 at 9:06 PM

Feel free to implement it, send us a patch :)

Feb 21, 2011 at 12:32 PM

Hello,

do you have news about this "patch" because I have the same "problem" I would like to have the username without domain.

Feb 22, 2011 at 1:54 PM

I am sorry to inform you that I am not working on this patch.  I am not in a position to take on any additonal projects at this time.  To quote dblock, "Feel free to implement it, send them a patch:)". 

Feb 23, 2011 at 5:43 PM

ok, I looked a little in the src, but I'm not a pro of Java so it's a little complicate for me :(

I found a way to change the fqn in the code but I'm not able to had a parameter :(

So If dblok has a little time for the release 1.4 if it's possible to add this feature :)

May 31, 2011 at 4:47 PM
Edited May 31, 2011 at 4:47 PM

Perhaps I misunderstood but if you have the name in the format domain\name and you just want the name, why can't you use regex e.g.

String name = request.getUserPrincipal().getName();
name = name.replaceFirst(".*\\\\", "");

Coordinator
May 31, 2011 at 5:06 PM

You can certainly do whatever you want in your code. In Waffle though there're parsers that deal with all formats, including FQN (foo@domain). So it's not a bad idea to extend that to support a different format, in this case just the username.

Jun 1, 2011 at 4:19 PM

dblock, what is the preferred way to submit a patch? I see the issue page you created. Should I just modify the waffle source code and submit only the changed files? I figure since I'm going to implement this anyway, I might as well submit it so others can use it.

Coordinator
Jun 1, 2011 at 4:54 PM

Check out the source code. Make sure you write tests with your change and all tests pass. Make an SVN patch (it's a diff that you can make with TortoiseSVN or anything like that) and submit it in the patches here.

Jun 2, 2011 at 7:26 PM
Edited Jun 2, 2011 at 7:28 PM
dblock wrote:

There're not. You can get the user principal object which has methods that give you username and domain separately, but you might as well parse the result from request.getRemoteUser as well. I think dropping the domain name has to be wrong though, you can have a local user Bob and a domain user domain\bob and a domain2\bob and they are all different people.

Update: I'd actually like a patch that lets you specify the principal name in various formats (fqn, sid are already supported, maybe you could add name).

How are fqn and sid supported? From looking at the code it seems to me that only fqn is supported. If you use request.getUserPrincipal().getName() it will always return the _fqn found in the WindowsPrincipal class, which is the value found by using the methods from WindowsIdentityImpl, which calls methods found at: http://jna.java.net/javadoc/platform/com/sun/jna/platform/win32/Advapi32Util.Account.html ...

 

Am I missing something here? It seems to me that the value returned from WindowsPrincipal.getName() should vary based on what principalFormat was specified in the java bean...

Jun 3, 2011 at 2:51 PM
Edited Jun 3, 2011 at 3:07 PM

.. i removed this post ..

Coordinator
Jun 7, 2011 at 11:21 PM

Look at WindowsPrincipal.java, getPrincipalNames and such.