1 40 41 42 package org.jahia.services.audit; 43 44 import org.jahia.data.containers.JahiaContainer; 45 import org.jahia.data.containers.JahiaContainerList; 46 import org.jahia.data.events.JahiaEvent; 47 import org.jahia.data.events.JahiaEventListener; 48 import org.jahia.data.fields.JahiaField; 49 import org.jahia.exceptions.JahiaException; 50 import org.jahia.registries.ServicesRegistry; 51 import org.jahia.services.pages.JahiaPage; 52 import org.jahia.services.pages.JahiaPageDefinition; 53 import org.jahia.utils.JahiaObjectTool; 54 55 56 public class LoggingEventListener extends JahiaEventListener { 57 58 public static final int FIELD_TYPE = JahiaObjectTool.FIELD_TYPE; 59 public static final int CONTAINER_TYPE = JahiaObjectTool.CONTAINER_TYPE; 60 public static final int CONTAINERLIST_TYPE = JahiaObjectTool.CONTAINERLIST_TYPE; 61 public static final int PAGE_TYPE = JahiaObjectTool.PAGE_TYPE; 62 public static final int ACL_TYPE = JahiaObjectTool.ACL_TYPE; 63 64 private final String MSG_INTERNAL_ERROR = new String ("Logging Event Listener internal error"); 65 66 private int objectType = 0; 67 68 private JahiaAuditLogManagerService mAuditLogManager = null; 70 71 72 76 public LoggingEventListener () 77 throws JahiaException { 78 ServicesRegistry registry = ServicesRegistry.getInstance (); 80 if (registry != null) { 81 mAuditLogManager = registry.getJahiaAuditLogManagerService (); 82 if (mAuditLogManager == null) { 83 throw new JahiaException (MSG_INTERNAL_ERROR, "User manager could not get the Audit Log Manager Service instance.", 84 JahiaException.SERVICE_ERROR, JahiaException.CRITICAL_SEVERITY); 85 } 86 87 } else { 88 throw new JahiaException (MSG_INTERNAL_ERROR, "User manager could not get the Service Registry instance.", 89 JahiaException.REGISTRY_ERROR, JahiaException.CRITICAL_SEVERITY); 90 } 91 } 93 94 100 public void fieldAdded (JahiaEvent je) { 101 if (je != null && je.getObject () != null) { 102 JahiaField theField = (JahiaField)je.getObject (); 103 mAuditLogManager.logEvent (je, FIELD_TYPE, "added field"); 104 } 105 } 106 107 108 114 public void fieldUpdated (JahiaEvent je) { 115 JahiaField theField = (JahiaField)je.getObject (); 116 mAuditLogManager.logEvent (je, FIELD_TYPE, "modified field"); 117 } 118 119 120 126 public void fieldDeleted (JahiaEvent je) { 127 JahiaField theField = (JahiaField)je.getObject (); 128 mAuditLogManager.logEvent (je, FIELD_TYPE, "deleted field"); 129 } 130 131 132 138 public void containerAdded (JahiaEvent je) { 139 JahiaContainer theContainer = (JahiaContainer)je.getObject (); 140 mAuditLogManager.logEvent (je, CONTAINER_TYPE, "added container"); 141 } 142 143 144 148 public void containerUpdated (JahiaEvent je) { 149 JahiaContainer theContainer = (JahiaContainer)je.getObject (); 150 mAuditLogManager.logEvent (je, CONTAINER_TYPE, "updated container"); 151 } 152 153 154 158 public void containerDeleted (JahiaEvent je) { 159 JahiaContainer theContainer = (JahiaContainer)je.getObject (); 160 mAuditLogManager.logEvent (je, CONTAINER_TYPE, "deleted container"); 161 } 162 163 164 168 public void pageAdded (JahiaEvent je) { 169 JahiaPage thePage = (JahiaPage)je.getObject (); 170 mAuditLogManager.logEvent (je, PAGE_TYPE, "added page"); 171 } 172 173 174 178 public void pagePropertiesSet (JahiaEvent je) { 179 JahiaPage thePage = (JahiaPage)je.getObject (); 180 mAuditLogManager.logEvent (je, PAGE_TYPE, "set properties for page"); 181 } 182 183 184 189 public void templateUpdated (JahiaEvent je) { 190 if (je.getObject () != null) { 191 JahiaPageDefinition theTemplate = (JahiaPageDefinition)je.getObject (); 192 mAuditLogManager.logEvent (je, JahiaObjectTool.TEMPLATE_TYPE, "template updated"); 193 } 194 } 195 196 197 201 public void containerListPropertiesSet (JahiaEvent je) { 202 JahiaContainerList theContainerList = (JahiaContainerList)je.getObject (); 203 mAuditLogManager.logEvent (je, CONTAINERLIST_TYPE, "set properties for containerList"); 204 } 205 206 207 211 public void rightsSet (JahiaEvent je) { 212 Object theObject = je.getObject (); 213 if (theObject instanceof JahiaField) { 214 mAuditLogManager.logEvent (je, FIELD_TYPE, "set rights"); 215 } else if (theObject instanceof JahiaField) { 216 mAuditLogManager.logEvent (je, FIELD_TYPE, "set rights"); 217 } else if (theObject instanceof JahiaContainer) { 218 mAuditLogManager.logEvent (je, CONTAINER_TYPE, "set rights"); 219 } else if (theObject instanceof JahiaContainerList) { 220 mAuditLogManager.logEvent (je, CONTAINERLIST_TYPE, "set rights"); 221 } else if (theObject instanceof JahiaPage) { 222 mAuditLogManager.logEvent (je, PAGE_TYPE, "set rights"); 223 } 224 } 225 226 } 227 | Popular Tags |