How 2 get WINDOWS USERNAME in a JSP

<%@ page import="sun.misc.BASE64Encoder" %>
<%
String auth = request.getHeader("Authorization");
if (auth == null) {
response.setStatus(response.SC_UNAUTHORIZED);
response.setHeader("WWW-Authenticate", "NTLM");
return;
if (auth.startsWith("NTLM ")) {
byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
int off = 0, length, offset;
String s;
if (msg[8] == 1) {
off = 18;
byte z = 0;
byte[] msg1 = {(byte)'N', (byte)'T', (byte)'L', (byte)'M', (byte)'S',
(byte)'S', (byte)'P', z,
(byte)2, z, z, z, z, z, z, z,
(byte)40, z, z, z, (byte)1, (byte)130, z, z,
z, (byte)2, (byte)2, (byte)2, z, z, z, z, //
z, z, z, z, z, z, z, z};
response.setStatus(response.SC_UNAUTHORIZED);
response.setHeader("WWW-Authenticate", "NTLM "
+ new sun.misc.BASE64Encoder().encodeBuffer(msg1).trim());
return;
     else if (msg[8] == 3) {
off = 30;
length = msg[off+9]*256 + msg[off+8];
offset = msg[off+11]*256 + msg[off+10];
s = new String(msg, offset, length);
out.println(s + " ");
else
return;
%></BODY>

Please use Code tags
Any of theses answer your question?
Ohh, wait that code is a direct copy of the first two posts.
What is wrong with it?

Similar Messages

  • How get windows username

    Hi,
    In my java application I have following code to get windows username-
    *<%*
    String s1 = System.getProperty("user.name");
    out.println("The Username : "+s1+" ");
    String s2 = System.getenv("USERNAME");
    out.println("The Username : "+s2);
    *%>*
    If I log in to my PC and execute it I get correct output for both the statements, But when I execute it on server machine(when I logged in) I get the output as-
    The Username : SYSTEM The Username : null
    I use Apache Tomcat 5.5 to run the jsp on both (PC & server) machines. One small difference is I use eclipse on my PC and I don't use eclipse on server (I think it doesn't matter).
    But when I use the same code inside a java class I get correct output on both (PC & server) machines.
    Can any one solve my problem.
    Thanks in advance,
    Tiijnar

    tiijnar wrote:
    Hi BalusC,
    Thanks for the reply.
    Could you please be more elaborted on this. What I mean is- can you provide me the code for the applet.Just the same code. Use System#getProperty() in an applet. The only difference is that the applet runs at the client machine and the Java web application runs at the server machine. If your problem is rather that you don't know how to use applets, just check the applet tutorial here at sun.com. Google can find it.
    Moreover when I execute jsp on my PC, I execute it on localhost (a server inside my PC). I face the problem when I host my application on my server machine.D'oh. On "localhost" the client and the server are physically on the same machine.

  • How to get windows username & password

    Hi friends,
    Requirement is to get windows username & password,
    My server is Tomcat4.0,
    My code in login.jsp page is
    <%
    String auth = request.getHeader("Authorization");
    if (auth == null) {
    response.setStatus(response.SC_UNAUTHORIZED);
    response.setHeader("WWW-Authenticate", "NTLM");
    return;
    if (auth.startsWith("NTLM ")) {
    byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
    int off = 0, length, offset;
    String s;
    if (msg[8] == 1) {
    off = 18;
    byte z = 0;
    byte[] msg1 = {(byte)'N', (byte)'T', (byte)'L', (byte)'M', (byte)'S',
    (byte)'S', (byte)'P', z,
    (byte)2, z, z, z, z, z, z, z,
    (byte)40, z, z, z, (byte)1, (byte)130, z, z,
    z, (byte)2, (byte)2, (byte)2, z, z, z, z, //
    z, z, z, z, z, z, z, z};
    response.setStatus(response.SC_UNAUTHORIZED);
    response.setHeader("WWW-Authenticate", "NTLM "
    + new sun.misc.BASE64Encoder().encodeBuffer(msg1).trim());
    return;
    else if (msg[8] == 3) {
    off = 30;
    length = msg[off+17]*256 + msg[off+16];
    offset = msg[off+19]*256 + msg[off+18];
    s = new String(msg, offset, length);
    //out.println(s + " ");--------------------------> here getting system_name
    else
    return;
    length = msg[off+1]*256 + msg[off];
    offset = msg[off+3]*256 + msg[off+2];
    s = new String(msg, offset, length);
    //out.println(s + " ");
    length = msg[off+9]*256 + msg[off+8];
    offset = msg[off+11]*256 + msg[off+10];
    s = new String(msg, offset, length);
    out.println("Hello <span style='position:relative; width:190;"
    + " height:10;filter:glow(Color=#009966,Strength=1)'>");
    out.println(s + "</SPAN>");----------------------------------->here getting loginname.
    %>
    from this i was able to get systemname & username,How do i get password.
    Is it possible to get password?
    Thanks,
    Satya.

    There's no way to get the password. NTLM uses a two-round challenge-response scheme which never send the password (neither clear nor encrypted) on the wire.
    Why do you need the user's password? Is your service going to access a backend service using the user's credential? If so, you may need to use Kerberos delegation.

  • How to get windows username printed on each page irrespective of application? we have cm6030f.

    How to get windows username printed on each page irrespective of application? we have HP CM6030F.

    Hi,
    Normally, you will receive a Windows Azure Pass from your local Windows Azure team. Please try to contact your local Windows Azure contact (http://support.microsoft.com/gp/customer-service-phone-numbers?wa=wsignin1.0
    Also, you could see this page
    http://www.windowsazurepass.com/AzureU/AcademicFAQ and apply the free trial azure via (http://www.windowsazurepass.com/AzureU/).
    Q: I am a student. Can I apply for a pass?                     
    A: Windows Azure Educator Grants are only for valid faculty. If your faculty has been awarded a Windows Azure Educator Grant, you will be able to get a pass through him/her for you coursework. If you are interested in learning more about Windows Azure,
    we encourage you to share these Educator Grants with your faculty or sign up for the FREE 3-month trial offer. 
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to get SSO username in a JSP

    Hi,
    How can i get the value for SSO username in my JSP which is being called after the Single Sign On is done. Can anyone help on this?
    Thanks in advance
    Unmesh

    Unmesh --
    I think (albeit I've never tried) that you might be able to get it from the HttpServletRequest using something like:
    User is <%=request.getUserPrincipal().getName()%>[b/]
    The request.getUserPrincipal returns a java.security.UserPrincipal object, which should be populated with the name of the authenticated user.
    Can you see if that works?
    cheers
    -steve-

  • Getting Windows Username In A Page

    Hello,
    I am currently developing an application that requires to know the Windows username, these are generic and will be used as a terminal. I was wondering if it is possible to get this information? I know I can use javascript and a active x control but I don't really want to go down that route.
    Our technology stack is:
    Apex 4.2.2.00.11
    Apex Listener 2
    Oracle 10g, 10.2.0.4.0
    Thanks,
    Paul.

    Here's a barebones script that you can call from a script in your form to retrieve the login name of the user:
    // Folder-level JavaScript function
    var getLoginName = app.trustedFunction(
        function () {
            // Get and return the user's login name
            app.beginPriv();
            return identity.loginName;
            app.EndPriv();
    This needs to be included in a JavaScript file that's installed in the correct location. It's just a text file, so you can create/edit it with a text editor, but make sure the extension is ".js". For more information about how to determine where to place the file, see: http://acrobatusers.com/tutorials/2006/folder_level_scripts
    More information on all of this is in the Acrobat JavaScript reference: http://www.adobe.com/devnet/acrobat/javascript.html
    To populate a text field with the login name, do something like:
    // Populate field with loginName
    getField("text1").value = getLoginName();
    Change "text1" with the actual name of the field in your form. You can place this code in a document-level JavaScript so it executes when the form is opened.
    Note that all of this code is the bare minimum, and you may want to expand it to check for errors, etc.

  • How get window between selection screen and alv output

    Hi Friends,
    I am displaying ALV report now i want to display small window with one button and it should show list of fields before displaying alv output.
    means i want a window showing list of fields of internal table coming from program.and when i will click on yes button it should show ALV output.
    how can i achive this .
    Pls. help
    thanks in advance.

    Hi,
    Try to use the following command:
    <b><i>WINDOW STARTING AT <some-value> <some-value> ENDING AT <some-value> <some-value>.
    </i></b>
    notice that there is a space between <> <>.
    This statement should be used inside the AT USER-COMMAND event.
    i.e.,
    AT USER-COMMAND.
       CASE SY-UCOMM.
           WHEN 'XXX'.
                <b> <i> WINDOW STARTING AT <> <> ENDING AT <> <>.</i></b>
                 ..............statements....................
       ENDCASE.
    This should help you some what.
    Bye

  • Getting Windows Username of the Client m/c

    Hi,
    I want to be able to get the userid of a person when they call a servlet which is residing on a server.
    The person will log into his own computer using his user id and when he calls my servlet which
    is on my server over a network, I will be able to retrieve his user id .
    Thanx in advance
    bye

    Why don't you include these informations with the POST (or GET) message to the servlet?
    just use:
    http://....../servlet?userLogin=User Name&userPassword=765
    at the servlet, you can retrieve these info using the getParameter() command:
       public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    String usrId = request.getParameter("userLogin");
    String usrPassword = request.getParameter("userPassword");
    .....

  • How to get the windows username in jsx

    Hello,
    I have a JSX script in "My Documents\Adobe Scripts" to make it trusted script. I have another text file I need to read from JSX. Since the location depends on logged in user, I need to find the windows username. If anyone know how to get the windows username from jsx please reply.
    Thank you very much.
    Regards
    Nima.

    Hey,
    You can get username like this:
    var myUsername = $.getenv('username');
    You could also get My Documents folder like this:
    var myDocFolder = Folder.myDocuments;
    Hope that helps.
    Marijan (tomaxxi)
    http://tomaxxi.com/

  • How do I get the URL of a jsp page?

    I have a jsp page which has a link to a servlet page, in the servlet page, I want to get the URL of the jsp page.
    I tried to use request.getHeader("referer"), it seems like if it is a link in the jsp directly lead to the servlet, it works, but if the link calls a javascript function which opens up a window runing the servlet, it is not working. I have to do the second way, so it is not working by doing request.getHeader("referer")
    I tried to use javascript "location.href", I get the whole url by alerting the url in the jsp page:
    http://localhost:8080/pos-webapp/serv/qt_old?currentpage=portal&bcd=ABC123&pnm=P1001830&prnm=1&psd=236863.0&ln=01&sln=NYPPA&stp=2.1&stt=A&_POSID=1F8464122ADAF4EEC9B1A94C286EB252
    then I pass this url when calling with my servlet, in the servlet page, when I do request.getParameter("url"), the url is actually cut off like this:
    http://localhost:8080/pos-webapp/serv/qt_old?currentpage=portal
    anything after &pnm is cut off, anyone has any idea?
    Thanks in advance.

    Thank you.
    but how do I put encoding in the javascript code? do I need to decode in my servlet page?
    here is my code in the jsp page:
    linkset[3]+='<div class="menuitems">Email Diagnostics to AutoOne</div>'<%     
    function emailDiagnostics()
    win = window.open("/pos-webapp/serv/email_diagnostics?url=" + location.href + "&browser=" + navigator.appName, "emailDiagnostics",
    "width=350, height=140, resizable=no, scrollbars=no, toolbar=no, location=yes, directories=no, status=no, menubar=no, copyhistory=no, left=450, top=300");
    win.focus();
    }

  • HDD failure, I'd like to know how to get Windows 7 back on it.

    Hello everyone, I've had a HDD issue lately, but before I move on to describe my issue, here are the specs of my notebook:
    HP Pavilion dv6-3264ca
    AMD Triple-Core CPU 2.2 Ghz
    6GB RAM
    128MB ATI Graphic Card
    750GB Toshiba HDD
    Windows 7 64-bit
    The issue:
    Recently I've had a very unfortunate HDD failure. The recovery partition wouldn't even load. I tried booting my notebook on Linux with the HDD still attached, and it wouldn't read. I extracted the HDD and placed it in an HDD-enclosuer and it still wouldn't load on Windows XP or Vista or 7. It would however read in the device manager of Windows and also in the BIOS.
    I needed to extract some high-priority data from there so I managed to retrieve all my data safely through a data recovery service, but now the drive is rendered useless. I was told a low-level format might be able to help it be usable again, and if that were to happen, the recovery partition would then be removed in the process. 
    In addition to that, I would like to install Windows 7 64-bit onto the drive, but the notebook box did not come with an installation CD, which is quite frustrating. Is there any way HP can let me download Windows 7 through some warranty service?
    I have a one-year warranty on my laptop.
    So in closing, I would like to know if I can get Windows 7 back onto my HDD for free, or if I need to go about buying Windows 7 again.
    Any advice from you kind folks?
    This question was solved.
    View Solution.

    Hi,
    Here are Two options.
    1.  If you have ( or can borrow ) a retail Windows 7 installation disc that is exactly the same version as your OEM installation - ie if your notebook came with Windows 7 Home Premium 64bit this is the exact retail version you would need.
    If you don't have access to a retail disc, you can create an installation disc yourself - just download the correct Disc Image from the link below and use an application such as ImgBurn to burn the ISO correctly to a blank DVD.
    http://www.mydigitallife.info/download-windows-7-iso-official-32-bit-and-64-bit-direct-download-link...
    Use the disc to perform the installation, enter the Windows activation key found on the underside of your notebook when requested and when the installation has completed, use the 'Phone Method' detailed in the link below to activate the OS - this method supported by Microsoft and is popular with people who just want a clean installation of Windows 7 without the additional software load normally bundled with OEM installations.
    http://www.kodyaz.com/articles/how-to-activate-windows-7-by-phone.aspx
    Any additional drivers you may need can be found Here.
    2.  You can order a replacement set of Recovery Discs using the link below - these cost around $30 if you live in the US.
    http://h10025.www1.hp.com/ewfrf/wc/document?docname=c00810334&cc=us&lc=en&dlc=en
    If you have any problem with this link, order them directly from HP.
    If you live in the US, contact HP Here.
    If you are in another part of the world, start Here.
    Regards,
    DP-K
    ****Click the White thumb to say thanks****
    ****Please mark Accept As Solution if it solves your problem****
    ****I don't work for HP****
    Microsoft MVP - Windows Experience

  • *** How to get the username in a custom password change routine....

    How to get the username in a custom password change routine / procedure / form when a user's password has expired and is redirected automatically to this custom program?
    We use the 2nd parameter in LOGIN_URL column in WWSSO_LS_CONFIGURATION_INFO$ table to get to this custom change-password proc.

    OK !
    Use that maybe good :
    select USERID into v_user from sys.aud$
      where ntimestamp#=(
      select max(ntimestamp#)
      from sys.aud$ );

  • My iPod Classic is not detected by my Windows 8 computer when I connect it via USB port.  How can I get windows to detect this device?

    My iPod Classic is not detected by my Windows 8 computer when I connect it via USB port.  How can I get windows to detect this device?  A message from windows says: the device has malfunctioned.

    Try TS1363: iPod: Appears in Windows but not in iTunes.
    See also Corrupt iPod classic.
    tt2

  • How do I get windows to connect to the internet on my iMac

    How do I get Windows 7 Home Premium to connect to my existing internet connection, on my iMac (Lion 10.7.3)?  The installation of the Windows 7 using Bootcamp went fine, up to the point of getting connected to the internet.  My iMac side of the partition connects to the internet just like it always did.

    You should ask this in the boot camp forum.
    You will probably get more help there.

  • Trying to download update to iTunes in Vista but get Windows installer error. How do I update?

    Trying to download update to iTunes but get Windows Installer error.  How do I correct?

    many thanks.
    "There is a problem with this Windows Installer package.  A program required for this install to complete could not be run.  Contact your support personnel or package vendor."
    Perhaps let's first try updating your Apple Software Update.
    Launch Apple Software Update ("Start > All Programs > Apple Software Update"). Does it launch and offer you a newer version of Apple Software Update? If so, choose to install just that update to Apple Software Update. (Deselect any other software offered at the same time.)
    If the ASU update goes through okay, try another iTunes install. Does it go through without the errors this time?

Maybe you are looking for