Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

j_security_check

Posted on 2007-03-19
10
Medium Priority
?
3,387 Views
Last Modified: 2013-12-02
i'm using form based security in jboss with j_security_check

the problem is when i access login.jsp directly and try to login it gives an invalid page reference error 400.  

how can i make it so that u can login by going to the login.jsp directly and then it sends you to a page based on the role of your entered username?  if ur the admin role it sends to admin.jsp and if its in user role it sends to somethingelse.jsp
0
Comment
Question by:wrynn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 19

Accepted Solution

by:
ramazanyich earned 2000 total points
ID: 18778064
First of all you should not go directly to login.jsp.
You just call a protected page (protected by <security-constraint> element ) and Tomcat (web server of jboss) will first  call login.jsp to perform authentication and if it is succesful will load protected page. In this page you can check then user roles and forward to necessary URL based on role.

Let illustrate it with an example.
So you have following directory structure in your webapp:
/
-login.jsp
 protected/
 protected/firstpage.jsp
 protected/admin/...
 protected/usualuser/....

in your web.xml you add following:
---
<web-app>
....
<security-constraint>
        <web-resource-collection>
              <web-resource-name>Sample Application</web-resource-name>
              <description>Require users to authenticate</description>
              <url-pattern>/protected</url-pattern>
              <http-method>POST</http-method>
              <http-method>GET</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>admin</role-name>
            <role-name>others</role-name>
        </auth-constraint>
            <user-data-constraint>
                  <transport-guarantee>NONE</transport-guarantee>
            </user-data-constraint>
      </security-constraint>
      <security-role>
            <description>admin users</description>
            <role-name>admin</role-name>
      </security-role>
      <security-role>
            <description>Other users</description>
            <role-name>others</role-name>
      </security-role>
      <login-config>
            <auth-method>FORM</auth-method>
            <form-login-config>
                  <form-login-page>/login.jsp</form-login-page>
                  <form-error-page>/login.jsp</form-error-page>
            </form-login-config>
      </login-config>

...
</web-app>
---

In your firstpage.jsp you do checkup user roles and based on that forward to necessary URL:
<%if(request.isUserInRole("admin")){%>
        request.forward("admin/");
      <%}%>
<%if(request.isUserInRole("others")){%>
        request.forward("usualuser/");
      <%}%>

Deploy your web app. And in browser enter http://your-host:8080/yourwebappPath/protected/firstpage.jsp

And based on your user role you will be redirected to necessary page
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 19110692
Hi,

drop the prefix "/" from the url pattern and try ...

R.K
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:ramazanyich
ID: 19311794
I think my answer could be accepted as correct one. We had exactly the sameproblem and my solution works perfectly and explains the behaviour
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 19312533
i would say still drop the prefix "/" from the url pattern , it will work...
0
 
LVL 20

Expert Comment

by:Venabili
ID: 19314934
I kinda love experts that ignore pings and then come asking for points.

ramazanyich,

The question is how to go to it directly. Yes - you are giving a nice idea but unless the asker shows up, it does not really answer the question, does it? For all we know - he may have some business reason to want it like this.

rama,
From which pattern? Where do you know what he has in the prefix when he had never posted a pattern? :)
0
 
LVL 19

Expert Comment

by:ramazanyich
ID: 19316657
The way it is asked will not work in Tomcat. I was  facing the same problem during of one of my implementations.
I want just call j_security_check from my URL, but got error 400. It works only the way I described
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
Upgrading Tomcat – There are a couple of methods to upgrade Tomcat is to use The Apache Installer is to download and unzip and run the services.bat remove|install Tomcat6 Because of the App that we are working with, we can only use Tomcat 6.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

670 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