Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add filter #55

Open
aelmottaki opened this issue Aug 20, 2016 · 3 comments
Open

how to add filter #55

aelmottaki opened this issue Aug 20, 2016 · 3 comments
Labels

Comments

@aelmottaki
Copy link

i want to add a login filter to my app
so i registred the filter like that
@bean
public FilterRegistrationBean loginFilter(){
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new LoginFilter());
registration.addUrlPatterns("/src//*");
return registration;
}
but it seems not working i don't know why !!

@persapiens
Copy link
Member

hi @aelmottaki ,

The urlPatterns "/src/*" is correct?
Could you provide full example?

@aelmottaki
Copy link
Author

hi @persapiens ,
thas LoginFilter
public class LoginFilter implements Filter {
@Autowired
UserSessionBean userSessionBean;

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        if(userSessionBean!=null && userSessionBean.getLoggedIn()==true){
            String contextPath = ((HttpServletRequest)request).getContextPath();
            ((HttpServletResponse)response).sendRedirect(contextPath+"/sc/dashboard.jsf");
        }else{
            request.getRequestDispatcher("/sc/loginPage.jsf").forward(request, response);
        }
        chain.doFilter(request, response);
}

private boolean isSessionValid(HttpServletRequest httpServletRequest) {
    return httpServletRequest.getRequestedSessionId() != null;
}

@Override
public void init(FilterConfig config) throws ServletException {
}

@Override
public void destroy() {
}

}

and i registered the filter like that

@configurable
public class AppConfig {
@bean
public FilterRegistrationBean loginFilter(){
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new LoginFilter());
registration.addUrlPatterns("/sc/*");
return registration;
}

}

i have two jsf pages Dashboard.xhtml and loginPage.xhtml in sc directory

@persapiens
Copy link
Member

Hi @aelmottaki , I could see LoginFilter working if include AppConfig at org.joinfaces.example package and LoginFilter at org.joinfaces.example.view package.

I don't have access to UserSessionBean class.

Note that joinfaces-example uses spring-security.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants