cancel
Showing results for 
Search instead for 
Did you mean: 

Java-backed script failed with BadCredentialsException

marctsg
Champ in-the-making
Champ in-the-making
Hi all.  I'm working on a script which is meant to automatically update some fields on a specified user via a web script.  I have the script set to require admin authentication, and I am able to step through the script so I know I am passing the script based authentication.  The next step is to retrieve the person by name using
serviceRegistry.getPersonService().getPerson(userName);
  however, I fail with a BadCredentialsException every time.

Below is a stack trace, formatting from the web script error page:

net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider.authenticate(DaoAuthenticationProvider.java:290)
net.sf.acegisecurity.providers.ProviderManager.doAuthentication(ProviderManager.java:159)
net.sf.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:49)
net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:372)
net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:245)
org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
$Proxy46.getPerson(Unknown Source)
com.sample.person.UpdateUser.execute(UpdateUser.java:65)
org.alfresco.web.scripts.WebScriptRuntime.wrappedExecute(WebScriptRuntime.java:364)
org.alfresco.web.scripts.WebScriptRuntime$1.execute(WebScriptRuntime.java:330)
org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:241)
org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:171)
org.alfresco.web.scripts.WebScriptRuntime.transactionedExecute(WebScriptRuntime.java:341)
org.alfresco.web.scripts.WebScriptRuntime.authenticatedExecute(WebScriptRuntime.java:284)
org.alfresco.web.scripts.WebScriptRuntime.executeScript(WebScriptRuntime.java:150)
org.alfresco.web.scripts.WebScriptServlet.service(WebScriptServlet.java:109)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
java.lang.Thread.run(Thread.java:595)

I assumed that as an admin I have the privileges to access this service.  Why is the runtime rejecting my credentials?
3 REPLIES 3

marctsg
Champ in-the-making
Champ in-the-making
As an aside, if I knew the uuid of the user node, could I just use the node service to update any properties by instantiating a NodeRef for it?

marctsg
Champ in-the-making
Champ in-the-making
Tried just creating a noderef and using the NodeService to update it, same error. 

The strange thing is that this script is really a dual-purpose script which is supposed to allow creation and update of users.  The create portion works perfectly.

zomurn
Champ in-the-making
Champ in-the-making
This piece of code causes the bad credentials error too, why ??

private void traiter(String pRef) {
      NodeRef srcNode = new NodeRef(pRef);
      NodeRef destNode = mscSearchService
            .getStaticNodeRef(MscSearchService.FOLDER_TRAITER_NAME);
      try
      {
         fileFolderService.move(srcNode, destNode, null);
      } catch (Exception e)
      {
         throw new IllegalArgumentException(
               "Traiter action failed. Error moving file: " + pRef);
      }
      StoreRef lStoreRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE,
            "SpacesStore");
      // plus efficace :
      // +PATH:"/sys:system/sys:people/*"
      // +@cm\:userName:"fantoni"
      authenticationService.authenticate("admin", "admin".toCharArray());
      System.out.println("searchService: " + searchService);
      ResultSet lResultSet = searchService.query(lStoreRef,
            SearchService.LANGUAGE_LUCENE, "@cm\\:userName:\"ffournel\"");
      NodeRef person = lResultSet.getNodeRef(0);
      NodeRef homeFolder = (NodeRef) nodeService.getProperty(person,
            org.alfresco.model.ContentModel.PROP_HOMEFOLDER);
      lResultSet = searchService.query(lStoreRef,
            SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home\"");
      NodeRef companyHome = lResultSet.getNodeRef(0);
      Map<String, Object> map = scriptService.buildDefaultModel(person,
            companyHome, homeFolder, null, null, null);
      System.out.println("person: " + person);
      System.out.println("companyHome: " + companyHome);
      System.out.println("homeFolder: " + homeFolder);
      System.out.println("map: " + map);
      scriptService.executeScript(
            "classpath:alfresco/extension/scripts/msc-actions.js", map);
   }