Integratio of Custom Filter Problem
mechtatel Dec 12, 2008 2:03 PMHi,
I'm using Eclipse 3.4.0 ganymede with JSF 1.2, Dynamic Web Module 2.5 and Facelets and RichFaces 3.2.2.
I'm developing a Facebook app. I´m implementing the Authentication layer in custom filter:
public class FaceBookAuthFilter implements Filter {
private String _apiKey;
private String _secretKey;
public void init(final FilterConfig filterConfig){
_apiKey = filterConfig.getInitParameter("api_key");
_secretKey = filterConfig.getInitParameter("secret_key");
}
/**
* Verifies whether user is logged in. If not, sends user to the login page.
*/
public void doFilter(final ServletRequest request, final ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) request;
HttpServletResponse httpRes = (HttpServletResponse) response;
try {
FacebookXmlRestClient authClient = FaceBookAuthHandler.getAuthenticatedClient(httpReq, _apiKey, _secretKey);
request.setAttribute("auth.client", authClient);
chain.doFilter(request, response);
} catch (FailedLoginException fle) {
//user not logged in
forceLogin(httpRes);
} catch (Exception e) {
//handle exception
System.out.println(e.toString());
}
}
/**
* Sends user to login page
* @param response
*/
private void forceLogin(HttpServletResponse response) {
try {
response.sendRedirect ("http://www.facebook.com/login.php?api_key=" + _apiKey + "&v=1.0");
} catch (IOException ioe) {
//handle exception
}
}
public void destroy() {
}
}
This is what I have in web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>AskAvila</display-name> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param> <welcome-file-list> <welcome-file>index.xhtml</welcome-file> <welcome-file>index.html</welcome-file> </welcome-file-list> <context-param> <param-name>org.richfaces.SKIN</param-name> <param-value>classic</param-value> </context-param> <context-param> <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name> <param-value>com.sun.facelets.FaceletViewHandler</param-value> </context-param> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> <filter> <filter-name>FaceBookAuthFilter</filter-name> <filter-class>util.FaceBookAuthFilter</filter-class> <init-param> <param-name>api_key</param-name> <param-value>[the api key]</param-value> </init-param> <init-param> <param-name>secret_key</param-name> <param-value>[the secret_key]</param-value> </init-param> </filter> <filter-mapping> <filter-name>FaceBookAuthFilter</filter-name> <url-pattern>/faces/*</url-pattern> </filter-mapping> <filter> <display-name>RichFaces Filter</display-name> <filter-name>richfaces</filter-name> <filter-class>org.ajax4jsf.Filter</filter-class> </filter> <filter-mapping> <filter-name>richfaces</filter-name> <servlet-name>Faces Servlet</servlet-name> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> </web-app>
Adding the custom filter I receive a blank page, richfaces don´t work propertly. How can I integrate propertly the custom filter, without having conflict with RichFaces filter?