Solved

j_security_check

Posted on 2007-03-19
10
3,319 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
10 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 18750357
0
 
LVL 19

Accepted Solution

by:
ramazanyich earned 500 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Allow Firefox to use Java 6 plugin? 15 46
runtime exception and error differences 4 78
maven set up 2 142
servlet example 17 29
-Xmx and -Xms are the two JVM options often used to tune JVM heap size.   Here are some common mistakes made when using them:   Assume BigApp is a java class file for the below examples. 1.         Missing m, M, g or G at the end …
This article is about some of the basic and important steps to be used to improve the performance in web-sphere commerce application development. 1) Always leverage the Dyna-caching facility provided by the product 2) Remove the unwanted code …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

785 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