I need referrer URI in Grails 2.x - grails

I'm using Grails 2.4.4 and trying to get the browser url which loaded my grails app (referrer url) in my controller. I have searched SO and google already, looked in documentation but it seems like i'm searching for a mythical creature.
// inside my before interception
String referer = request.getHeader("Referer");
println "referer= "+referer // null
Anyone done this?

Related

redirect user from php url to grails page

I am using grails 2.X.
when user hits on http://www.abcdef.com/redir/abc.php?id=123, i want to redirect user to some other url mappings like http://www.abcdef.com/abcd.
I already used grails filter but can't get appropriate solution.
Can anyone tell me how to do so using grails?
Do we need Filters or some scripts to achieve this.
Thanks in advance.
This can be achieved in UrlMappings.groovy. This configuration should suit your needs:
"/$controller.$suffix" {
constraints {
suffix(matches: 'php')
}
}

grails cache headers plugin for controllers

This question is not an implementation specific question of the grails plugin, but more of a question illustrated using grails.
Grails a plugin for writing cache related headers (http://grails.org/plugin/cache-headers) and they show an example that looks like
class ContentController
def show = {
cache shared:true, validFor: 3600 // 1hr on content
render(....)
}
}
Since the grails request to get here would look something like http://myapp/content/show, would a browser even try to cache this since it's not a specific resource with a filename (e.g. it's not show.gsp, even though that is what is being used to generate the html)?
What's the purpose of specifying a cache time on dynamic content that won't be cached by the browser (assuming I'm understanding how the browser will cache it based on my statement above)? When might this be useful? Might this be useful in an ajax environment where the user is not typing the full url but rather we're dynamically updating part of a page?
Browser caches URL, not a filename (because HTTP is not a filesystem). I thinks it's the answer for both questions, right?
See:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13
http://www.mnot.net/cache_docs/
https://developers.google.com/speed/docs/best-practices/caching

Retrieving HTTP parameters in Grails

the request was sent from an HTML form, the request body contains the form data,how can i retrieve that data in my Grails application.Below is the URL from where i need to retrieve data.I'm a Rookie in Grails so please help me with this.
hxxp//localhost:8080/copypolicyNumber/loginaction.jsp?fname=Roger&lname=wallace&city=Des+Moines&pnum=123456&submit=Submit
As you just started with Grails, I suggest you look at the screencasts available in the Grails website, and also check the free e-book Getting Started with Grails (need registration).
Grails works with the params map for both GET and POST requests. Also, it uses an special url mapping that you need to be aware of.
So, assuming that you have a login controller with the action login and considering that you called the url: myapp/login/login?fname=Roger&lname=wallace&city=Des+Moines&pnum=123456
class LoginController {
def login() {
println params.fname //Roger
println params.lname //wallace
println params.city //Des Moines
println params.pnum //123456
}
}

Determine the url (or controller and action names) of a request which is unauthorized with Shiro Grails plugin

I would like to be able to log the requests that my app receives that are unauthorized. Because the Shiro plugin uses an HTTP redirect to send the user to auth/unauthorized the request object is a fresh one and I can't get the original URL; controller/action name; or request parameters from it.
Is there a way to determine either the original url, or the controller and action names (and request params if possible) inside the AuthController unauthorized action?
I am looking at http://plugins.grails.org/grails-shiro/tags/RELEASE_1_1_3/ShiroGrailsPlugin.groovy as a reference of the plugin source.
Details:
Grails 1.3.7
Shiro Grails plugin 1.1.3
I had the same problem... my solution is not perfect:
a browser sends the so called referer in one of the headers which you can get through
request?.getHeader('Referer')
But the referer is nothing you really can rely on -- but most of the browsers send it.
Another solution could be the filter: try to write the current url to another variable before you call accessControl() in ShiroSecurityFilters.groovy. You can get the current URL through request.forwardURI.
Update: just verified my last assumption - this seems the cleanest solution to me:
In ShiroSecurityFilters.groovy, replace
// Access control by convention.
accessControl()
with
// Access control by convention.
if (!accessControl()) {
session.deniedUrl = request.forwardURI
return false
}
which enables you to access the url as session.deniedUrl in your auth/unauthorized controller.

Grails set language (internationalization) via URL mappin

I'm interested in supporting English and French in my Grails app with user-friendly URL.
format: /appname/language/controller/action
example: /store/en/product/list
What is the best way without passing as a parameter (?lang=fr) then rewriting the URL.
Thanks
Adding the following mapping in your appname\grails-app\conf\UrlMappings.groovy should do it.
"/$lang/$controller/$action?/$id?"{
}
See the URL mapping article on the grails website for details.

Resources