UserRoleFilter.java
// license-header java merge-point
// Generated by andromda-jsf cartridge (utils\UserRoleFilter.java.vsl) DO NOT EDIT!
package org.andromda.presentation.jsf;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
/**
* This filter populates user role constants into the request scope.
*/
public class UserRoleFilter
implements Filter
{
/**
* Initialize the filter
*
* @param config the configuration
*/
public void init(FilterConfig config)
{
}
/**
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
* javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
public void doFilter(
ServletRequest request,
ServletResponse response,
FilterChain chain)
throws IOException, ServletException
{
final HttpServletRequest httpRequest = (HttpServletRequest)request;
final boolean userIsUser = httpRequest.isUserInRole("USER")
|| httpRequest.isUserInRole("ADMIN")
;
httpRequest.setAttribute("userIsUser", Boolean.valueOf(userIsUser));
final boolean userIsAdmin = httpRequest.isUserInRole("ADMIN")
;
httpRequest.setAttribute("userIsAdmin", Boolean.valueOf(userIsAdmin));
chain.doFilter(
request,
response);
}
/**
* @see javax.servlet.Filter#destroy()
*/
public void destroy()
{
}
}