Question

Create a Java Class which returns the logged on Username from Windows

Asked by: tgatif

Hi, I need to create a Java Class which I can instantiate in a different programming language to get the values of a logged on windows user with domain. I have a asp page where I use ServerVariableName("Logon_User") to get that value now.

So in short, I need a java class which i can instantiate from a non-java programming language which gets me the windows logged on username. If it can get the password, that is great too.

Users will be logged on Windows platform, thus info is in AD.

I dont know Java and your hellp is appreciated.
Thanks,

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-05-16 at 15:48:51ID23409945
Tags

WebObjects

Topics

Apple Software

,

Java Programming Language

,

Sun Java System Web Server

Participating Experts
2
Points
500
Comments
38

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. JAVA PLATFORM INDEPENDENT
    Can you support java is platform independent?. Case1: VC++ exe file needs Win to run, Case2: JAVA Byte code needs interpreter to run. In both cases we need extra software support then how Case 2 is advantageous?.
  2. Cross Platform Java
    Hello, I heard that Java was a cross-platform language. If I write a Java program on a Windows computer, will it work on a Mac, or UNIX? If so do I need to do anything extra?
  3. what makes java platform independent
    Can someone explain me what makes Java a platform independent language. can't we say that other languages like C or C++ are also platform independent. I know tht source code of a java program gets compiled into a bytecode. but say if we implement the same feature in C or C...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: krakatoaPosted on 2008-05-16 at 23:28:42ID: 21588174

>Create a Java Class which returns the logged on Username from Windows ...

String User = System.getProperty("user.name");

 

by: CEHJPosted on 2008-05-16 at 23:42:12ID: 21588199

You can do what krakatoa suggests, but you'd need to use a signed applet in a web page

 

by: tgatifPosted on 2008-05-16 at 23:51:52ID: 21588213

How do I do that. I dont know Java at all. I need to create a class. Problem is that the proprietry language i use can only instantiate Java objects. I think it wants me to create a dll file or some file than import it. I dont know how to do it. I need a lot of help there.

The code Krakatoa gave, I already had it. I just didnt know how to create a class which has a property or a method which returns the username.

 

by: tgatifPosted on 2008-05-16 at 23:52:11ID: 21588214

btw, Thanks to you guys for your reply.

 

by: CEHJPosted on 2008-05-16 at 23:55:15ID: 21588220

I'm wondering, if you working in a Microsoft environment, why you want to use Java for this?

 

by: tgatifPosted on 2008-05-17 at 00:17:16ID: 21588258

Unfortuantely, I will be running files on weblogic server which is JSP. However, This is what I am trying to do. You may have a better suggestion.

I have an ERP system where i want to setup a single sign-on with their logged on username on the web. I just need the logged on username. I can use an asp page and do it. However, I want to either call a java object or a windows object and do it. However, windows one is tricky and doesnt work that well. Its easier for me to call and instantiate a java class i have which has a method or a property getting me the name of the user logged on.

From there, I can take care of it. So my plan was that if there is a dll (i dont know what java has :P ) i can import and then call that object, it may work.


Also  I tried the code above but doesnt return me the username.


 

by: tgatifPosted on 2008-05-17 at 00:24:26ID: 21588268

Or I can use a Javascript if that works

 

by: tgatifPosted on 2008-05-17 at 00:27:27ID: 21588273

Also the ASP solution I have now only works in IE.

 

by: CEHJPosted on 2008-05-17 at 00:29:09ID: 21588277

The code posted will work - it just has to be used in the right context. That context is a signed applet running on the machine of the user whose name you want. See

http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html

 

by: CEHJPosted on 2008-05-17 at 00:31:36ID: 21588282

That applet would then have to interact with the server side, either by posting the user name back to a script or by interacting with the user's web page, which then posted the name back in the page to the server

 

by: tgatifPosted on 2008-05-17 at 18:50:51ID: 21591308

My concern is that I dont want user to download or allow the pagelet. I wnat it to be seemless.

 

by: tgatifPosted on 2008-05-17 at 19:07:12ID: 21591345

Alright the web solution is not feasable. I am going back to the basic. I need to have a java class created called loggedonuser.jar which i can instantiate and call a method which gets me the logged on user back. how hard it is to do it. Again, I dont know java. I have to do it in simple java. no web applets etc...

 

by: krakatoaPosted on 2008-05-18 at 01:52:57ID: 21591999

class UserID {

  public String UID;

           public UserID(){
           this.UID=System.getProperty("user.name");
          }

         public String getUID(){
                  return this.UID;
         }

}


// String User = new UserID().getUID();

 

by: CEHJPosted on 2008-05-18 at 08:37:53ID: 21593035

>>My concern is that I dont want user to download or allow the pagelet.

That's probably not feasible in any language as details on the logged in user are privileged info and therefore you need to use signed code to get it. That will need active acceptance

 

by: tgatifPosted on 2008-05-20 at 11:19:40ID: 21608757

I used eclipse to create a project and then the jar file with teh code above. seems to create thejar file but when i invoke it, i get errors about java exception: bad magic number.

 

by: CEHJPosted on 2008-05-20 at 11:35:45ID: 21608903

You probably are compiling it with too high a Java version for the runtime you're running it on. Compilation must have Eclipse compliance set to <= your applet runtime

 

by: tgatifPosted on 2008-05-20 at 19:57:03ID: 21611851

how do i do that

 

by: CEHJPosted on 2008-05-21 at 03:53:15ID: 21613637

First of all, check what version of the applet runtime you have

 

by: tgatifPosted on 2008-05-21 at 10:01:01ID: 21616968

how do i check that? i think if you are talking about java version its 1.4.12

 

by: CEHJPosted on 2008-05-21 at 10:53:17ID: 21617394

Go to

Project|Properties|Java Compiler in Eclipse and make sure you have compliance set to 1.4

 

by: tgatifPosted on 2008-05-22 at 10:18:14ID: 21625752

This is the error I get. I have checke dthe version is 1.4 whcih is what i have.
i have also added the path in teh classpath environmental variable.
attached is the file of the error.

 

by: krakatoaPosted on 2008-05-22 at 11:18:04ID: 21626240

Re : getloggedonuser90 : It looks like you've put together your own code now - can you post it so we can see what's going on?

 

by: krakatoaPosted on 2008-05-22 at 11:18:56ID: 21626247

Sorry -

getloggedonuser90

should read

getloggedonuser().

 

by: tgatifPosted on 2008-05-22 at 11:54:23ID: 21626544

package erp;
 
class getloggedonuser {
 
	  public String UID;
 
	           public getloggedonuser(){
	           this.UID=System.getProperty("user.name");
	          }
 
	         public String getUID(){
	                  return this.UID;
	         }
 
	}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:

Select allOpen in new window

 

by: CEHJPosted on 2008-05-22 at 11:54:34ID: 21626550

>>This is the error I get. I have checke dthe version is 1.4 whcih is what i have.

Please post a shot of your Eclipse compliance settings

 

by: tgatifPosted on 2008-05-22 at 11:58:53ID: 21626593

i just realized something. when i create a jar file and put it out there. it gives me a different error. but with the class file, it gives me the bad magic number. I dont know how to create a class file alone in ecl;ipse. i go to export. then pick as jar file and then pchange teh name to .class instead of .jar. is this correct

  • java2.jpg
    • 27 KB

    error when i have a jar file out there. seems canot find jar

    error when i have a jar file out there. seems canot find jar
 

by: tgatifPosted on 2008-05-22 at 12:05:23ID: 21626655

it worked. i grabbed teh correct class file and we are good to go. however, it brings in the userid of the server lopgon where the class file is located. i need the client username.

 

by: CEHJPosted on 2008-05-22 at 12:06:50ID: 21626666

If you're using a jar, you need to use the archive tag

<applet code="a.b.c.Something" archive="x.jar" width="100" height="75"></applet>

                                              
1:

Select allOpen in new window

 

by: tgatifPosted on 2008-05-22 at 12:09:18ID: 21626686

No, Now I am using class. I didnt know hwere the class file was. What I need now is the client logged on username which is equvilent to Request.ServerVariables("LOGON_USER") in an asp page when NTLM is checked.

 

by: tgatifPosted on 2008-05-22 at 12:12:54ID: 21626722

can i do it without any applet?

 

by: tgatifPosted on 2008-05-22 at 12:14:15ID: 21626739

other option is kind of convulated which is to instantiate a windows object in java class and then return the username. i just cant ask users to download or allow anything.
can i do that?

 

by: CEHJPosted on 2008-05-22 at 12:19:18ID: 21626785

>>
 i just cant ask users to download or allow anything.
can i do that?
>>

No. Signed server-side originating code will have to be downloaded and permissions given

 

by: CEHJPosted on 2008-05-22 at 12:38:21ID: 21626900

>>to instantiate a windows object in java class

I don't know what you mean by that ...

 

by: tgatifPosted on 2008-05-22 at 12:54:09ID: 21627012

so how do i do it with the applet but using a class.

some of teh avriables i found that i can read are (in jsp)

String accept = request.getHeader("accept");
String user_agent = request.getHeader("user-agent");
String accept_charset = request.getHeader("accept-charset");
String accept_language = request.getHeader("accept-language");
String x_wap_profile = request.getHeader("x-wap-profile");
String profile = request.getHeader("profile");

 

by: tgatifPosted on 2008-05-22 at 12:55:15ID: 21627021

>>I don't know what you mean by that ...

I mean can i call a windows library and get the logged on username from the windows itself.

 

by: CEHJPosted on 2008-05-22 at 13:10:04ID: 21627131

>>I mean can i call a windows library and get the logged on username from the windows itself.

That won't make any difference. You'll still need signed code - Windows equivalents would include a signed ActiveX control

 

by: CEHJPosted on 2008-05-22 at 13:12:38ID: 21627152

>>so how do i do it with the applet but using a class.

Not sure what you mean - an applet *is* a class ...

 

by: CEHJPosted on 2008-05-23 at 01:38:22ID: 21630400

:-)

Not sure where you are now, but good luck!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...