Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8613857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:58:55+00:00 2026-06-12T04:58:55+00:00

I am about to graduate from university with a web application that needs be

  • 0

I am about to graduate from university with a web application that needs be implemented at school, everything is working perfect and this needs to be ready before november but I’m having a real trouble taking care of the security. The application must be able to have different users with one or more different roles, ( user1: roles: student; user 2: admin, user 3: professor, boss ).

When a user logs in it should be redirected to a different view depending on the roles it has and then if he tries to access to resources not allowed for his role, an error page should be shown.

This is what I’ve tried so far:

Method 1:

Authentication Method: Specified in web.xml as

<login-config>
   <auth-method>FORM</auth-method>
   <form-login-config>
      <form-login-page>/login.jsp</form-login-page>
   </form-login-config>
</login-config>

Then using the names j_username and j_password along with j_security_check on a custom jsp.

Authorization Method: Used Container Security (Tomcat) via DataSourceRealm, wich allow us to connect to a database and get the user and the roles associated with him from 2 Tables that need to be mapped in the server.xml:

<Resource auth="Container" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" maxActive="100" maxIdle="30" maxWait="1000" name="jdbc/sstt" password="pass" type="javax.sql.DataSource" url="jdbc:sqlserver://localhost;databaseName=BDTT" username="sa"/>

web.xml:

<security-constraint>

    <web-resource-collection>
        <web-resource-name>Students Only</web-resource-name>
        <url-pattern>/student/*</url-pattern>
    </web-resource-collection>

    <auth-constraint>
        <role-name>student</role-name>
    </auth-constraint>

</security-constraint>

// Same mapping for professor, admin, and boss (/professor/* maps to professor role)

Results: Whenever I tried to access a restricted area, for example, /members/ (configured in the web.xml inside a security constraint) it would work just perfect, so authorization goal was achieved.

The problem:
When I submit the login form it fires the j_security_check so I’m not able to fire a Struts2 Action that could help me to redirect depending on the user roles this is the main problem. Everything was perfect but I can’t find a way to redirect after logging in with the Container security.

Method 2:

Authentication Method: A LoginAction class that queries the database and checks if the password is correct. It also checks on the user roles and here we should be able to return a String like “admin”, or “student” and redirect to the appropriate index.jsp resource, but that would work only if users were allowed to have only one role, but they can have many, so how should the view be constructed depending on the total user roles? What String would we return?

Authorization Method: I wrote a custom Interceptor wich retrieves the User object from the session (this User object should be in the session only if the user authenticated successfully) and then perform the authorization logic here.

The problem:
Unable to find a way to construct a view depending on several roles, and the problem about the Interceptor is that it only protects my actions, so the authorization goal was achieved but only on actions, that means I could write /students/ and the URL would change to /students/index.jsp without even trying to authorize.

Other plans

I was thinking that maybe I could use filters to achieve the authorization ( that way I could protect both the dynamic and static resources ) but I don’t know if that would be a good practice since we have configured the Struts2 filter which maps to /*

I was also looking that I could use JAAS or Spring Security but I don’t know if I could achieve this, authenticate, redirect based on roles and authorizate. I wouldn’t want to spend more several hours to find out that I can’t do what I need, and I have just a very short time to finish this.

Other questions

Is it really a good practice to put jsp under WEB-INF? if so I should rewrite all the access to my jsp’s in the struts.xml to WEB-INF/jsp/students/index.jsp? ( for example ). Or should I stick to a security constraint defined in web.xml to avoid direct access to the /jsp/* url pattern?

Thank You very much in advance for all your time and help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:58:56+00:00Added an answer on June 12, 2026 at 4:58 am

    For problem in method 1: You can write Struts2 interceptor to achieve what you want.

    For Spring Security examples see my answer to this question https://stackoverflow.com/questions/12615354/how-to-implement-role-based-login/12629731#12629731

    And YES it is a good practice to put jsp under WEB-INF folder. See Why put JSP in WEB-INF?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for my final exam (to graduate from university) I’ve been asked to create a
This is my models.py from django.db import models class School(models.Model): school = models.CharField(max_length=300) def
About six years ago, a software engineer named Harri Porten wrote this article ,
For my graduate research I am creating a neural network that trains to recognize
I have a simple django app that is using only the admin. This is
I am a beginner in android programming. My Graduate project is about tracking a
I am a fresh graduate with a bachelor in Computer Science. As most school
About a dozen users have complained that my app that fetches photos they are
About two months ago, I upgraded a SilverStripe website from 2.3.5 to 2.4.6. Since
About a year ago, a manager in another department brainstormed that I could code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.