Solved

j_security_check

Posted on 2007-03-19
10
3,329 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

-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 …
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.…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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