Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getRemoteUser is null

Status
Not open for further replies.

RicardoPereira

Programmer
Jun 3, 2003
255
PT
Hi,

I'am trying to get the username of windows 2000 using the getRemoteUser method but i'am having always the null value.
What could be the problem and how should i resolve them?

Thanks
Ricardo Pereira
 
Are you using HTTP Authentication? If not that header will not exist.

-pete
 
Look my validation code:

<%@ page import=&quot;java.sql.*&quot; %>
<%@ page import=&quot;java.util.*&quot; %>
<%@ page import=&quot;java.text.*&quot; %>

<%

Connection connection = null;
ResultSet SQLRetorno = null;
ResultSet SQLRetorno_cons = null;
Statement SQLQuery = null;
String consulta = null;

int erro = 0;
int errado = 0;
int certo = 0;
String erro_str = &quot;erro&quot;;
String contador = &quot;&quot;;
String user = &quot;&quot;;



Class.forName(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;).newInstance();
connection = DriverManager.getConnection(&quot;jdbc:eek:dbc:sqlintranet&quot;);
SQLQuery = connection.createStatement();


String host = request.getRemoteHost();
String remoteuser = request.getRemoteHost();

%>

<%
String consulta_cons=&quot;SELECT distinct COUNT(*),loginame,hostname FROM [master].[dbo].[sysprocesses] &quot; +
&quot; WHERE hostname ='&quot; + host + &quot;' group by loginame,hostname&quot;;
SQLRetorno_cons = SQLQuery.executeQuery( consulta_cons );


while ( SQLRetorno_cons.next() ) {
contador = SQLRetorno_cons.getString(1);
session.setAttribute(&quot;utilizador&quot;,SQLRetorno_cons.getString(2));
session.setAttribute(&quot;hostname&quot;,SQLRetorno_cons.getString(3));
}


%>

<%
if (!contador.equals(&quot;0&quot;)){
session.setAttribute(&quot;nivel&quot;, host);


%>

<INPUT TYPE=&quot;hidden&quot; NAME=&quot;username&quot; VALUE=&quot;<%= user %>&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;hostname&quot; VALUE=&quot;<%= host %>&quot;>
<jsp:forward page=&quot;teste/index.jsp&quot;>
<jsp:param name=&quot;username&quot; value=&quot;<%= user %>&quot; />
</jsp:forward>

<%
}
%>

<%
if (contador.equals(&quot;0&quot;)){
%>


<INPUT TYPE=&quot;hidden&quot; NAME=&quot;username&quot; VALUE=&quot;<%= user %>&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;hostname&quot; VALUE=&quot;<%= host %>&quot;>
<jsp:forward page=&quot;teste/index1.jsp&quot;>
<jsp:param name=&quot;username&quot; value=&quot;<%= user %>&quot; />
</jsp:forward>


<%
}
%>



<body>
<CENTER>
</CENTER>
</BODY>
</HTML>
 
>> String user = &quot;&quot;;

the variable user is initialized to an empty string and never changed in the code you posted. Therefore it will be an empty string right? I don't understand your question.

-pete
 
Here is what i want:

I have one sql server 2000 database, webserver tomcat and i want to build an intranet with all permissions set on SQL server (one user to access sql server must be register in sql server with windows authentication).
When the user access the internet i want to get his windows username to establish the connection with sql server.
This coulb be possible if getRemoteUser() methot dont return null value. With null value i cannot estabelish permission for each type of user.

How can i get the windows username using the jsp?

 
I just want to estabelish the connection with sql server using the windows authentication.
Where can i get an jdbc driver that allow trustedAuthentication ?
 
RicardoPereira,

I've got to say here, people are trying to help you and you are clearly not listening. Just posting your code and demanding people to look at it is not going to get you very far, nor will constantly restating your wishes.

As the other guys have said - you will not be able to authenticate your user unless http authentication is enabled.
Please read the suggestions others have given !

 
Hi,

For establishing connection with SQL Server you can use
microsoft dirver. In your class path you need have the following jar files

mssqlserver.jar
msutil.jar
msbase.jar

Cheers,
venu
 
What i want is estabelish the connection with sql server 2000 using the windows 2000 definition. But i think the microsoft JDBC driver doesn't support trusted connections.
Anyone have a idea how to connect with trusted connection?

Thanks
Ricardo Pereira
 
Hi,

I dont think this is the answer you are looking for, but It might help you.

You need to use SQL Server authentication and it sounds like your instance of SQLServer is configured for Windows authentication only. To change the authentication mode, from Enterprise Manager right click on the instance and
select properties. On the security tab, change the authentication mode to the SQL Server and Windows option.

Cheers
Venu
 
Thanks for the help venur but what i want is jsp authentication with windows definitions.
To do this i need an JDBC driver that support trusted connection. That's what i'm looking for.
 
>>But i think the microsoft JDBC driver doesn't support trusted connections.
>> Anyone have a idea how to connect with trusted connection?

First i don't know that the microsoft JDBC driver does not support trusted connection. However if that is correct then you can shop for a commercial third party driver that does. sun maintains a list of JDBC driver vendors at java.sun.com

Is that what you are looking for?


-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top