0

hello i am using prettyfaces jsf2.0 i ve created a filter which is checking every request whether user is logged in or not

@WebFilter(urlPatterns= {"*.xhtml"} , dispatcherTypes = {DispatcherType.REQUEST})
public class Authentication implements Filter {

@Override
public void init(FilterConfig config) throws ServletException {
System.out.println("[Authentication Filter] : init Method");
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws         IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession(false);
PrettyContext context = PrettyContext.getCurrentInstance(request);      
if (!(context.getCurrentMapping().getId().equals("login")) && (session == null ||     session.getAttribute("username") == null)) {
{
response.sendRedirect(request.getContextPath()+"/login");
}
else {
chain.doFilter(req, res); // Logged-in user found, so just continue request.
}
@Override
public void destroy() {}
}

when i started tomcat server it load login.xhtml page URL is showing in address bar //localhost:8080/MyApp/login in login.xhtml i ve form with user name and password fields

when i submit form using

<p:commandButton ajax="false" value="Login" action="pretty:loggedin" />

and when i get values in action class, the values are null there and when i print system.out.println loggin in filter it looks like two URL are requesting 1. /login 2. /loggedin thats y values are getting null there. any solution please thanks in advance.

Mohsin AR
  • 2,998
  • 2
  • 24
  • 36

1 Answers1

1

It doesn't look correct what you are doing. You are using pretty:loggedin as an action attribute in your login command button. This won't execute any action method but instead redirect to some other mapping without any chance to process the values the user entered.

You should instead reference an method in your action attribute which you use process the login attempt. If it was successful, the this method should return pretty:loggedin which will redirect the user to the new page.

I hope this helps a bit. If you have more problems, you should post on the PrettyFaces forums. That's a better place to help you if solving the problem takes multiple question/response cycles. :)

http://ocpsoft.org/support/

chkal
  • 5,598
  • 21
  • 26
  • when server load it loads login.xhtml page – Mohsin AR Apr 26 '13 at 06:26
  • when server loads login.xhtml successfully the url of that page is //localhost:8080/MyApp/login but when i submit form to @URLAction(mappingId="loggedin") loggedInAction(){} using values are null in action method – Mohsin AR Apr 26 '13 at 06:32
  • you are saying that suppose i ve class name MyClass having method myAction() so i ve to use instead of this ?? – Mohsin AR Apr 26 '13 at 06:37
  • Exactly. You will have to process the user login somehow, right? And you typically do this in an action method. Where else would you process it? – chkal Apr 26 '13 at 07:25