Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

how to check user Authencation from Database

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
princehyderabad
Asked:
princehyderabad
  • 4
  • 2
  • 2
  • +1
1 Solution
 
Murali MurugesanFull stack Java developerCommented:
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
 
GuntCommented:
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
 
CodingExpertsCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
CodingExpertsCommented:
0
 
princehyderabadAuthor Commented:
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
 
GuntCommented:
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
 
Murali MurugesanFull stack Java developerCommented:
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
 
princehyderabadAuthor Commented:
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
 
Murali MurugesanFull stack Java developerCommented:
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
 
Murali MurugesanFull stack Java developerCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now