Wednesday, June 02, 2010

Alfresco - method createAuthentication is undefined

I am using Alfresco-Community-3.3 and am trying out the following example code from Jeff Potts book: Alfresco Developer Guide

// client-extensions/src/java/com/someco/module/BootstrapAuthorityCreator.java
// create tuser1, tuser2, tuser3, tuser4
if(!authenticationService.authenticationExists("tuser1")) {
  authenticationService.createAuthentication("tuser1", "password".toCharArray());
  if (logger.isDebugEnabled()) logger.debug("Created tuser1 auth");
}

But I get this error:

The method createAuthentication(String, char[]) is undefined for the type AuthenticationService

And indeed when I look at the javadocs for org.alfresco.service.cmr.security.AuthenticationService there is no createAuthentication() method. It seems to have been moved into org.alfresco.service.cmr.security.MutableAuthenticationService. So, I changed authenticationService into an instance of MutableAuthenticationService:

// private AuthenticationService authenticationService;
private MutableAuthenticationService authenticationService;

You also need to modify the signature of setAuthenticationService().

I posted this on the Alfresco Forums too.