Issue Details (XML | Word | Printable)

Key: GRAILSPLUGINS-476
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Peter Ledbrook
Reporter: Ruslan Roz
Votes: 1
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
Grails Plugins

<g:javascript> tag is working wrong in pair with security plugin

Created: 18/Dec/07 12:33 PM   Updated: 03/Sep/08 02:20 PM
Component/s: None
Affects Version/s: None
Fix Version/s: Grails-JSecurity 0.3

Time Tracking:
Not Specified

File Attachments: 1. Text File jsecurity.patch (2 kB)



 Description  « Hide
I have been using the Canoo WebTest plugin for functional testing of Grails application.
When I run following test method:

def testLoginLogOutListNewDelete() {
webtest('teLoginLogOut basic operations: view list, create new entry, view, edit, dele, view') { invoke(url: "http://localhost:8080/LIFT/auth/login") }
}

I get the following errors:

[java] INFO (com.canoo.webtest.steps.request.TargetHelper) - getting response for url: http://localhost:8080/LIFT/auth/login
2007-12-18 15:07:41.192:/LIFT:INFO: GSP servlet initialized
2007-12-18 15:07:44.926:/LIFT:INFO: Initializing Spring FrameworkServlet 'grails-errorhandler'
[java] ERROR (com.gargoylesoftware.htmlunit.html.HtmlPage) - Error loading javascript from [http://localhost:8080/LIFT/plugins/jsecurity-0.1.1/j
/application.js] status=[404 Not Found]
[java] ERROR (com.gargoylesoftware.htmlunit.html.HtmlPage) - Error loading javascript from [http://localhost:8080/LIFT/plugins/jsecurity-0.1.1/j
/application.js]:
[java] com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 404 Not Found for http://localhost:8080/LIFT/plugins/jsecurity-0.1.1/js/app
ication.js
[java] at com.gargoylesoftware.htmlunit.html.HtmlPage.loadJavaScriptFromUrl(HtmlPage.java:845)
[java] at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:775)
[java] at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:229)

The tag below

<g:javascript library="application"/>

are resolving as

<script type="text/javascript" src="/lift//plugins/jsecurity-0.1.1/js/application.js"></script>

but actually, the path to JS file should be like that

<script type="text/javascript" src="/lift/js/application.js"></script>

So, just for test I've copied JS files from the original location to the web-apps/plugins/jsecurity-0.1.1/ location (where Grails/Canoo is looking for them)

and after that the test was successful.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Peter Ledbrook added a comment - 30/Dec/07 06:21 PM
This is actually a tricky problem: the view is in the plugin, but the layout is in the application. So, somehow the plugin context path must be cleared once rendering reaches the layout - easier said than done I think.

In the meantime, I would simply copy login.gsp from the plugin to your grails-app/views/auth directory. This also enables you to customise the look of it.


Peter Ledbrook added a comment - 30/Dec/07 06:22 PM
Since it is fairly easy to work around this problem, I'm dropping it down to minor.

Peter Ledbrook added a comment - 14/May/08 12:34 PM
Various changes to the plugin have made this issue redundant, I believe. Re-open if it's still a problem for you.

Rogério Carrasqueira added a comment - 25/May/08 12:50 PM
Hi,

I had this same problem, I just installed the plugin jsecurity, now on version 0.2 at grails 1.0.2 and the problem appeared again. I made a controller with an create action to add users to my website and when the page was load, the page try to look for the js libraries inside the jsecurity folders, as describe bellow:

<script type="text/javascript" src="/multilinguas//plugins/jsecurity-0.2/js/jquery-1.2.3.cust.js"></script>
<script type="text/javascript" src="/multilinguas//plugins/jsecurity-0.2/js/application.js"></script>

and at my create.gsp I defined on this way:

<g:javascript library="jquery-1.2.3.cust" />
<g:javascript library="application" />

Unfortunately, to avoid this I defined base_href equals to the name of my aplication and I had to call directly the js using the tag <script></script>. The other pages that the controller does not use the Jsecurity, loads normally, without any problems to find the js library.

So I think that a part of this bug remains!

Thanks

Rogério Carraqueira


Lee Butts added a comment - 15/Jun/08 05:57 PM - edited
I've also just come across this issue with a fres 1.0.3 app and the lastest jsecuroity pluhin - installed the plugin, ran grails quick-start (which created grails-app/views/auth/login.gsp) and my webtests are failing (after clicking sign in on the login page) due to invalid JS library links on the pages using the main layout.

cheers

Lee


David Doty added a comment - 21/Jul/08 09:09 PM
I'm sorry, I am confused by this issue. I too encountered a similar error when using Canoo Webtest and Jsecurity. What is the "fairly easy" workaround to which Peter Ledbrook alludes?

In my grails-app/views/layout/main.gsp file, I replaced the line

<g:javascript library="application"/>

with

<script type="text/javascript" src="/codegrader/js/application.js"></script>

since the latter is how the former is dynamically rendered at run time (unless the bug under discussion incorrectly renders it as mentioned in the previous comments). However, I don't entirely understand the former line (it was placed in main.gsp by default by Grails), and I am afraid that some future change in Grails (for instance, moving the location application.js) will break this.

So what is the correct workaround for this bug?

Thank you in advance,
Dave


Craig Blake added a comment - 19/Aug/08 05:44 AM
I am also seeing this problem with the JSecurity plugin. Once a user authenticates, all <g:javascript.../> tags on every application page render with a bogus path, such as:

<script type="text/javascript" src="/plugins/jsecurity-0.2.1/js/prototype/prototype.js"></script>

As soon as the user signs out, all paths are rendered correctly. Unless I am doing something wrong, this is a critical bug.

I am using Grails 1.0.3 and JSecurity Plugin 0.2.1 with the login page in the application view directory.


Peter Ledbrook added a comment - 19/Aug/08 08:28 AM
<g:javascript library="application"/> is incorrect in my opinion. It should be:
<g:javascript src="application.js"/>

The workaround I mentioned is to copy the login.gsp file from the plugin to the application view folders. So, I suspect that this report is not for the bug that you are seeing. In fact, I suspect it's a bug in Grails instead. Please try the "src" version of the <g:javascript/> tag - if that still doesn't work, I think it may be a Grails bug.


Craig Blake added a comment - 27/Aug/08 07:22 PM
Here is the problem. In the Grails "JavascriptTagLib.groovy" file, the src path is appended with the value of "pluginContextPath" if it exists:
def requestPluginContext = request[CONTROLLER]?.pluginContextPath
		out << '<script type="text/javascript" src="'
		if (!attrs.base) {
            def baseUri = grailsAttributes.getApplicationUri(request)
            out << baseUri
            out << (baseUri.endsWith('/') ? '' : '/')
			if (requestPluginContext) {
			  out << (requestPluginContext.startsWith("/") ? requestPluginContext.substring(1) : requestPluginContext)
			  out << "/"
			} 
			out << 'js/'
		} else {
			out << attrs.base
		}
		out << attrs.src
 		out.println '"></script>'

I've verified that after authentication, the value of "request[CONTROLLER]?.pluginContextPath" within a tag lib is "/plugins/jsecurity-0.2.1".

I don't know if this is a JSecurity Plugin or Grails bug, but it is not the expected behavior that every invocation of the javascript tag have that path appended, right?


Craig Blake added a comment - 27/Aug/08 09:29 PM
Aha. This issue only affects applications which have controllers that are listed in the JSecurity plugin.xml file under resources. For some reason, that file contains an entry for BookController, ItemController, TestController, AdminController, and a bunch of other stuff (and lots of repetitions - is it automatically generated?)

The logic in DefaultPluginMetaManager matches any resource declared in the plugin and modifies the "pluginContextPath" if the plugin has an entry. So, for people using the sample application (BookController) or others using controller names listed (in my case, TestController) the JSecurity plugin path gets added to resource paths.

Fix is to remove the extraneous entries from the JSecurity plugin resources list.


Craig Blake added a comment - 27/Aug/08 09:34 PM
Patch to be applied to an existing JSecurity plugin installation to remove controllers from the plugin.xml resources.

Peter Ledbrook added a comment - 03/Sep/08 02:20 PM
The resources in plugin.xml come from the test projects in the plugin directory. I have to manually move the "test/projects" directory out of the plugin before packaging it. Hopefully the "PackagePlugin" script will not include them in plugin.xml in future.