PDA

View Full Version : Restricting access to jsp pages in Filters



tech99sri
04-25-2008, 09:59 PM
Hi ,
I am using a filter to prevent direct access to jsp pages (everything works fine). But I have 2 pages that should not be "filtered" when the url is given.
Like the welcome.jsp page . When the user gives welcome.jsp page it should not be forwarded to the login.jsp page (I am redirecting all the other jsp pages to login.jsp page) .
I dont want to hard code it using if () stmts in the filter.
Please provide me the solution so tht when the user enters the welcome.jsp , he is directed to welcome.jsp page instead of login.jsp page.
Is there any way to do it in the web.xml.
thanks

shyam
04-26-2008, 11:31 AM
you could specify the pages u want to be ignored by the filter in the form of initialization parameters which can be specified in web.xml

tech99sri
04-27-2008, 03:23 AM
Hello Shyam ,
Thanks for the reply.
How do I specify these jsp pages in the web.xml .
Can u please provide me the sample code .
Where do I need to initialize the parameters (is tht inside the filter declaration ??) .
Please provide the solution

shyam
04-27-2008, 05:31 AM
<filter>
<filter-name>my-filter</filter-name>
<filter-class>org.foo.bar.MyFilter</filter-class>
<init-param>
<param-name>allow-without-auth</param-name>
<param-value>/welcome.jsp</param-value>
</init-param>
</filter>

tech99sri
04-28-2008, 05:11 AM
Hi Shyam ,
I made the changes you suggested in the web.xml , but the filer still filters the welcome.jsp and redirects to the login.jsp page .
Do I need to add any code anywhere other than the web.xml (I just added the
<init-param>
<param-name>allow-without-auth</param-name>
<param-value>/welcome.jsp</param-value>
</init-param> in the web.xml )

this is my web.xml --

<filter>
<filter-name>filter</filter-name>
<filter-class>
RedirectFilter
</filter-class>
<init-param>
<param-name>allow-without-auth</param-name>
<param-value>/welcome.jsp</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>filter</filter-name>
<servlet-name>RedirectFilter</servlet-name>

<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<!-- <url-pattern>*.jsf</url-pattern> -->
</filter-mapping>

<filter-mapping>
<filter-name>filter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>

----
---

Please help me solve this prob
thanks

shyam
04-28-2008, 06:14 PM
just adding the init-param isn't gonna magically do anything...you've to code in the Filter to take appropriate action based on the specified params