This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The trick is to open the login page before actually trying to post the login data. I assume something is stored in the cookie, but I only know this is how it works. See also my question on stackoverflow:
http://stackoverflow.com/questions/20355874/how-to-use-rcurl-to-authenticate-to-spring-security-grails-app/20370222#20370222
I'm a big fan of the spring-security plug-in series for grails. It allows me to do almost anything concerning security issues while giving me faith that this works properly. One scenario I encountered now, however, was not covered. In order to secure mit JSON web-service actions I couldn't rely on spring security. Instead I wanted to create unique links just like in google's picasa, when you wanted to share an image with a 3rd party that does not necessarily have a picasa account like you do. I decided to implement this in a very simple fashion:
I added a field String uuid to the domain class in question. Then I added a service class:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Then all I needed to do is to modify controller actions like this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
With grails projections one should keep in mind that when one of the associated values turns out to be null, the entire entry is ignored in the result list. I found numerous posts, where this problem is addressed by alternating the join mode from inner join to left outer join:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In one of my grails apps, I export a large quantity of data in JSON format. This process was incredibly slow (~30s) and somehow I was convinced that this was a database issue since numerous joins were involved as well. As it turns out, however, the database query took ~1s to complete so that I got curious what the other 29s were spent on. Very unexpectedly, I had to blame grails' native JSON converter. A google search revealed that this was already known:
I decided to follow the suggested solution and started playing around with Jackson. Pitfalls are that some Java objects seem to cause Jackson some trouble, e.g. if objects can't be serialized. I therefore decided to use projections to efficiently recover all the database fields I was interested in (probably speeding up the database access as well). Since all the fields were then strings, ints or doubles, conversion worked like a charm. The exact same conversion now takes only ~1s, adding up to ~2s in total.
However, I didn't try it out since development does not appear to be active.
One last important thing to note is that if you want to use jackson to render JSON content you might get into conflict with the regular JSON converter if you try to do something along the lines of
render AS JSON.
What you need to do instead is:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters