cancel
Showing results for 
Search instead for 
Did you mean: 

[solved] AuthenticationUtil.runAs: how to get ride of this ?

zomurn
Champ in-the-making
Champ in-the-making
Hi,

I'am currently coding an evaluator.
When I'am logged as admin, when I navigate in a specific folder, an action evaluator is executed.
Inside, an instruction causes "Bad credentials presented" whereas I'am logged into admin…why ?
This problem occurs on the instruction nodeService.getProperty(something);
The problem is solved with the instruction AuthenticationUtil.runAs(something, "admin");

But how to get "ride of" this "runas" instruction? because, I'am afraid to "pollute" my code always with this….
In other words, I'am pretty sure that the problem comes from a bad xml file configuration dealing with permission on services (acegi security?)
Could you help me to go in depth on this problem ?

Regards !
3 REPLIES 3

zomurn
Champ in-the-making
Champ in-the-making
I found the answer here : http://forums.alfresco.com/en/viewtopic.php?f=11&t=1046

And the solution is :

Create a spring bean like follows :

<bean id="MscAbstractEvaluator"
      class="org.alfresco.module.msc.action.evaluator.MscAbstractEvaluator"
      abstract="true">
      <property name="nodeService">
         <ref bean="nodeService" />
      </property>
      <property name="authorityService">
         <ref bean="AuthorityService" />
      </property>
      <property name="authenticationService">
         <ref bean="AuthenticationService" />
      </property>
      <property name="transactionService">
          <ref bean="transactionService"/>
       </property>
   </bean>

AND NOT like follows :

<bean id="MscAbstractEvaluator"
      class="org.alfresco.module.msc.action.evaluator.MscAbstractEvaluator"
      abstract="true">
      <property name="nodeService">
         <ref bean="NodeService" />
      </property>
      <property name="authorityService">
         <ref bean="AuthorityService" />
      </property>
      <property name="authenticationService">
         <ref bean="AuthenticationService" />
      </property>
   </bean>

NOTICE : NodeService is a heavy proxied object contains the security interceptor (and more). I need to get ride of this interceptor so I need to explode the NodeService (in public-service-context.xml).
The basis of NodeService is nodeService (in node-service-context.xml). nodeService is the real alfresco business code.
So I reference a "nodeService" bean and not a "NodeService" bean.
The problem now, is that I need the nodeService in transaction inside my action executer impl. So I have to add the transaction service (the unproxied one !) and then execute the use of nodeService inside this transaction.
The java resulting code is :

private boolean evaluateGeneric(final Node pNode) throws Exception {

      RetryingTransactionHelper txnHelper = transactionService
            .getRetryingTransactionHelper();
      RetryingTransactionCallback<String> callback = new RetryingTransactionCallback<String>() {

         public String execute() throws Throwable {

            // on récupère l'état en cours
            return (String) nodeService.getProperty( pNode.getNodeRef(),
                  MscPropertyEnum.PROPERTY_ETAT.getPropertyName() );
         }
      };
      try
      {
         String lEtat = txnHelper.doInTransaction( callback, false, true );

         if (log.isDebugEnabled())
         {
            log.debug( "lEtat" + lEtat );
         }
         MscStateEnum lEtatEnum = MscStateEnum.valueOf( lEtat );

         if (log.isDebugEnabled())
         {
            log.debug( "Current state: " + lEtatEnum );
         }

         // on récupère les actions autorisées associées
         List<MscActionEnum> lActionList = lEtatEnum.getActionList();

         if (log.isDebugEnabled())
         {
            log.debug( "Available actions: " + lActionList );
         }

         return lActionList.contains( getAction() );
      }
      catch (Exception e)
      {
         if (log.isDebugEnabled())
         {
            log.debug( e );
         }
      }

      return false;

   }

Regards,

zomurn
Champ in-the-making
Champ in-the-making
U have changed the bean but how do you integrate it with Alfresco working module.
Is that possible to customize the code and add it to the working module?

You have to include the spring bean in the module-context.xml
And package your AMP module like explained in the wiki.
When you code the module, you can customize alfresco all in it , then generate the .jar and integrate it in the war file.
Have a look to Alfresco SDK multiple examples (Basic AMP for example)

dillibabubottu
Champ in-the-making
Champ in-the-making
I am not able to login to alfresco here i am sending my log file please help me on this
at java.lang.Thread.run(Thread.java:722)
Caused by: net.sf.acegisecurity.providers.ProviderNotFoundException: No authentication provider for net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken
   at net.sf.acegisecurity.providers.ProviderManager.doAuthentication(ProviderManager.java:169)
   at net.sf.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:49)
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:376)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:159)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.transaction.RetryingTransactionInterceptor$1.execute(RetryingTransactionInterceptor.java:69)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:433)
   at org.alfresco.repo.transaction.RetryingTransactionInterceptor.invoke(RetryingTransactionInterceptor.java:59)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy7.getRootNode(Unknown Source)
   at org.alfresco.repo.importer.ImporterComponent.getNodeRef(ImporterComponent.java:300)
   at org.alfresco.repo.importer.ImporterComponent.importView(ImporterComponent.java:268)
   at org.alfresco.repo.importer.ImporterBootstrap.doImport(ImporterBootstrap.java:475)
   at org.alfresco.repo.importer.ImporterBootstrap.access$000(ImporterBootstrap.java:70)
   at org.alfresco.repo.importer.ImporterBootstrap$1$1.execute(ImporterBootstrap.java:350)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:433)
   at org.alfresco.repo.importer.ImporterBootstrap$1.doWork(ImporterBootstrap.java:354)
   at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:529)
   at org.alfresco.repo.importer.ImporterBootstrap.bootstrap(ImporterBootstrap.java:357)
I have gone through the above blogs ,from this am able to create a spring bean and help me how to create java class for that bean


Thanks and regards