AnsweredAssumed Answered

'Bad credentials' error after a call to the lockSe

Question asked by anweber on May 24, 2006
Latest reply on May 29, 2006 by anweber

   I try a little test with a sandalone java application. I obtain an exception of type "Bad credentials" after having called some API services.  It occurs just after a first call to the lockService.  Some times ago, I already met the same situation after a call to checkOutCheckInService.getWorkingCopy(), see post

There is my code :

package ec.ep.dit.isp.sp.alfrescoeval;
import java.util.List;

import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.transaction.TransactionService;
import javax.transaction.UserTransaction;
import javax.transaction.Status;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockStatus;
import org.alfresco.service.cmr.lock.LockType;

public class TestGetLocks {
    public static void main(String[] args) throws Exception
        // initialise app content
        ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
        // get registry of services
        final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
        TransactionService transactionService = serviceRegistry.getTransactionService();
        UserTransaction trx = transactionService.getUserTransaction();

        // authenticate
        AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
        authenticationService.authenticate("admin", "admin".toCharArray());

        catch(Exception exc){
            if (trx.getStatus() == Status.STATUS_ACTIVE)
              catch(Throwable ee)

     * We list the files locked by admin
      * Prerequisites :
      *   With the webClient, logon as admin and checkout some files
     * Expected results :
     *    You should obtain information about files locked by admin
      * @param serviceRegistry
     * @throws Exception
    public static void testGetLocks(ServiceRegistry serviceRegistry) throws Exception
      LockService lockService = serviceRegistry.getLockService();
        NodeService nodeService = serviceRegistry.getNodeService();
        // get the store
        StoreRef storeRef = new StoreRef(
        if (!nodeService.exists(storeRef))
       List<NodeRef> nodes = lockService.getLocks(storeRef);  // Give locks for current user
        System.out.println("You have " + nodes.size() + " locked nodes");
        String nodeTitle;
      LockType lockType;
      LockStatus lockStatus;
        for(NodeRef nodeRef : nodes){
            if (nodeRef!=null){
               nodeTitle = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
               lockType = lockService.getLockType(nodeRef);
               lockStatus = lockService.getLockStatus(nodeRef);
               System.out.println("the node titled \"" + nodeTitle + "\" is locked, the type if this lock is " + lockType + ", it's status is "+ lockStatus);

I obtain the following output :

10:31:00,834 INFO  [service.descriptor.DescriptorService] Alfresco started (Community Network): Current version 1.2.0 schema 6 - Installed version 1.2.0 schema 6
You have 2 locked nodes
net.sf.acegisecurity.BadCredentialsException: Bad credentials presented
   at net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider.authenticate(
   at net.sf.acegisecurity.providers.ProviderManager.doAuthentication(
   at net.sf.acegisecurity.AbstractAuthenticationManager.authenticate(
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(
   at $Proxy15.getProperty(Unknown Source)
   at ec.ep.dit.isp.sp.alfrescoeval.TestGetLocks.testGetLocks(
   at ec.ep.dit.isp.sp.alfrescoeval.TestGetLocks.main(

   We see that the exception occurs in the first call to the API just after the call of "lockService.getLocks(storeRef);".  I have tried to insert others calls to the API before and after the call to "lockService.getLocks" : all calls before succeed, all calls after fail.

  What is wrong?

   Thanks for your help,