Sunday, December 12, 2010

Testing Groovy/Grails with Jargon

I'm having a great time looking at Groovy and Grails as a rapid development environment for iRODS web interfaces via the new Jargon API I am developing.

Jargon is a pure Java API that encapsulates the iRODS server protocol. I am developing a new version, and one of the goals is to make it more usable in Spring-based apps. I have web projects to develop, and at the same time, I need to kick the tires on how Jargon works with dynamic scripting languages. So far, so good. I'm able to wire together some simple things, and utilize the Jargon libraries quite smoothly. Here's a little bit of wiring together of IRODSFileSystem using Spring DSL:

beans = {

irodsFileSystem( {
bean ->
bean.factoryMethod = "instance"
bean.singleton = true

irodsFileServiceWrapperService(mydrop.IrodsFileServiceWrapperService) {
irodsFileSystem = ref("irodsFileSystem")

irodsAuthenticationHelperService(mydrop.IRODSAuthenticationHelperService) {
irodsFileServiceWrapperService = ref("irodsFileServiceWrapperService")


Here's a bit of my hacked auth code (I need to see how to more formally wire in Spring Security with Grails:

IrodsFileServiceWrapperService irodsFileServiceWrapperService

* Validate the user by logging into iRODS under the given credentials. Also retrieve the iRODS user groups for
* use in role-based access
* @param host
* @param port
* @param zone
* @param userName
* @param password
* @param resource
* @return
def authenticate(String host, int port, String zone, String userName, String password, String resource) throws AuthenticationException {
def irodsAccount = IRODSAccount.instance(host, port, userName, password, resource, zone, "")
def irodsFileSystem = irodsFileServiceWrapperService.getIrodsFileSystem()
def irodsAccountAuthenticationManager = new IRODSAccountAuthenticationManager()
irodsAccountAuthenticationManager.setIrodsAccessObjectFactory irodsFileSystem.getIRODSAccessObjectFactory()
def irodsAuthentication = new IRODSAuthenticationToken(irodsAccount)
def irodsAuthenticationToken = irodsAccountAuthenticationManager.authenticate(irodsAuthentication)

I'm certain that this is not the most beautiful Grails code, but it's promising nevertheless.

No comments: