Skip to content

Commit

Permalink
Merge branch 'release/14.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Van Geem committed Oct 2, 2019
2 parents 44225c6 + 882e645 commit 6113995
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<groupId>com.icfolson.aem.groovy.console</groupId>
<artifactId>aem-groovy-console</artifactId>
<packaging>jar</packaging>
<version>13.0.0</version>
<version>14.0.0</version>
<name>AEM Groovy Console</name>
<description>
The AEM Groovy Console provides an interface for running Groovy scripts in the AEM container. Scripts can be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h4 class="panel-title">
</div>
<div id="enhancements" class="panel-collapse collapse">
<div class="panel-body">
<p>See the AEM Groovy Extension documentation <a href="http://code.digitalatolson.com/aem-groovy-extension/groovydocs/com/citytechinc/aem/groovy/extension/services/impl/DefaultMetaClassExtensionProvider.html" target="_blank">here</a> for details on registered metaclasses.</p>
<p>See the AEM Groovy Extension documentation <a href="http://code.digitalatolson.com/aem-groovy-extension/groovydocs/com/icfolson/aem/groovy/extension/services/impl/DefaultMetaClassExtensionProvider.html" target="_blank">here</a> for details on registered metaclasses.</p>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -26,8 +25,6 @@ class DefaultConfigurationService implements ConfigurationService {
@Reference
private ResourceResolverFactory resourceResolverFactory

private ResourceResolver resourceResolver

boolean emailEnabled

Set<String> emailRecipients
Expand All @@ -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
Expand All @@ -59,25 +63,14 @@ 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
vanityPathEnabled = properties.vanityPathEnabled()
auditDisabled = properties.auditDisabled()
displayAllAuditRecords = properties.auditDisplayAll()
}

@Deactivate
void deactivate() {
resourceResolver?.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit 6113995

Please sign in to comment.