this servlet run but not exactly....

Discussion in 'Java' started by gbattine, Jul 23, 2006.

  1. gbattine

    gbattine Guest

    Hi guys,
    i'm a problem and i don't find a solution from 10 days....please help
    me.
    I have to give access security to my jsf application because each page
    shows private information. I have a login page and a visit bean that
    store the session's information,like current user and current locale.
    I've developed a filter that when a page is loaded try to retrieve user
    from Visit Object,if it's not found go to login page.
    What's my problem?
    After i developed my filter my application don't go well,because after
    i logged in my application try to open next page but it loads for
    infinite time....and while i try to load a page without log in i read
    the messagge "indirizzamento a Login.jsf...." but it loads for infinite
    time.
    It seems the filter acts but not exactly......
    Can you help me?
    I post you the important code.
    This is the important code of mu AuthenticationBean

    User newUser=new User(loginName,password,teamName,tipo);
    Visit visit = new Visit();
    visit.setUser(newUser);
    visit.setAuthenticationBean(this);
    setVisit(visit);
    FacesContext facesContext = getFacesContext();
    getApplication().createValueBinding("#{sessionScope.visit}").setValue(facesContext,
    visit);

    this is my Visit Object

    package giu;

    import javax.faces.context.FacesContext;
    import java.util.Locale;
    import javax.faces.model.SelectItem;
    import javax.faces.application.Application;
    import java.util.*;

    import java.io.Serializable;

    public class Visit implements Serializable
    {
    /**
    *
    */
    private static final long serialVersionUID = 1L;
    private User user;
    private AuthenticationBean authenticationBean;

    public Visit()
    {
    }

    public User getUser()
    {
    return user;
    }

    public void setUser(User user)
    {
    this.user = user;
    }



    public AuthenticationBean getAuthenticationBean()
    {
    return authenticationBean;
    }

    public void setAuthenticationBean(AuthenticationBean
    authenticationBean)
    {
    this.authenticationBean = authenticationBean;
    }

    and this is my filter

    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.jsf");
    httpResponse.sendRedirect(httpRequest.getContextPath() +
    "/faces/Login.jsf");
    }
    else
    {
    session.removeAttribute("originalTreeId");
    String role = visit.getUser().getRole();
    /*
    if ((role.equals("utente") && requestPath.indexOf("protected") >
    0))
    {
    String text = Utils.getDisplayString("ptrackResources",
    "PathNotFound",
    new Object[] { requestPath },
    request.getLocale());
    httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND,
    text);
    }
    else*/
    {
    chain.doFilter(request, response);
    }
    }
    Utils.log(servletContext, "Exiting the filter");
    }

    public void destroy()
    {
    }
    }


    with its declaration in web.xml

    <filter>
    <filter-name>AuthorizationFilter</filter-name>
    <filter-class>giu.AuthorizationFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>AuthorizationFilter</filter-name>
    <url-pattern>/faces/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>AuthorizationFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
    </filter-mapping>

    Please help me.....
    gbattine, Jul 23, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    0
    Views:
    3,679
    Guest
    Jan 18, 2004
  2. circuit_breaker
    Replies:
    2
    Views:
    1,984
    Jack Jia
    Apr 4, 2004
  3. Ollie
    Replies:
    0
    Views:
    360
    Ollie
    Oct 2, 2003
  4. Andrea9
    Replies:
    1
    Views:
    330
    Andrea9
    Oct 20, 2006
  5. Banibrata Dutta
    Replies:
    3
    Views:
    234
Loading...

Share This Page