G
gbattine
Hi guys,
excuse me if i repeat a my old post,but now i have more clear ideas
about problems.
I've developed an authorization filter in my jsf application that when
a page is loaded try to find a visit object in the session,if it
doesn't find show login page.
It's simple as concept,but in my application my filter doesn't start!
Can you help me?
My filter is very simple
package giu;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
public class AuthorizationFilter implements Filter
{
FilterConfig config = null;
ServletContext servletContext = null;
public AuthorizationFilter()
{
}
public void init(FilterConfig filterConfig) throws ServletException
{
config = filterConfig;
servletContext = config.getServletContext();
}
public void doFilter(ServletRequest request, ServletResponse
response,
FilterChain chain) throws IOException,
ServletException
{
Utils.log(servletContext, "Inside the filter");
HttpServletRequest httpRequest = (HttpServletRequest)request;
HttpServletResponse httpResponse = (HttpServletResponse)response;
HttpSession session = httpRequest.getSession();
String requestPath = httpRequest.getPathInfo();
Visit visit = (Visit)session.getAttribute("visit");
if (visit == null)
{
session.setAttribute("originalTreeId",
httpRequest.getPathInfo());
Utils.log(servletContext, "redirecting to " +
httpRequest.getContextPath() +
"/faces/Login.jsp");
httpResponse.sendRedirect(httpRequest.getContextPath() +
"/faces/Login.jsp");
}
else
{
session.removeAttribute("originalTreeId");
String role = visit.getUser().getRole(); }
Utils.log(servletContext, "Exiting the filter");
}
public void destroy()
{
}
}
my Login.jsp and index.jsp pages are in WebContent folder,while the
other pages are in the Webcontent/protected.
What i miss?
Here is my web.xml, i thing the error is here,it's how filter doesn't
intercept the requests...can you help me?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<filter>
<filter-name>AuthorizationFilter</filter-name>
<filter-class>giu.AuthorizationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthorizationFilter</filter-name>
<url-pattern>/faces/protected/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/nomedb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
and index.jsp
<jsp:forward page="/Login.jsf"/>
excuse me if i repeat a my old post,but now i have more clear ideas
about problems.
I've developed an authorization filter in my jsf application that when
a page is loaded try to find a visit object in the session,if it
doesn't find show login page.
It's simple as concept,but in my application my filter doesn't start!
Can you help me?
My filter is very simple
package giu;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
public class AuthorizationFilter implements Filter
{
FilterConfig config = null;
ServletContext servletContext = null;
public AuthorizationFilter()
{
}
public void init(FilterConfig filterConfig) throws ServletException
{
config = filterConfig;
servletContext = config.getServletContext();
}
public void doFilter(ServletRequest request, ServletResponse
response,
FilterChain chain) throws IOException,
ServletException
{
Utils.log(servletContext, "Inside the filter");
HttpServletRequest httpRequest = (HttpServletRequest)request;
HttpServletResponse httpResponse = (HttpServletResponse)response;
HttpSession session = httpRequest.getSession();
String requestPath = httpRequest.getPathInfo();
Visit visit = (Visit)session.getAttribute("visit");
if (visit == null)
{
session.setAttribute("originalTreeId",
httpRequest.getPathInfo());
Utils.log(servletContext, "redirecting to " +
httpRequest.getContextPath() +
"/faces/Login.jsp");
httpResponse.sendRedirect(httpRequest.getContextPath() +
"/faces/Login.jsp");
}
else
{
session.removeAttribute("originalTreeId");
String role = visit.getUser().getRole(); }
Utils.log(servletContext, "Exiting the filter");
}
public void destroy()
{
}
}
my Login.jsp and index.jsp pages are in WebContent folder,while the
other pages are in the Webcontent/protected.
What i miss?
Here is my web.xml, i thing the error is here,it's how filter doesn't
intercept the requests...can you help me?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<filter>
<filter-name>AuthorizationFilter</filter-name>
<filter-class>giu.AuthorizationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthorizationFilter</filter-name>
<url-pattern>/faces/protected/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/nomedb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
and index.jsp
<jsp:forward page="/Login.jsf"/>