Groovy Module

The Groovy module consists of 2 parts:

Commons Groovy Module

The Groovy execution API provides the possibility to define GroovyCompilationCustomizer components in order to customize the execution of Groovy scripts: automatically add imports, stop script execution after a certain timeout, prevent using some imports, statements or operators.

The module also provides a TimedInterruptCustomizerConfiguration interface allowing to stop executing Groovy scripts after a certain timeout thus preventing long running operations. 

The Timed Interrupt Customizer works only for Groovy code but if this one calls Java methods which take a long time to execute, the execution will be stopped only when the Groovy code regains control.

Implement a Timed Interrupt Customizer

To implement a customizer, you need to add a Component implementing the GroovyCompilationCustomizer Component Role, then to implement the CompilationCustomizer createCustomizer(); method.

@Component
@Named("customTimedInterrupt")
@Singleton
public class TimedInterruptGroovyCompilationCustomizer implements GroovyCompilationCustomizer
{
  /**
     * Used to get the script timeout configuration parameter value.
     */

  @Inject
  private TimedInterruptCustomizerConfiguration configuration;

  @Override
  public CompilationCustomizer createCustomizer()
  {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("value", this.configuration.getTimeout());
      return new ASTTransformationCustomizer(parameters, TimedInterrupt.class);
  }
}

Since Groovy customizers are not enabled by default, each time you create one, you have to edit the WEB-INF/xwiki.properties file and add the groovy.compilationCustomizers property. The value will be a coma-separated list of customizer identifiers, like for instance:

groovy.compilationCustomizers=customTimedInterrupt 

Additionally, you can use the groovy.customizer.timedInterrupt.timeout parameter in order to configure the Timed Interrupt Customizer timeout. The value should be in seconds.

Platform Groovy Module

The Platform Groovy module complements the Commons Groovy module by adding a Secure Groovy Compilation Customizer allowing to run Groovy scripts in a Security Sandbox. The Secure Customizer prevents:

  • bytecode expressions and sequences
  • synchronized blocks; e.g. synchronized(this) { }
  • imports
  • method definition
  • any token

Just like in the above example, in order to enable the Secure Groovy Compilation Customizer, you have to edit the WEB-INF/xwiki.properties file and add the groovy.compilationCustomizers property as follows: groovy.compilationCustomizers=secure 

    

Related Pages

Search this space

 

Most popular tags

Failed to execute the [groovy] macro
  1. access rights
  2. activity stream
  3. annotation
  4. attachment
  5. comment
  6. Document Tree Macro
  7. export
  8. Extension Manager
  9. Flamingo skin
  10. global user
  11. Groovy event listener
  12. group
  13. nested page
  14. search
  15. skin
  16. syntax
  17. user
  18. user profile
  19. velocity macros
  20. wiki
  21. wysiwyg
  22. XWiki Applications
  23. xwikiattachment_archive table
  24. xwikiattachment table
  25. xwikiattrecyclebin table
  26. xwikiproperties table

[Display all tags from this space]