Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2005

Tip: Looking for answers? Try searching our database.

User Access with Struts

Thread view: 
boanator@gmail.com - 28 Sep 2005 16:44 GMT
I am developing a Struts web application.  This application will
require users to login with a username and password.  Each user will
have different access levels.

I will not be using role-based access b/c there are too many services
and too many access levels.  Let's say there are 10 services.  If a
user has access to a service, he will have read permission or
read/write permission to that service.  I would like to set up bitflags
to determine the user's access level.
Ex)
// Contents of Constants.java
...
public final static int service_1_read = 1
public final static int service_1_read_write = 2
public final static int service_2_read = 4
public final static int service_2_read_write = 8
public final static int service_3_read = 16
public final static int service_3_read_write = 32
...

When a user logs in to the website, the user information will be stored
in the session.

I am using Tiles to design the layout of my website.  The tiles are
setup using definitions in tiles-defs.xml.  I load the pages using the
definitions.  For example:
// Contents of /service_1_index.jsp
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>

<tiles:insert definition="service1.index" />

This will allow the index for service1 to be displayed.  I was thinking
of adding a check for user access to /service_1_index.jsp to look like
the following:
// New Contents of /service_1_index.jsp that checks user access
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>
<%@ page import="com.myco.constants.Constants" %>

<% User user = (User)session.getAttribute("User");
if ( user.hasAccess(Constants.service_1_read) ||
user.hasAccess(Constants.service_1_read_write) ) {
%>
<tiles:insert definition="service1.index" />
<% } else { %>
<tiles:insert definition="access.denied" />
<% } %>

I know that this will work, but it goes against the whole purpose of
using Struts!!  Keep java code out of the JSP files!!!!!  Is there a
way that I can use the Tiles Controller?  There has to be a better
way!!!

Any advice would help.  Thanks in advance.
boanator@gmail.com - 28 Sep 2005 20:30 GMT
I have decided to try the logic tag library to determine user access.
When the user logs in, I will set some session variables:
hasServiceOneAccess = true or false
hasServiceTwoAccess = true or false
hasServiceThreeAccess=true or false
...

Now the /service_1_index.jsp page will look like this:
<%@ taglib prefix="tiles" uri="/tags/struts-tiles" %>
<%@ taglib prefix="logic" uri="/tags/struts-logic" %>

<logic:equal name="hasServiceOneAccess" value="true">
 <tiles:insert definition="service1.index" />
</logic:equal>

<logic:equal name="hasServiceOneAccess" value="false">
 <tiles:insert definition="access.denied" />
</logic:equal>

There is redundant code for each service page, but I have not found
another way to get around this.  Also, I have taken the business logic
out of the JSP file.  If anyone has a better solution to this problem,
please let me know.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.