cancel
Showing results for 
Search instead for 
Did you mean: 

'Bad credentials' error after a call to the lockSe

anweber
Champ in-the-making
Champ in-the-making
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
4 REPLIES 4

kevinr
Star Contributor
Star Contributor
You have found a small bug. A method is missing from the service security context definitions.

Find and edit the file "public-services-security-context.xml" and search for the section starting with this line:

<bean id="LockService_security" class="net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">

now add this line to the list in the <value> element:

org.alfresco.service.cmr.lock.LockService.getLocks=ACL_NODE.0.sys:base.Read

Restart the server and your tests should work.

I will commit this change ready for the next 1.3 build.

Thanks,

Kevin

anweber
Champ in-the-making
Champ in-the-making
Thanks Kevin.  It's very nice.  I will test it.  Please, could you also check if there is the same problem with the method "CheckOutCheckInService.getWorkingCopy()"

       Regards,

               Andre.

kevinr
Star Contributor
Star Contributor
Thanks Kevin.  It's very nice.  I will test it.  Please, could you also check if there is the same problem with the method "CheckOutCheckInService.getWorkingCopy()"

No problem. I've checked getWorkingCopy() and it looks to be configured ok. What method did you call before it? As this exception case is quite confusing as it is thrown from the method call _after_ this config issue occurs.

Thanks,

Kevin

anweber
Champ in-the-making
Champ in-the-making
Hi Kevin,

   After I have done the modifications in the file "public-services-security-context.xml", the problem is solved with the lockService.

   But I still have the same kind of problem with "CheckOutCheckInService.getWorkingCopy()".  This problem is explained in this post : http://forums.alfresco.com/viewtopic.php?t=1448#6403 .

   Many thanks for your help,

                Andre