diff --git a/README.md b/README.md index 02adb076..e9635526 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ The AEM Groovy Console provides an interface for running [Groovy](http://www.gro ## Compatibility -Groovy Console Version(s) | AEM Version +Groovy Console Version(s) | AEM Version(s) ------------ | ------------- -13.x.x | 6.3, 6.4, 6.5 +14.x.x, 13.x.x | 6.3, 6.4, 6.5 12.x.x | 6.4 11.x.x | 6.3 10.x.x, 9.x.x | 6.2 @@ -81,9 +81,16 @@ Saved scripts can be remotely executed by sending a POST request to the console ## Extensions -Beginning in version 7.0.0, the Groovy Console provides extension hooks to further customize script execution. The console exposes an API containing three extension provider interfaces that can be implemented as OSGi services in any bundle deployed to an AEM instance. See the default extension providers in the `com.icfolson.aem.groovy.console.extension.impl` package for examples of how a bundle can implement these services to supply additional script bindings, metaclasses, and star imports. +The Groovy Console provides extension hooks to further customize script execution. The console provides an API containing extension provider interfaces that can be implemented as OSGi services in any bundle deployed to an AEM instance. See the default extension providers in the `com.icfolson.aem.groovy.console.extension.impl` package for examples of how a bundle can implement these services to supply additional script bindings, compilation customizers, metaclasses, and star imports. -### Notifications +Service Interface | Description +------------ | ------------- +`com.icfolson.aem.groovy.console.api.BindingExtensionProvider` | Customize the bindings that are provided for each script execution. +`com.icfolson.aem.groovy.console.api.CompilationCustomizerExtensionProvider` | Restrict language features (via blacklist or whitelist) or provide AST transformations within the Groovy script compilation. +`com.icfolson.aem.groovy.console.api.ScriptMetaClassExtensionProvider` | Add runtime metaclasses (i.e. new methods) to the underlying script class. +`com.icfolson.aem.groovy.console.api.StarImportExtensionProvider` | Supply additional star imports that are added to the compiler configuration for each script execution. + +## Notifications To provide custom notifications for script executions, bundles may implement the `com.icfolson.aem.groovy.console.notification.NotificationService` interface (see the `com.icfolson.aem.groovy.console.notification.impl.EmailNotificationService` class for an example). These services will be dynamically bound by the Groovy Console service and all registered notification services will be called for each script execution. diff --git a/pom.xml b/pom.xml index 2996cc95..fa11f646 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ com.icfolson.aem.groovy.console aem-groovy-console jar - 13.0.0 + 14.0.0 AEM Groovy Console The AEM Groovy Console provides an interface for running Groovy scripts in the AEM container. Scripts can be diff --git a/src/main/content/jcr_root/apps/groovyconsole/components/console/enhancements.html b/src/main/content/jcr_root/apps/groovyconsole/components/console/enhancements.html index d12b7446..07bb661e 100644 --- a/src/main/content/jcr_root/apps/groovyconsole/components/console/enhancements.html +++ b/src/main/content/jcr_root/apps/groovyconsole/components/console/enhancements.html @@ -6,7 +6,7 @@

-

See the AEM Groovy Extension documentation here for details on registered metaclasses.

+

See the AEM Groovy Extension documentation here for details on registered metaclasses.

\ No newline at end of file diff --git a/src/main/groovy/com/icfolson/aem/groovy/console/configuration/impl/DefaultConfigurationService.groovy b/src/main/groovy/com/icfolson/aem/groovy/console/configuration/impl/DefaultConfigurationService.groovy index 8f1f71a2..600a1c4b 100755 --- a/src/main/groovy/com/icfolson/aem/groovy/console/configuration/impl/DefaultConfigurationService.groovy +++ b/src/main/groovy/com/icfolson/aem/groovy/console/configuration/impl/DefaultConfigurationService.groovy @@ -3,18 +3,17 @@ package com.icfolson.aem.groovy.console.configuration.impl import com.icfolson.aem.groovy.console.configuration.ConfigurationService import groovy.transform.Synchronized import groovy.util.logging.Slf4j +import org.apache.jackrabbit.api.security.user.User import org.apache.jackrabbit.api.security.user.UserManager import org.apache.sling.api.SlingHttpServletRequest -import org.apache.sling.api.resource.ResourceResolver import org.apache.sling.api.resource.ResourceResolverFactory import org.osgi.service.component.annotations.Activate import org.osgi.service.component.annotations.Component -import org.osgi.service.component.annotations.Deactivate import org.osgi.service.component.annotations.Modified import org.osgi.service.component.annotations.Reference import org.osgi.service.metatype.annotations.Designate -@Component(service = ConfigurationService) +@Component(service = ConfigurationService, immediate = true) @Designate(ocd = ConfigurationServiceProperties) @Slf4j("LOG") class DefaultConfigurationService implements ConfigurationService { @@ -26,8 +25,6 @@ class DefaultConfigurationService implements ConfigurationService { @Reference private ResourceResolverFactory resourceResolverFactory - private ResourceResolver resourceResolver - boolean emailEnabled Set emailRecipients @@ -42,15 +39,22 @@ class DefaultConfigurationService implements ConfigurationService { @Override boolean hasPermission(SlingHttpServletRequest request) { - resourceResolver.refresh() + def resourceResolver = resourceResolverFactory.getServiceResourceResolver(null) + + def hasPermission = false - def user = resourceResolver.adaptTo(UserManager).getAuthorizable(request.userPrincipal) + try { + def user = resourceResolver.adaptTo(UserManager).getAuthorizable(request.userPrincipal) as User + def memberOfGroupIds = user.memberOf()*.ID - def memberOfGroupIds = user.memberOf()*.ID + LOG.debug("member of group IDs = {}, allowed group IDs = {}", memberOfGroupIds, allowedGroups) - LOG.debug("member of group IDs = {}, allowed group IDs = {}", memberOfGroupIds, allowedGroups) + hasPermission = allowedGroups ? user.admin || memberOfGroupIds.intersect(allowedGroups as Iterable) : false + } finally { + resourceResolver.close() + } - allowedGroups ? memberOfGroupIds.intersect(allowedGroups as Iterable) : true + hasPermission } @Override @@ -59,15 +63,9 @@ class DefaultConfigurationService implements ConfigurationService { } @Activate - void activate(ConfigurationServiceProperties properties) { - resourceResolver = resourceResolverFactory.getServiceResourceResolver(null) - - modified(properties) - } - @Modified @Synchronized - void modified(ConfigurationServiceProperties properties) { + void activate(ConfigurationServiceProperties properties) { emailEnabled = properties.emailEnabled() emailRecipients = (properties.emailRecipients() ?: []).findAll() as Set allowedGroups = (properties.allowedGroups() ?: []).findAll() as Set @@ -75,9 +73,4 @@ class DefaultConfigurationService implements ConfigurationService { auditDisabled = properties.auditDisabled() displayAllAuditRecords = properties.auditDisplayAll() } - - @Deactivate - void deactivate() { - resourceResolver?.close() - } } diff --git a/src/main/groovy/com/icfolson/aem/groovy/console/impl/DefaultGroovyConsoleService.groovy b/src/main/groovy/com/icfolson/aem/groovy/console/impl/DefaultGroovyConsoleService.groovy index e9518bc0..34373a88 100755 --- a/src/main/groovy/com/icfolson/aem/groovy/console/impl/DefaultGroovyConsoleService.groovy +++ b/src/main/groovy/com/icfolson/aem/groovy/console/impl/DefaultGroovyConsoleService.groovy @@ -34,7 +34,7 @@ import static com.icfolson.aem.groovy.console.constants.GroovyConsoleConstants.E import static com.icfolson.aem.groovy.console.constants.GroovyConsoleConstants.PARAMETER_DATA import static com.icfolson.aem.groovy.console.constants.GroovyConsoleConstants.PATH_SCRIPTS_FOLDER -@Component(service = GroovyConsoleService) +@Component(service = GroovyConsoleService, immediate = true) @Slf4j("LOG") class DefaultGroovyConsoleService implements GroovyConsoleService { diff --git a/src/main/groovy/com/icfolson/aem/groovy/console/notification/impl/EmailNotificationService.groovy b/src/main/groovy/com/icfolson/aem/groovy/console/notification/impl/EmailNotificationService.groovy index e3e4fad4..ed607877 100644 --- a/src/main/groovy/com/icfolson/aem/groovy/console/notification/impl/EmailNotificationService.groovy +++ b/src/main/groovy/com/icfolson/aem/groovy/console/notification/impl/EmailNotificationService.groovy @@ -13,7 +13,7 @@ import org.osgi.service.component.annotations.Component import org.osgi.service.component.annotations.Reference import org.osgi.service.component.annotations.ReferenceCardinality -@Component(service = NotificationService) +@Component(service = NotificationService, immediate = true) @Slf4j("LOG") class EmailNotificationService implements NotificationService {