Solved

j_security_check

Posted on 2007-03-19
10
3,300 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:mayankeagle
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now