Posts

Showing posts with the label groovy

Trying out Java/Scala/Groovy artefacts on the fly

There are times when you need to try out a simple snippet using a Java/Scala/Groovy artefact published on Maven central or the corporate repository. Groovy (with all its goodness ) can help you just do that without requiring you to create a dummy Maven, Gradle or SBT project. The key piece is Grape which is a " JAR dependency manager embedded into Groovy. " For example let's say you need to quickly test something with Eclipse JGit . Assuming you have already installed Groovy (eg via sdkman .), drop into the terminal and type groovysh to enter, well, the Groovy shell . // Import the Grape API we need - it's just a static method groovy:000> import static groovy.grape.Grape.grab ===> static groovy.grape.Grape.grab // Ask Grape to download the specified artefact and all its dependencies. // You may find the details for your artefact in https://mvnrepository.com groovy:000> grab(group: 'org.eclipse.jgit', module: 'org.eclipse.jgit', vers...

Grab Packt With Groovy

Automatically claim Packt's free e-books with a Groovy program. Introduction Packt Publishing has launched a new programme called " free learning offer "; each day they put an e-book for free on their website to download: one only needs to login to Packt's website and click on the "claim your free book" link. Following Grab Packt with Racket, here is the Groovy version, to automatically add the e-book to your Packt account for later downloads. The Code The code is in public domain. You can get it directly from is.gd/isbviw or from my github gist . For this to work you need to replace YOUR-EMAIL-ADDRESS (line 26) and YOUR-PASSWORD (line 27) with reasonable values. If you wish to run this from shell/cron remember to add #! /usr/bin/env groovy to the top of the file. The script is completely self-contained as @Grab annotation on line 4 fetches the dependencies it requires. /** * @author Bahman Movaqar */ @Grab('org.jsoup:jsoup:1.8.2') i...

Grails: How To Secure Your Application Using Spring Security Core

Image
A step by step tutorial on how to use Spring Security Core to secure your Grails application. Introduction Any web-based application must have a mechanism for authenticating users and authorising them to do their defined activities in the system. One can go for the traditional approach of doing it with a login form; it works for the start. But on today's Internet, a classic pair of username and password is not always available as many people prefer to use a single OpenID, Twitter or Facebook account to access their data across different web sites. Also in corporate environments usually authentication and authorisation is done against an LDAP database. This is where Spring Security collection comes to play by allowing you to connect to a wide range of data sources and acquire access information from them instead of strong them yourself. At the heart of Spring Security lies Spring Security Core and as usual there's a Grails plugin for that! Let's see how we can use it. ...