marko
marko

Reputation: 3776

Accepting calls from certain URL in Grails

I have a situation that requires me to call a certain controller when a specific request is sent from a certain URL.

Let's say my application is running on: http://www.app.com/listencontroller

When a request is sent to this URL, and the request is sent from http://www.itsme.com, I want to be able to process that request, otherwise I don't want to do anything with it.

How can this be done in a pretty way, i.e. no hard coded URLs in my controller?

Upvotes: 3

Views: 111

Answers (2)

Lauri Piispanen
Lauri Piispanen

Reputation: 2097

Do you mean that the browser must come from the domain itsme.com, or the request must come through a link that's present on a page that resides in itsme.com?

The first would require you to do a reverse dns lookup on request.remoteAddr.

The latter entails looking at the Referer header of the incoming request. This is not bulletproof, as it can be easily spoofed. Also, in some cases it will not be sent at all, so your mileage may vary.

In either case, either a Grails filter or a controller interceptor would probably be the most elegant solution.

Upvotes: 1

Related Questions