0

Is it possible to do this? If yes, then how?

When client invokes a jsp/html page, this page should be able to retrieve client email id from his system or from active directory and send it to server. Here we are not providing any login page in jsp/html page.It should retrieve email from windows logged in user.

Pooja
  • 528
  • 2
  • 6
  • 14
  • servlets and jsp's are executed on the server, not on the client. – Stultuske Sep 08 '15 at 13:05
  • @Stultuske.. yep.. I know ... but is it possible through some configuration? – Pooja Sep 08 '15 at 13:08
  • through some configuration ... of course not. first of all, every client would need to have his/her email 'setup' somewhere identical in the system for you to find (which is not very ethical, in most likely illegal), and not all users have their email linked to their account, or want you to have it, secondly ... no matter how you configure it, your code is executed on the server, it can't 'connect' the OS of the client. – Stultuske Sep 08 '15 at 13:11
  • @Stultuske By configuration I meant configuration for the web server and the web app. – Pooja Sep 08 '15 at 13:15
  • Doesn't really change my answer. Besides, I very much doubt the JVM to have access to the Windows authentication data, so you'll need another language for it. – Stultuske Sep 08 '15 at 13:20

2 Answers2

2

Short answer: NO

A bit longer one: Well, it depends.

First, you have to get the username of the currently logged in user on the client's (browser) side. To get that, start with the link provided by Gary in comments.

Then, you have to communicate with the Active Directory server, usually using the LDAP. A good starting point could be this article.

Anyway, all of this expects your application and clients to be in a controlled environment, e.g. within your company network. It won't help you to get the e-mail address of some John Doe from the other side of the globe.

Community
  • 1
  • 1
Jozef Chocholacek
  • 2,874
  • 2
  • 20
  • 25
0

If you mean to get the windows logged in username alone, there is a way. And it only works in Internet Explorer, the latest browser Edge probably supports this. It will not work in any other browser!

<script type="text/javascript">
    var WinNetwork = new ActiveXObject("WScript.Network");
    alert(WinNetwork.UserName); 
</script>

Now, if you want to know the password as well, there is absolutely no way from pure JavaScript. The browser context will not be able to access such details from the system it is running, because of security reasons. And even if it works, it will be a Microsoft only, IE/Edge Only solution, which is not what web is targeted to.

If you do not want to move out of JSP and HTML, then the best possible way is to setup a reverse proxy between your server and IIS.

This setup will secure the in an IIS and the IIS security context (or header) can be accessed by your server to authenticate or validate the user. However, I assume that this does need a login page, if the user accesses the page from a non-IE based browser.

A link on how to do this in Tomcat is here - http://tomcat.apache.org/tomcat-8.0-doc/windows-auth-howto.html#Microsoft_IIS

Footnote - I would just create a login page instead of going through all these things.

aksappy
  • 3,400
  • 3
  • 23
  • 49