Skip to content

Commit

Permalink
System notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
justinedelson committed Nov 29, 2016
1 parent 9a91ba2 commit 1088964
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

@Component(immediate = true)
Expand All @@ -78,6 +80,8 @@ public class SystemNotificationsImpl extends AbstractHtmlRequestInjector impleme

private static final String PN_ENABLED = "enabled";

private static final String REP_POLICY = "rep:policy";

private static final String INJECT_TEXT =
"<script>"
+ "if(window === top) {"
Expand All @@ -86,6 +90,12 @@ public class SystemNotificationsImpl extends AbstractHtmlRequestInjector impleme
+ "}"
+ "</script>";

private static final String SERVICE_NAME = "system-notifications";
private static final Map<String, Object> AUTH_INFO;
static {
AUTH_INFO = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) SERVICE_NAME);
}

private AtomicBoolean isFilter = new AtomicBoolean(false);

private ComponentContext osgiComponentContext;
Expand Down Expand Up @@ -194,7 +204,8 @@ public String getMessage(String message, String onTime, String offTime) {

private boolean isActiveNotification(final SlingHttpServletRequest request,
final Resource resource) {
if (JcrConstants.JCR_CONTENT.equals(resource.getName())) {
if (JcrConstants.JCR_CONTENT.equals(resource.getName()) ||
REP_POLICY.equals(resource.getName())) {
return false;
}

Expand Down Expand Up @@ -255,19 +266,20 @@ private boolean hasNotifications() {
ResourceResolver resourceResolver = null;

try {
resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
resourceResolver = resourceResolverFactory.getServiceResourceResolver(AUTH_INFO);

final Resource notificationsFolder = resourceResolver.getResource(PATH_NOTIFICATIONS);
final Iterator<Resource> resources = notificationsFolder.listChildren();

while (resources.hasNext()) {
final Resource resource = resources.next();
if (!JcrConstants.JCR_CONTENT.equals(resource.getName())) {
if (!JcrConstants.JCR_CONTENT.equals(resource.getName()) &&
!REP_POLICY.equals(resource.getName())) {
return true;
}
}
} catch (LoginException e) {
log.error("Could not get an admin ResourceResolver", e);
log.error("Could not get an service ResourceResolver", e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
Expand Down Expand Up @@ -320,25 +332,14 @@ public void handleEvent(final Event event) {
return;
}

ResourceResolver resourceResolver = null;
try {
resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);

if (this.hasNotifications()) {
if (!this.isFilter.getAndSet(true)) {
this.registerAsFilter();
}
} else {
if (this.isFilter.getAndSet(false)) {
this.unregisterFilter();
log.debug("Unregistered System Notifications Sling Filter");
}
if (this.hasNotifications()) {
if (!this.isFilter.getAndSet(true)) {
this.registerAsFilter();
}
} catch (LoginException e) {
log.error("Could not get an admin ResourceResolver", e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
} else {
if (this.isFilter.getAndSet(false)) {
this.unregisterFilter();
log.debug("Unregistered System Notifications Sling Filter");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
user.mapping="[com.adobe.acs.acs-aem-commons-bundle:ensure-oak-index=acs-commons-ensure-oak-index-service,com.adobe.acs.acs-aem-commons-bundle:email-service=acs-commons-email-service,com.adobe.acs.acs-aem-commons-bundle:review-task-asset-mover=acs-commons-review-task-asset-mover-service,com.adobe.acs.acs-aem-commons-bundle:error-page-handler=acs-commons-error-page-handler-service,com.adobe.acs.acs-aem-commons-bundle:form-helper=acs-commons-form-helper-service,com.adobe.acs.acs-aem-commons-bundle:dispatcher-flush=acs-commons-dispatcher-flush-service,com.adobe.acs.acs-aem-commons-bundle:package-replication-status-event-listener=acs-commons-package-replication-status-event-service,com.adobe.acs.acs-aem-commons-bundle:component-error-handler=acs-commons-component-error-handler-service]"/>
user.mapping="[com.adobe.acs.acs-aem-commons-bundle:ensure-oak-index=acs-commons-ensure-oak-index-service,com.adobe.acs.acs-aem-commons-bundle:email-service=acs-commons-email-service,com.adobe.acs.acs-aem-commons-bundle:review-task-asset-mover=acs-commons-review-task-asset-mover-service,com.adobe.acs.acs-aem-commons-bundle:error-page-handler=acs-commons-error-page-handler-service,com.adobe.acs.acs-aem-commons-bundle:form-helper=acs-commons-form-helper-service,com.adobe.acs.acs-aem-commons-bundle:dispatcher-flush=acs-commons-dispatcher-flush-service,com.adobe.acs.acs-aem-commons-bundle:package-replication-status-event-listener=acs-commons-package-replication-status-event-service,com.adobe.acs.acs-aem-commons-bundle:component-error-handler=acs-commons-component-error-handler-service,com.adobe.acs.acs-aem-commons-bundle:system-notifications=acs-commons-system-notifications-service]"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
jcr:primaryType="rep:ACL">
<allow
jcr:primaryType="rep:GrantACE"
rep:principalName="acs-commons-system-notifications-service"
rep:privileges="{Name}[jcr:read]"/>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
jcr:primaryType="rep:SystemUser"
jcr:uuid="8c1283dc-f7f0-3084-909b-5bc052b01cd0"
rep:authorizableId="acs-commons-system-notifications-service"
rep:principalName="acs-commons-system-notifications-service"/>
8 changes: 8 additions & 0 deletions generate-user-uuid.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env groovy

if (this.args.length != 1) {
System.err.println("[ERROR] Must provide a userId")
return
}

println java.util.UUID.nameUUIDFromBytes(this.args[0].getBytes("UTF-8")).toString();

0 comments on commit 1088964

Please sign in to comment.