[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

how to check user Authencation from Database

Posted on 2004-08-27
12
Medium Priority
?
267 Views
Last Modified: 2010-05-18
HI,

I need a help from experts, I'm using Tomcat 5.0: I have login page, upon submit it should display inner pages depending upon the autheticating status. While Adding Users I have this option if he/she can be "Read Only" or "Admin".

Read Only can only view inner pages, where as Admin can view inner pages and change certain part of inner pages if wanted to.

So please send me the steps to follow on this:
1. Upon submit of login page, how to identify its valide user ? (CHECKING FROM DATABASE)
2. Upon verfication of valide user, how to restrict "Read Only" user to view only but not able to change values on any pages.

NOTE:  I dont wanna check User/Password which is stored in the Tomcat XML, but rather I wanna check using Database query. Bcoz my application will be used by various clients and they can add user/pass with role as "Admin" or "Read Only" which all gets stored in the Database.

Regards,
Hyx
0
Comment
Question by:princehyderabad
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 13

Expert Comment

by:Murali Murugesan
ID: 11920582
U can do the following steps,

Once u get the username & password have them in the session attributes.

While loading the login page write to query to select all usernm,pwd & their permissions inside a global arrayList.

In each page thereafter check ur session attribute value across the array list to identify the permission.
HAve the permission loaded in a global variable like R-for read only and A-for Admin.

Using this value u can show the controls correspondingly.for eg: testbox or label..

if(per='A')
<input type=text .......>
else
<label ...>

This will sove ur problem i hope.

-Murali*
0
 
LVL 3

Expert Comment

by:Gunt
ID: 11921416
I would use the standard container security.
Tomcat supports use of a JDBC realm, so it doesn't check from the XML, but from a database.

Then, to programatically check the username/role, you can use the request methods getRemoteUser(), isUserInRole(String), etc.

To see how to set up Tomcat for this kind of authentication, see this link:
http://www.linux-sxs.org/internet_serving/c619.html

Good luck
0
 
LVL 6

Expert Comment

by:CodingExperts
ID: 11924311
One can use Tomcat to support container managed security, by connecting to an existing "database" of usernames, passwords, and user roles. You only need to care about this if you are using a web application that includes one or more <security-constraint> elements, and a <login-config> element defining how users are required to authenticate themselves.Tomcat 4 onwards defines a Java interface (org.apache.catalina.Realm) that can be implemented by "plug in" components to establish a JDBC connection.

Read More on this:
http://jakarta.apache.org/tomcat/tomcat-4.0-doc/realm-howto.html#JNDIRealm
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
LVL 6

Expert Comment

by:CodingExperts
ID: 11924500
0
 

Author Comment

by:princehyderabad
ID: 11933306
thx Guys, But with my application keep in mind the software we using, I think the best idea would be to go with Murali's steps.

Murali, can you please write in deatails along with a simple sample example for session setting attribute and checking from the DB etc., And I can take care from Displaying part....

Regards,
Hyd
0
 
LVL 3

Expert Comment

by:Gunt
ID: 11936875
As a side comment, I would put the logic from Murali's solution in the Tag, and not in the JSP.
If you go with the if in a scriptlet, you will have to make that check in EVERY JSP. Writing a page will be pretty painful.

Instead, you can write a custom JSP tag (or extend the ones you use), to check the security, and write an input box or a label (or whatever), depending upon user permissions.
That way, you program it once, and changes are centraliced.

http://www.javaworld.com/javaworld/jw-08-2000/jw-0811-jsptags.html
That's an interesting link on tag library development.
0
 
LVL 13

Expert Comment

by:Murali Murugesan
ID: 11939479
U do like this...I'll give u a raw example..

get the usrnm & pwd.

write a query in the login page like this...
select user_permission from authentication where
usrname like ? and pwd like ?.

So for this question maks [?] pass the variable values "usrnm" and "pwd".The result user_permission u load it to a session variable.say " permission".

Say the query might return either R-read only and A-Admin.
So load it into permission variable.

From the next page from login,u r first check shld be for the permission variable not equal to null,

if null throw message not a valid user..
Then chk whether permission has R or A and code like following

<%if(request.getParameter("permission").toString.equals("A")){%>
<input type=text.....>
<%}else{%>
<something for display only>
<%}%>

Similar way of coding in all pages would solve ur problem..This would be the easiest method i hope...

Hope i have done the maximum home work for u...

-Murali*
0
 

Author Comment

by:princehyderabad
ID: 11948171
Thx Murali,

I got your point and idea, but today I was told by manager to use "realms" as its easy to use and just it need a configuration thats it. What do you think ?
I'm in process of setting up realms in server.xml and then will try .....if any easy steps rather then the links above send by other plz let me know.

Once I go thru this U'll receive your point, a waada !!

Regards,
Hyd
0
 
LVL 13

Expert Comment

by:Murali Murugesan
ID: 11950966
Yes,
U can go thro realms too..the same thing which i explained u is given in a sophisticated way thats it..
There are different kinds of realms with tomcat.

-Murali*
0
 
LVL 13

Accepted Solution

by:
Murali Murugesan earned 800 total points
ID: 11951236
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After a recent Outlook migration from a 2007 to 2010 environment, some issues with Distribution List owners were realized. In this article, I explain how that was rectified.
The onset of year 2018 has been a usual business for IT teams still struggling to find their way out in terms of strengthening their cloud security.
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question