You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rapthor <ra...@lycos.de> on 2006/03/25 14:14:46 UTC
Get JDBCRealm's current user
Hello,
how is it possible to retrieve the user currently logged in via JDBCRealm? I
know how to check if the user is in some role (isUserInRole(name)). But how
do I get the username?
--
View this message in context: http://www.nabble.com/Get-JDBCRealm%27s-current-user-t1341315.html#a3586626
Sent from the Tomcat - User forum at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get JDBCRealm's current user
Posted by Rapthor <ra...@lycos.de>.
request.getRemoteUser() was the method I was searching for! Thanks :)
--
View this message in context: http://www.nabble.com/Get-JDBCRealm%27s-current-user-t1341315.html#a3731063
Sent from the Tomcat - User forum at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get JDBCRealm's current user
Posted by David Smith <dn...@cornell.edu>.
Why can't you just use request.getRemoteUser()? It provides the
username the user logged in with whether it be from BASIC auth or form
based auth.
--David
Rapthor wrote:
>Sorry, here's what I do:
>
>I have a web application and used Tomcat's Authentication mechanism called
>JDBCRealm. I had to edit server.xml to do so (this is not really the details
>I entered, it's just an example):
>
><Realm className="org.apache.catalina.realm.JDBCRealm"
>driverName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
>connectionURL="jdbc:microsoft:sqlserver://kebab.ucsd.edu:1433"
>connectionName="CSE135_XX" connectionPassword="XXXXXXXX"
>userTable="users" userNameCol="user_name" userCredCol="user_pass"
>userRoleTable="user_roles" roleNameCol="role_name" />
>
>Then I created the according tables:
>
>create table users
>(
> user_name varchar(15) not null primary key,
> user_pass varchar(15) not null
>);
>
>create table user_roles
>(
> user_name varchar(15) not null,
> role_name varchar(15) not null,
> primary key( user_name, role_name )
>);
>
>There is a user admin in the table "users" with "admin_role" (in the table
>user_roles). There are other users with other names and other roles.
>
>The web.xml got these additional entries:
>
><security-constraint>
><web-resource-collection>
> <web-resource-name>SecurePages</web-resource-name>
> <description>Security constraint /secure</description>
> <url-pattern>/secure/*</url-pattern>
></web-resource-collection>
><auth-constraint>
> <role-name>admin</role-name>
> </auth-constraint>
></security-constraint>
>
><login-config>
> <auth-method>FORM</auth-method>
> <form-login-config>
> <form-login-page>/login.jsp</form-login-page>
> <form-error-page>/loginerror.jsp</form-error-page>
> </form-login-config>
></login-config>
><security-role>
> <role-name>admin</role-name>
></security-role>
>
>
>This is everything (or at least the most important things) I had to do to
>configure everything. Now what I want to know is, which user is logged in at
>a certain moment ... I want to know it when I create JSPs for example to
>show the user's name (equal to the name in the users table).
>
>Do you know what I meant to achieve? I don't want to get the database's
>user, which would be "CSE135_XX" in the above JDBCRealm example ...
>--
>View this message in context: http://www.nabble.com/Get-JDBCRealm%27s-current-user-t1341315.html#a3657607
>Sent from the Tomcat - User forum at Nabble.com.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get JDBCRealm's current user
Posted by Martin Gainty <mg...@hotmail.com>.
you can do this one of 2 ways
1)create a bunch of tables which have entities defined like users and roles and such
this way you can look up the user which has a specific 'role' or user is defined within a group which has certain 'role'
this solution is probably the closest to your current effort..
2)Look at a security management package such as jetspeed which will
define your roles
define groups
define users
then..define which role (capabilities) do the groups and or users support
Take a look at
http://portals.apache.org/jetspeed-2/getting-started.html
Pay close attention to how to configure Jetspeed as a servlet engine
HTH,
Martin--
----- Original Message -----
From: "Rapthor" <ra...@lycos.de>
To: <us...@tomcat.apache.org>
Sent: Wednesday, March 29, 2006 3:06 PM
Subject: Re: Get JDBCRealm's current user
>
> Sorry, here's what I do:
>
> I have a web application and used Tomcat's Authentication mechanism called
> JDBCRealm. I had to edit server.xml to do so (this is not really the details
> I entered, it's just an example):
>
> <Realm className="org.apache.catalina.realm.JDBCRealm"
> driverName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
> connectionURL="jdbc:microsoft:sqlserver://kebab.ucsd.edu:1433"
> connectionName="CSE135_XX" connectionPassword="XXXXXXXX"
> userTable="users" userNameCol="user_name" userCredCol="user_pass"
> userRoleTable="user_roles" roleNameCol="role_name" />
>
> Then I created the according tables:
>
> create table users
> (
> user_name varchar(15) not null primary key,
> user_pass varchar(15) not null
> );
>
> create table user_roles
> (
> user_name varchar(15) not null,
> role_name varchar(15) not null,
> primary key( user_name, role_name )
> );
>
> There is a user admin in the table "users" with "admin_role" (in the table
> user_roles). There are other users with other names and other roles.
>
> The web.xml got these additional entries:
>
> <security-constraint>
> <web-resource-collection>
> <web-resource-name>SecurePages</web-resource-name>
> <description>Security constraint /secure</description>
> <url-pattern>/secure/*</url-pattern>
> </web-resource-collection>
> <auth-constraint>
> <role-name>admin</role-name>
> </auth-constraint>
> </security-constraint>
>
> <login-config>
> <auth-method>FORM</auth-method>
> <form-login-config>
> <form-login-page>/login.jsp</form-login-page>
> <form-error-page>/loginerror.jsp</form-error-page>
> </form-login-config>
> </login-config>
> <security-role>
> <role-name>admin</role-name>
> </security-role>
>
>
> This is everything (or at least the most important things) I had to do to
> configure everything. Now what I want to know is, which user is logged in at
> a certain moment ... I want to know it when I create JSPs for example to
> show the user's name (equal to the name in the users table).
>
> Do you know what I meant to achieve? I don't want to get the database's
> user, which would be "CSE135_XX" in the above JDBCRealm example ...
> --
> View this message in context: http://www.nabble.com/Get-JDBCRealm%27s-current-user-t1341315.html#a3657607
> Sent from the Tomcat - User forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Get JDBCRealm's current user
Posted by Rapthor <ra...@lycos.de>.
Sorry, here's what I do:
I have a web application and used Tomcat's Authentication mechanism called
JDBCRealm. I had to edit server.xml to do so (this is not really the details
I entered, it's just an example):
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
connectionURL="jdbc:microsoft:sqlserver://kebab.ucsd.edu:1433"
connectionName="CSE135_XX" connectionPassword="XXXXXXXX"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
Then I created the according tables:
create table users
(
user_name varchar(15) not null primary key,
user_pass varchar(15) not null
);
create table user_roles
(
user_name varchar(15) not null,
role_name varchar(15) not null,
primary key( user_name, role_name )
);
There is a user admin in the table "users" with "admin_role" (in the table
user_roles). There are other users with other names and other roles.
The web.xml got these additional entries:
<security-constraint>
<web-resource-collection>
<web-resource-name>SecurePages</web-resource-name>
<description>Security constraint /secure</description>
<url-pattern>/secure/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/loginerror.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
This is everything (or at least the most important things) I had to do to
configure everything. Now what I want to know is, which user is logged in at
a certain moment ... I want to know it when I create JSPs for example to
show the user's name (equal to the name in the users table).
Do you know what I meant to achieve? I don't want to get the database's
user, which would be "CSE135_XX" in the above JDBCRealm example ...
--
View this message in context: http://www.nabble.com/Get-JDBCRealm%27s-current-user-t1341315.html#a3657607
Sent from the Tomcat - User forum at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get JDBCRealm's current user
Posted by Martin Gainty <mg...@hotmail.com>.
A construction worker in Antartica once said
"No matter how many times I cut it ..it still is too short"
the same scenario applies here
JDBC is a driver model for DB access
a package designed primarily for DB access would not have knowledge of other environmental and or configuration items..right?
I can better help you if you provide me some info on the ultimate goal,
HTH,
Martin--
----- Original Message -----
From: "Rapthor" <ra...@lycos.de>
To: <us...@tomcat.apache.org>
Sent: Wednesday, March 29, 2006 12:18 PM
Subject: Re: Get JDBCRealm's current user
>
> Using the #InitialContext().lookup() method to get the DataSource, it seems
> to get to the point that I find out the user connected to the database,
> which in fact is another than the user logged in via JDBCRealm?! Am I right?
> I wanted to get the user currently logged in, not the one using the
> database.
>
> Can you still help me?
> --
> View this message in context: http://www.nabble.com/Get-JDBCRealm%27s-current-user-t1341315.html#a3654460
> Sent from the Tomcat - User forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Get JDBCRealm's current user
Posted by Rapthor <ra...@lycos.de>.
Using the #InitialContext().lookup() method to get the DataSource, it seems
to get to the point that I find out the user connected to the database,
which in fact is another than the user logged in via JDBCRealm?! Am I right?
I wanted to get the user currently logged in, not the one using the
database.
Can you still help me?
--
View this message in context: http://www.nabble.com/Get-JDBCRealm%27s-current-user-t1341315.html#a3654460
Sent from the Tomcat - User forum at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get JDBCRealm's current user
Posted by Martin Gainty <mg...@hotmail.com>.
If you have JNDI you can look it up that way for example
Context initialContext = new InitialContext();
DataSource datasource = (DataSource)initialContext.lookup(fDATASOURCE_CONTEXT);
Martin-
----- Original Message -----
From: "Rapthor" <ra...@lycos.de>
To: <us...@tomcat.apache.org>
Sent: Wednesday, March 29, 2006 4:24 AM
Subject: Re: Get JDBCRealm's current user
>
> Okay, I think I nearly get it.
>
> What do I have to do to get the DataSource from within a JSP page? Get the
> "ServletContext"? There's no method to do a lookup for a DataSource with
> ServletContext.
> --
> View this message in context: http://www.nabble.com/Get-JDBCRealm%27s-current-user-t1341315.html#a3646592
> Sent from the Tomcat - User forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Get JDBCRealm's current user
Posted by Rapthor <ra...@lycos.de>.
Okay, I think I nearly get it.
What do I have to do to get the DataSource from within a JSP page? Get the
"ServletContext"? There's no method to do a lookup for a DataSource with
ServletContext.
--
View this message in context: http://www.nabble.com/Get-JDBCRealm%27s-current-user-t1341315.html#a3646592
Sent from the Tomcat - User forum at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get JDBCRealm's current user
Posted by Martin Gainty <mg...@hotmail.com>.
Rapthor-
take a look at http://developer.mimer.com/howto/howto_29.htm
JDBCRealm is a technique for storing user information in a database.
Where JDBCRealm info is accessed via your connection handle (and hopefully acquired from connection pool ) defined within server.xml as in this example
<Resource name="jdbc/MimerPool" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/WhateverPoolYouAreUsing">
<parameter>
<name>user</name>
<value>HOTELADM</value>
</parameter>
<parameter>
<name>password</name>
<value>HOTELADM</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mimer.jdbc.Driver</value>
</parameter>
<parameter>
<name>driverName</name>
<value jdbc:mimer://localhost/UniqueNameForYourDriver</value>
</parameter>
</ResourceParams
more specifically DataSource is defined within your app's web.xml as in
<resource-ref>
<resource-ref-name>jdbc/WhateverPoolYouAreUsing</resource-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
To quote mimer.com doc:
JDBCRealm is a technique for storing user information in a database. The first step to enable storing user information is to create the necessary tables.
(The context is where the connection handle is typically stored..)
Context = new InitialContext();
Get a data source, for example:
DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/WhateverPoolYouAreUsing");
Get a connection, for example:
Connection con = ds.getConnection();
the connection handle will be used to access JDBCRealm information-
Martin--
----- Original Message -----
From: "Rapthor" <ra...@lycos.de>
To: <us...@tomcat.apache.org>
Sent: Monday, March 27, 2006 5:49 AM
Subject: Re: Get JDBCRealm's current user
>
> I didn't find the ConnectionHandle ... it's an interface but where is my
> instance of "ConnectionHandle"? Do I get it by using one of the Servlet's
> request, response or session objects?
> --
> View this message in context: http://www.nabble.com/Get-JDBCRealm%27s-current-user-t1341315.html#a3607425
> Sent from the Tomcat - User forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Get JDBCRealm's current user
Posted by Rapthor <ra...@lycos.de>.
I didn't find the ConnectionHandle ... it's an interface but where is my
instance of "ConnectionHandle"? Do I get it by using one of the Servlet's
request, response or session objects?
--
View this message in context: http://www.nabble.com/Get-JDBCRealm%27s-current-user-t1341315.html#a3607425
Sent from the Tomcat - User forum at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get JDBCRealm's current user
Posted by Martin Gainty <mg...@hotmail.com>.
Just a Cursory answer from google-
ConnectionHandle.getMetaData().getUserName().
Anyone else?
Viel Gluck,
Martin-
----- Original Message -----
From: "Rapthor" <ra...@lycos.de>
To: <us...@tomcat.apache.org>
Sent: Saturday, March 25, 2006 8:14 AM
Subject: Get JDBCRealm's current user
>
> Hello,
>
> how is it possible to retrieve the user currently logged in via JDBCRealm?
> I
> know how to check if the user is in some role (isUserInRole(name)). But
> how
> do I get the username?
> --
> View this message in context:
> http://www.nabble.com/Get-JDBCRealm%27s-current-user-t1341315.html#a3586626
> Sent from the Tomcat - User forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org