4 Replies Latest reply on Nov 18, 2009 12:36 PM by Raj S

    Integrating JSFUnit with Spring Security

    Raj S Newbie

      We are having some issue with integrating JSFUnit with Spring Security. Appreciate any help regarding this:

      Details :
      We are trying to test the login page using JSFUnit, and it seems like till credentials validation it is working fine but the JSFContext is getting lost when redirected to another page after via the spring security after validation.

      JSFUnit Test Page :

      final WebClientSpec wcSpec = new WebClientSpec("/pages/Login.xhtml");
      final FormAuthenticationStrategy formAuth = new FormAuthenticationStrategy("test", "test", "login_button", "username", "password");

      final JSFSession jsfSession = new JSFSession(wcSpec);
      final JSFServerSession server = jsfSession.getJSFServerSession();

      The exception is thrown while trying to create JSFSession using the wcSpec

      Here is what we have in login validate method

      final ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();

      final RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())

      final ServletRequest req = (ServletRequest) context.getRequest();
      final ServletResponse res = (ServletResponse) context.getResponse();

      dispatcher.forward(req, res);


      The exception is thrown when dispatcher tries to forward

      Here is what is there in Spring Security which tries to forward based after successful Logon

      The exception is thrown right after successful logon and trying to load the Main Page. I do see the FacesContext is null. Hence we are getting this exception. Are we missing some config required by JSFUnit for Spring Security Please Help?