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
Hello,

   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 http://forums.alfresco.com/viewtopic.php?t=1448

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.cmr.security.AuthenticationService;
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());

        try{
        trx.begin();   
       testGetLocks(serviceRegistry);
       trx.commit();
        }
        catch(Exception exc){
           exc.printStackTrace();
           
            if (trx.getStatus() == Status.STATUS_ACTIVE)
            {
              try
              {
                 trx.rollback();
              }
              catch(Throwable ee)
              {
                ee.printStackTrace();
              }
            }
           
        }
    }

    /**
     * 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(
                StoreRef.PROTOCOL_WORKSPACE,
                "SpacesStore"
                );
        if (!nodeService.exists(storeRef))
        {
            return;
        }
       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(DaoAuthenticationProvider.java:290)
   at net.sf.acegisecurity.providers.ProviderManager.doAuthentication(ProviderManager.java:159)
   at net.sf.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:49)
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:372)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:37)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
   at $Proxy15.getProperty(Unknown Source)
   at ec.ep.dit.isp.sp.alfrescoeval.TestGetLocks.testGetLocks(TestGetLocks.java:89)
   at ec.ep.dit.isp.sp.alfrescoeval.TestGetLocks.main(TestGetLocks.java:36)


   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,

             Andre

Outcomes