VansFannel
VansFannel

Reputation: 45921

Detect user logged on a computer using Java web app

I want to develop an Java application that can detect the user logged on a Windows Domain. These credentials are going to be used to logging on the Java application running on Tomcat.

How can I do this? I want to know the remote user accessing my web app. This user is logged on in Active Directory.

Upvotes: 8

Views: 10047

Answers (4)

VansFannel
VansFannel

Reputation: 45921

This is my solution:

Put jcifs-1.2.7.jar on [TOMCAT_HOME]/common/lib directory.

Modify application's web.xml adding the followin text to section webapp:

<filter>
    <filter-name>NtlmHttpFilter</filter-name>
    <filter-class>jcifs.http.NtlmHttpFilter</filter-class>
    <init-param>
        <param-name>jcifs.http.domainController</param-name>
        <param-value>xx.xx.xx.xxx</param-value>  --> Domain Controller IP
    </init-param>
    <init-param>
        <param-name>jcifs.util.loglevel</param-name>
        <param-value>2</param-value>
    </init-param>
  </filter>
  <filter-mapping>
       <filter-name>NtlmHttpFilter</filter-name>
       <url-pattern>/*</url-pattern>
  </filter-mapping>

And the you can get the remote user using request.getRemoteUser() whithout prompt.

See you.

Upvotes: 5

user88193
user88193

Reputation: 9

Jcifs liabrary will be surely of your help. This library can be used for performing NTLM authentication.

Upvotes: 0

Moshe
Moshe

Reputation: 2668

I recall using mod_ntlm for apache did the trick for me, but that was few years ago, so I don't know what had changed since.

Upvotes: -1

sleske
sleske

Reputation: 83599

In general, you can hook into the local authorization service using Java Authentication and Authorization Service. That might do what you want.

That said, are you sure this is the right way to go? What do you want to accomplish? Are you looking for a single-signon solution for the webapp?

Then this: How to configure Tomcat to use Windows NTLM authentication? might be what you are looking for, as proposed by Steve Read in the comment above.

Upvotes: 1

Related Questions