Get Current Windows user USERNAME only

1,233 views
Skip to first unread message

Gusti Arya

unread,
Feb 24, 2015, 4:01:28 AM2/24/15
to waffle...@googlegroups.com
Hi,

I just know waffle today, i already treed this example but still failed, seems to differences with the current version.
is it possible for me to get current windows username using pure Java like in the example ?

please give me some hint.

Thanks.


Daniel Doubrovkine

unread,
Feb 24, 2015, 6:57:39 AM2/24/15
to waffle...@googlegroups.com
You don't need Waffle for this, JNA implements a lot of the WIndows API, including GetUserNameEx.


So just call Advapi32.getUserName()

--
You received this message because you are subscribed to the Google Groups "waffle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to waffle-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Gusti Arya

unread,
Feb 24, 2015, 9:07:57 PM2/24/15
to waffle...@googlegroups.com
Thanks for your reply, 
i have tried Advapi32Util.getUserName(), but it get server username, not the client.
my goal is  to be able to read client username only via webapp, not his password or the other attribute.

recently i tried this example but error when i try to read client username

clientContext.getIdentity().getFqn();

then im getting this error
com.sun.jna.platform.win32.Win32Exception: The security context does not allow impersonation of the client

Daniel Doubrovkine

unread,
Feb 25, 2015, 7:14:41 AM2/25/15
to waffle...@googlegroups.com
Backup... are you trying to do this in the context of authentication behind Waffle? You should look at the context of the request, so request.getUserPrincipal().getName() or something like that. 

If your web app is setup to impersonate (see the specific docs for whichever filter you're using, it's usually an impersonate=true option that waffle supports natively, see http://code.dblock.org/2011/01/18/waffle-single-sign-on-user-impersonation-in-tomcat.html for history), then the Advapi32Util.getUserName call will return the client's username - the thread under which you're running will be running as the client. But impersonation may be hard - it requires a lot more privileges and is not always possible on all AD deployments.

Gusti Arya

unread,
Feb 25, 2015, 8:01:32 PM2/25/15
to waffle...@googlegroups.com
thanks daniel, it works, now i can retrieve every single client that access my webapp. cheers :D

Daniel Doubrovkine

unread,
Feb 26, 2015, 6:59:54 AM2/26/15
to waffle...@googlegroups.com
I would love it if you could contribute a simple FAQ for this, https://github.com/dblock/waffle/blob/master/Docs/FAQ.md.
Reply all
Reply to author
Forward
0 new messages