1 Reply Latest reply on Oct 19, 2008 3:48 PM by ssilvert

    ScriptException with FORM authentication and jQuery

    merlin-hst

      Hi,

      I've just tried the FORM authentication as described here :
      http://www.jboss.org/community/docs/DOC-10974

      But then I'm getting the following exception

      EcmaError: lineNumber=[93] column=[0] lineSource=[<no source>] name=[ReferenceError] sourceName=[script in http://localhost:8080/webportal/presentation/login.xhtml from (91, 55) to (104, 12)] message=[ReferenceError: "jQuery" is not defined. (script in http://localhost:8080/webportal/presentation/login.xhtml from (91, 55) to (104, 12)#93)]
      com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "jQuery" is not defined. (script in http://localhost:8080/webportal/presentation/login.xhtml from (91, 55) to (104, 12)#93)
       at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:528)
       at org.mozilla.javascript.Context.call(Context.java:499)
       at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:511)
       at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:405)
       at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:380)
       at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:889)
       at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:258)
       at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:311)
       at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:206)
       at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:498)
       at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
       at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:468)
       at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:210)
       at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:329)
       at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:971)
       at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:874)
       at org.cyberneko.html.HTMLScanner$SpecialScanner.scan(HTMLScanner.java:2906)
       at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:877)
       at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:495)
       at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:448)
       at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
       at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:636)
       at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:237)
       at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:127)
       at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:101)
       at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:440)
       at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:338)
       at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:388)
       at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:375)
       at org.jboss.jsfunit.framework.SimpleInitialRequestStrategy.doInitialRequest(SimpleInitialRequestStrategy.java:47)
       at org.jboss.jsfunit.framework.FormAuthenticationStrategy.doInitialRequest(FormAuthenticationStrategy.java:90)
       at org.jboss.jsfunit.framework.WebClientSpec.doInitialRequest(WebClientSpec.java:232)
       at org.jboss.jsfunit.jsfsession.JSFSession.<init>(JSFSession.java:80)
       at com.sunreader.web.BaseJSFTestNew.doFormLogin(BaseJSFTestNew.java:250)
       at com.sunreader.web.BaseJSFTestNew.doLoginAdmin(BaseJSFTestNew.java:241)
       at com.sunreader.web.PublicLinkJSFTest.testPublicLink(PublicLinkJSFTest.java:24)
      


      As you might see in the error message we're using the jQuery javascript library. If I do a login like this it works fine:
       assertEquals("/presentation/login.xhtml", getCurrentViewName());
       HtmlInputText login = (HtmlInputText)findComponent( "field_logon_username");
       HtmlInputSecret pwd = (HtmlInputSecret)findComponent( "field_logon_password");
       assertTrue(findComponent(login.getId()).isRendered());
       assertTrue(findComponent(pwd.getId()).isRendered());
      
       getClient().setValue(login.getId(), "xxx");
       getClient().setValue(pwd.getId(), "xxx");
       getClient().click("logon_logon");
       assertEquals("/presentation/plant_search.xhtml", getCurrentViewName());
      


      So for now I can live with it, but I would like to know why the FORM authentication doesn't work with jQuery.

      Thanks, Lothar

        • 1. Re: ScriptException with FORM authentication and jQuery
          ssilvert

          I'm not sure about the "jQuery is not defined" error. It looks like HtmlUnit is having trouble parsing the page. But it does correctly parse the same page when you request it the other way?

          I do think I see the reason that FormAuthenticationStrategy isn't working for you though. FormAuthenticationStrategy assumes you are using JEE container managed security. Part of that is the specification that your username and password fields must be named j_username and j_password. Of course you also need container managed security set up in your web.xml.

          I suggest that you create your own AuthenticationStrategy implementation for your customized login.

          Stan