SAIL-240 (SAIL-294): DAO refactor for Audit.hbm.xml

- Removed audit.hbm.xml and related audit classes
 - Audit tests grouped into suite


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20870 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-06-29 14:49:52 +00:00
parent 1b9e0d9837
commit a2e13ba30f
59 changed files with 98 additions and 7444 deletions

View File

@@ -1,305 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
import org.alfresco.repo.audit.AuditMode;
import org.alfresco.repo.audit.AuditModel;
import org.alfresco.repo.audit.PublicServiceIdentifier;
import org.alfresco.repo.audit.RecordOptions;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Attribute;
import org.dom4j.Element;
public abstract class AbstractAuditEntry
{
private static Log s_logger = LogFactory.getLog(AbstractAuditEntry.class);
private RecordOptionsImpl recordOptions = null;
private AbstractFilter filter = null;
private AuditMode auditMode = AuditMode.UNSET;
private TrueFalseUnset enabled = TrueFalseUnset.UNSET;
private TrueFalseUnset auditInternal = TrueFalseUnset.UNSET;
private AbstractAuditEntry parent;
private PublicServiceIdentifier publicServiceIdentifier;
public AbstractAuditEntry()
{
super();
}
PublicServiceIdentifier getPublicServiceIdentifier()
{
return publicServiceIdentifier;
}
public void setPublicServiceIdentifier(PublicServiceIdentifier publicServiceIdentifier)
{
this.publicServiceIdentifier = publicServiceIdentifier;
}
void configure(AbstractAuditEntry parent, Element element, NamespacePrefixResolver namespacePrefixResolver)
{
this.parent = parent;
Attribute auditModeAttribute = element.attribute(AuditModel.AT_MODE);
if (auditModeAttribute != null)
{
auditMode = AuditMode.getAuditMode(auditModeAttribute.getValue());
}
if(s_logger.isDebugEnabled())
{
s_logger.debug("Audit Mode = "+auditMode);
}
Attribute enabledAttribute = element.attribute(AuditModel.AT_ENABLED);
if (enabledAttribute != null)
{
enabled = TrueFalseUnset.getTrueFalseUnset(enabledAttribute.getValue());
}
if(s_logger.isDebugEnabled())
{
s_logger.debug("Enabled = "+enabled);
}
Attribute auditInternalAttribute = element.attribute(AuditModel.AT_AUDIT_INTERNAL);
if (auditInternalAttribute != null)
{
auditInternal = TrueFalseUnset.getTrueFalseUnset(auditInternalAttribute.getValue());
}
if(s_logger.isDebugEnabled())
{
s_logger.debug("Audit Internal = "+auditInternal);
}
// Make record options
Element recordOptionElement = element.element(AuditModel.EL_RECORD_OPTIONS);
if (recordOptionElement != null)
{
recordOptions = new RecordOptionsImpl();
recordOptions.configure(recordOptionElement, namespacePrefixResolver);
}
if(s_logger.isDebugEnabled())
{
s_logger.debug("Record Options = "+recordOptions);
}
// Make filters
Element filterElement = element.element(AuditModel.EL_FILTER);
if (filterElement != null)
{
filter = AbstractFilter.createFilter(filterElement, namespacePrefixResolver);
}
if(s_logger.isDebugEnabled())
{
s_logger.debug("Filter = "+filter);
}
}
/* package */TrueFalseUnset getAuditInternal()
{
return auditInternal;
}
/* package */AuditMode getAuditMode()
{
return auditMode;
}
public TrueFalseUnset getEnabled()
{
return enabled;
}
/* package */AbstractFilter getFilter()
{
return filter;
}
/* package */AbstractAuditEntry getParent()
{
return parent;
}
/* package */RecordOptionsImpl getRecordOptions()
{
return recordOptions;
}
protected TrueFalseUnset getEffectiveAuditInternal()
{
TrueFalseUnset auditInternal;
if (checkEnabled() == TrueFalseUnset.TRUE)
{
auditInternal = getAuditInternalOrParentAuditInternal();
}
else
{
auditInternal = TrueFalseUnset.FALSE;
}
if(s_logger.isDebugEnabled())
{
s_logger.debug("... Effective audit internal is = "+auditInternal);
}
return auditInternal;
}
private TrueFalseUnset getAuditInternalOrParentAuditInternal()
{
TrueFalseUnset auditInternal = getAuditInternal();
if(s_logger.isDebugEnabled())
{
s_logger.debug("... ... audit internal is = "+auditInternal);
}
if (auditInternal == TrueFalseUnset.UNSET)
{
if (getParent() == null)
{
return TrueFalseUnset.UNSET;
}
else
{
return getParent().getAuditInternalOrParentAuditInternal();
}
}
else
{
return auditInternal;
}
}
protected AuditMode getEffectiveAuditMode()
{
AuditMode auditMode;
if (checkEnabled() == TrueFalseUnset.TRUE)
{
auditMode = getAuditModeOrParentAuditMode();
}
else
{
auditMode = AuditMode.NONE;
}
if(s_logger.isDebugEnabled())
{
s_logger.debug("... Effective audit mode is = "+auditMode);
}
return auditMode;
}
private AuditMode getAuditModeOrParentAuditMode()
{
AuditMode auditMode = getAuditMode();
if(s_logger.isDebugEnabled())
{
s_logger.debug("... ... audit mode is = "+auditMode);
}
if (auditMode == AuditMode.UNSET)
{
if (getParent() == null)
{
return AuditMode.UNSET;
}
else
{
return getParent().getAuditModeOrParentAuditMode();
}
}
else
{
return auditMode;
}
}
protected RecordOptions getEffectiveRecordOptions()
{
RecordOptions recordOptions;
if (checkEnabled() == TrueFalseUnset.TRUE)
{
recordOptions = getRecordOptionsOrParentRecordOptions();
}
else
{
recordOptions = null;
}
if(s_logger.isDebugEnabled())
{
s_logger.debug("...Record Options = "+recordOptions);
}
return recordOptions;
}
private RecordOptions getRecordOptionsOrParentRecordOptions()
{
RecordOptions recordOptions = getRecordOptions();
if(s_logger.isDebugEnabled())
{
s_logger.debug("... ... record options = "+recordOptions);
}
if (recordOptions == null)
{
if (getParent() == null)
{
return null;
}
else
{
return getParent().getRecordOptionsOrParentRecordOptions();
}
}
else
{
return recordOptions;
}
}
private TrueFalseUnset checkEnabled()
{
TrueFalseUnset effective = getEnabled();
if (getParent() != null)
{
if ((getParent().checkEnabled() == TrueFalseUnset.TRUE) && (effective != TrueFalseUnset.FALSE))
{
return TrueFalseUnset.TRUE;
}
}
else
{
if (effective == TrueFalseUnset.TRUE)
{
return TrueFalseUnset.TRUE;
}
}
return TrueFalseUnset.FALSE;
}
}

View File

@@ -1,94 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
import org.alfresco.repo.audit.AuditModel;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Attribute;
import org.dom4j.Element;
/**
* The base class for filtering.
*
* This supports negating the filter, ie NOT.
*
* @author Andy Hind
*/
public abstract class AbstractFilter implements XMLModelElement
{
private static Log s_logger = LogFactory.getLog(AbstractFilter.class);
private boolean invert = false;
public AbstractFilter()
{
super();
}
public static AbstractFilter createFilter(Element filterElement, NamespacePrefixResolver namespacePrefixResolver)
{
AbstractFilter filter;
Attribute typeAttribute = filterElement.attribute(AuditModel.AT_TYPE);
if (typeAttribute == null)
{
throw new AuditModelException("A filter must specify it concrete type using xsi:type");
}
if (typeAttribute.getStringValue().endsWith("FilterSet"))
{
filter = new FilterSet();
}
else if (typeAttribute.getStringValue().endsWith("KeyFilter"))
{
filter = new KeyFilter();
}
else if (typeAttribute.getStringValue().endsWith("ParameterFilter"))
{
filter = new ParameterFilter();
}
else
{
throw new AuditModelException(
"Invalid filter type. It must be one of: FilterSet, KeyFilter, ParameterFilter ");
}
filter.configure(filterElement, namespacePrefixResolver);
return filter;
}
public void configure(Element element, NamespacePrefixResolver namespacePrefixResolver)
{
Attribute invertAttribute = element.attribute(AuditModel.AT_INVERT);
if (invertAttribute != null)
{
invert = Boolean.valueOf(invertAttribute.getStringValue()).booleanValue();
}
else
{
invert = false;
}
}
/* package */boolean isInvert()
{
return invert;
}
}

View File

@@ -1,65 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
import org.alfresco.repo.audit.AuditModel;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Attribute;
import org.dom4j.Element;
public abstract class AbstractNamedAuditEntry extends AbstractAuditEntry
{
private static Log s_logger = LogFactory.getLog(AbstractNamedAuditEntry.class);
private String name;
public AbstractNamedAuditEntry()
{
super();
}
@Override
void configure(AbstractAuditEntry parent, Element element, NamespacePrefixResolver namespacePrefixResolver)
{
Attribute nameAttribute = element.attribute(AuditModel.AT_NAME);
if (nameAttribute != null)
{
name = nameAttribute.getStringValue();
}
else
{
throw new AuditModelException("The name attribute is mandatory");
}
if(s_logger.isDebugEnabled())
{
s_logger.debug("Name = "+name);
}
super.configure(parent, element, namespacePrefixResolver);
}
/* package */String getName()
{
return name;
}
}

View File

@@ -1,62 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
import org.alfresco.repo.audit.ApplicationAuditModel;
import org.alfresco.repo.audit.AuditMode;
import org.alfresco.repo.audit.RecordOptions;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class ApplicationAuditEntry extends AbstractNamedAuditEntry implements ApplicationAuditModel
{
private static Log s_logger = LogFactory.getLog(ApplicationAuditEntry.class);
public ApplicationAuditEntry()
{
super();
}
public AuditMode beforeExecution(AuditMode auditMode, String application, String description, NodeRef key, Object... args)
{
if(s_logger.isDebugEnabled())
{
s_logger.debug("Evaluating if application is audited ..."+application);
}
return getEffectiveAuditMode();
}
public AuditMode afterExecution(AuditMode auditMode, String application, String description, NodeRef key, Object... args)
{
throw new UnsupportedOperationException();
}
public AuditMode onError(AuditMode auditMode, String application, String description, NodeRef key, Object... args)
{
throw new UnsupportedOperationException();
}
public RecordOptions getAuditRecordOptions(String application)
{
return getEffectiveRecordOptions();
}
}

View File

@@ -1,303 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.alfresco.repo.audit.AuditConfiguration;
import org.alfresco.repo.audit.AuditMode;
import org.alfresco.repo.audit.AuditModel;
import org.alfresco.repo.audit.RecordOptions;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.InitializingBean;
public class AuditEntry extends AbstractAuditEntry implements InitializingBean, AuditModel
{
private static Log s_logger = LogFactory.getLog(AuditEntry.class);
private Map<String, ServiceAuditEntry> services = new HashMap<String, ServiceAuditEntry>();
private Map<String, ApplicationAuditEntry> applications = new HashMap<String, ApplicationAuditEntry>();
private AuditConfiguration auditConfiguration;
private NamespacePrefixResolver namespacePrefixResolver;
public AuditEntry()
{
super();
}
public AuditConfiguration getAuditConfiguration()
{
return auditConfiguration;
}
public void setAuditConfiguration(AuditConfiguration auditConfiguration)
{
this.auditConfiguration = auditConfiguration;
}
public void setNamespacePrefixResolver(NamespacePrefixResolver namespacePrefixResolver)
{
this.namespacePrefixResolver = namespacePrefixResolver;
}
public void afterPropertiesSet() throws Exception
{
Document document = createDocument();
Element root = document.getRootElement();
// Check it is the correct thing
configure(null, root, namespacePrefixResolver);
}
@Override
void configure(AbstractAuditEntry parent, Element element, NamespacePrefixResolver namespacePrefixResolver)
{
if (!element.getNamespaceURI().equals(AuditModel.NAME_SPACE))
{
throw new AuditModelException("Audit model has incorrect name space");
}
if (!element.getName().equals(AuditModel.EL_AUDIT))
{
throw new AuditModelException("Audit model has incorrect root node");
}
if (s_logger.isDebugEnabled())
{
s_logger.debug("Audit configuration");
}
super.configure(parent, element, namespacePrefixResolver);
// Add services
if (s_logger.isDebugEnabled())
{
s_logger.debug("Adding services ...");
}
for (Iterator nsit = element.elementIterator(AuditModel.EL_SERVICE); nsit.hasNext(); /**/)
{
Element serviceElement = (Element) nsit.next();
ServiceAuditEntry service = new ServiceAuditEntry();
service.configure(this, serviceElement, namespacePrefixResolver);
services.put(service.getName(), service);
}
// Add Applications
if (s_logger.isDebugEnabled())
{
s_logger.debug("Adding applications ...");
}
for (Iterator nsit = element.elementIterator(AuditModel.EL_APPLICATION); nsit.hasNext(); /**/)
{
Element applicationElement = (Element) nsit.next();
ApplicationAuditEntry application = new ApplicationAuditEntry();
application.configure(this, applicationElement, namespacePrefixResolver);
applications.put(application.getName(), application);
}
}
public AuditMode beforeExecution(AuditMode auditMode, MethodInvocation mi)
{
String serviceName = getPublicServiceIdentifier().getPublicServiceName(mi);
ServiceAuditEntry service = services.get(serviceName);
if (service != null)
{
MethodAuditEntry method = service.getMethodAuditEntry(mi.getMethod().getName());
if (method != null)
{
return method.beforeExecution(auditMode, mi);
}
else
{
return service.beforeExecution(auditMode, mi);
}
}
else
{
if (s_logger.isDebugEnabled())
{
s_logger.debug("No specific audit entry for service " + serviceName);
}
return getEffectiveAuditMode();
}
}
public AuditMode afterExecution(AuditMode auditMode, MethodInvocation mi)
{
throw new UnsupportedOperationException();
}
public RecordOptions getAuditRecordOptions(MethodInvocation mi)
{
String serviceName = getPublicServiceIdentifier().getPublicServiceName(mi);
ServiceAuditEntry service = services.get(serviceName);
if (service != null)
{
MethodAuditEntry method = service.getMethodAuditEntry(mi.getMethod().getName());
if (method != null)
{
return method.getAuditRecordOptions(mi);
}
else
{
return service.getAuditRecordOptions(mi);
}
}
else
{
if (s_logger.isDebugEnabled())
{
s_logger.debug("No specific audit entry for service " + serviceName);
}
return getEffectiveRecordOptions();
}
}
public AuditMode onError(AuditMode auditMode, MethodInvocation mi)
{
throw new UnsupportedOperationException();
}
private Document createDocument()
{
InputStream is = null;
try
{
is = auditConfiguration.getInputStream();
if (is == null)
{
throw new AuditModelException("Audit configuration could not be opened");
}
SAXReader reader = new SAXReader();
try
{
Document document = reader.read(is);
return document;
}
catch (DocumentException e)
{
throw new AuditModelException("Failed to create audit model document ", e);
}
}
finally
{
if (is != null)
{
try
{
is.close();
}
catch (IOException e)
{
throw new AuditModelException("Failed to close audit model document ", e);
}
}
}
}
public AuditMode beforeExecution(AuditMode auditMode, String application, String description, NodeRef key, Object... args)
{
ApplicationAuditEntry aae = applications.get(application);
if (aae != null)
{
return aae.beforeExecution(auditMode, application, description, key, args);
}
else
{
if (s_logger.isDebugEnabled())
{
s_logger.debug("No specific audit entry for application " + application);
}
return getEffectiveAuditMode();
}
}
public AuditMode afterExecution(AuditMode auditMode, String application, String description, NodeRef key, Object... args)
{
throw new UnsupportedOperationException();
}
public AuditMode onError(AuditMode auditMode, String application, String description, NodeRef key, Object... args)
{
throw new UnsupportedOperationException();
}
public RecordOptions getAuditRecordOptions(String application)
{
ApplicationAuditEntry aae = applications.get(application);
if (aae != null)
{
return aae.getAuditRecordOptions(application);
}
else
{
if (s_logger.isDebugEnabled())
{
s_logger.debug("No specific audit entry for application " + application);
}
return getEffectiveRecordOptions();
}
}
public TrueFalseUnset getAuditInternalServiceMethods(MethodInvocation mi)
{
String serviceName = getPublicServiceIdentifier().getPublicServiceName(mi);
ServiceAuditEntry service = services.get(serviceName);
if (service != null)
{
MethodAuditEntry method = service.getMethodAuditEntry(mi.getMethod().getName());
if (method != null)
{
return method.getAuditInternalServiceMethods(mi);
}
else
{
return service.getAuditInternalServiceMethods(mi);
}
}
else
{
if (s_logger.isDebugEnabled())
{
s_logger.debug("No specific audit entry for service " + serviceName);
}
return getEffectiveAuditInternal();
}
}
}

View File

@@ -1,74 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.alfresco.repo.audit.AuditModel;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Attribute;
import org.dom4j.Element;
/**
* This groups a set of filters together using AND or OR. They are evaluated in definition order with short cut evaluation if possible. The default beahviour is to or Filters
* together.
*
* @author Andy Hind
*/
public class FilterSet extends AbstractFilter implements XMLModelElement
{
private static Log s_logger = LogFactory.getLog(FilterSet.class);
private List<AbstractFilter> filters = new ArrayList<AbstractFilter>();
private FilterSetMode mode = FilterSetMode.OR;
public FilterSet()
{
super();
}
@Override
public void configure(Element element, NamespacePrefixResolver namespacePrefixResolver)
{
super.configure(element, namespacePrefixResolver);
// Mode
Attribute modeAttribute = element.attribute(AuditModel.AT_MODE);
if (modeAttribute != null)
{
mode = FilterSetMode.getFilterSetMode(modeAttribute.getStringValue());
}
// Filters
for (Iterator nsit = element.elementIterator(AuditModel.EL_FILTER); nsit.hasNext(); /**/)
{
Element filterElement = (Element) nsit.next();
AbstractFilter filter = AbstractFilter.createFilter(filterElement, namespacePrefixResolver);
filters.add(filter);
}
}
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
/**
* The enum to define if elements of a filter set are combined using AND or OR.
*
* @author Andy Hind
*/
public enum FilterSetMode
{
AND, OR;
public static FilterSetMode getFilterSetMode(String value)
{
if(value.equalsIgnoreCase("or"))
{
return FilterSetMode.OR;
}
else if(value.equalsIgnoreCase("or"))
{
return FilterSetMode.AND;
}
else
{
throw new AuditModelException("Invalid FilterSetMode: "+value);
}
}
}

View File

@@ -1,72 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
import org.alfresco.repo.audit.AuditModel;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Attribute;
import org.dom4j.Element;
public class KeyFilter extends AbstractFilter
{
private static Log s_logger = LogFactory.getLog(KeyFilter.class);
private String expression;
private KeyFilterMode keyFilterMode;
public KeyFilter()
{
super();
}
@Override
public void configure(Element element, NamespacePrefixResolver namespacePrefixResolver)
{
super.configure(element, namespacePrefixResolver);
// Filter mode
Attribute keyFilterTypeAttribute = element.attribute(AuditModel.AT_MODE);
if(keyFilterTypeAttribute != null)
{
keyFilterMode = KeyFilterMode.getKeyFilterMode(keyFilterTypeAttribute.getStringValue());
}
else
{
keyFilterMode = KeyFilterMode.ALL;
}
// Expression
Element expressionElement = element.element(AuditModel.EL_EXPRESSION);
if(expressionElement == null)
{
throw new AuditModelException("An expression is mandatory for a key filter");
}
else
{
expression = expressionElement.getText();
}
}
}

View File

@@ -1,88 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
/**
* This enum defines the type of restriction to apply to filter based on the key node ref.
*
* This restriction can be based upon:
*
* <ol>
* <li> The path to the node
* <li> The type of the node
* <li> The presence of an aspect
* <li> The NodeRef of the node
* <li> An XPATH expression evaluated in the context of the node with the return tested for the node.
* e.g. ".[@cm:content = 'woof']"
* <li> A simple value for equality tests given a non node argument
* <li> The protocol of the store containing the node
* <li> The identifier of the store containing the node
* <li> Or no restriction
* </ol>
*
* @author Andy Hind
*/
public enum KeyFilterMode
{
PATH, TYPE, ASPECT, NODE_REF, ALL, XPATH, VALUE, STORE_PROTOCOL, STORE_IDENTIFIER;
public static KeyFilterMode getKeyFilterMode(String value)
{
if(value.equalsIgnoreCase("path"))
{
return KeyFilterMode.PATH;
}
else if(value.equalsIgnoreCase("type"))
{
return KeyFilterMode.TYPE;
}
else if(value.equalsIgnoreCase("aspect"))
{
return KeyFilterMode.ASPECT;
}
else if(value.equalsIgnoreCase("node_ref"))
{
return KeyFilterMode.NODE_REF;
}
else if(value.equalsIgnoreCase("all"))
{
return KeyFilterMode.ALL;
}
else if(value.equalsIgnoreCase("xpath"))
{
return KeyFilterMode.XPATH;
}
else if(value.equalsIgnoreCase("value"))
{
return KeyFilterMode.VALUE;
}
else if(value.equalsIgnoreCase("store_protocol"))
{
return KeyFilterMode.STORE_PROTOCOL;
}
else if(value.equalsIgnoreCase("store_identifier"))
{
return KeyFilterMode.STORE_IDENTIFIER;
}
else
{
throw new AuditModelException("Unknown KeyFilterMode: "+value);
}
}
}

View File

@@ -1,71 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
import org.alfresco.repo.audit.AuditMode;
import org.alfresco.repo.audit.MethodAuditModel;
import org.alfresco.repo.audit.RecordOptions;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MethodAuditEntry extends AbstractNamedAuditEntry implements MethodAuditModel
{
private static Log s_logger = LogFactory.getLog(MethodAuditEntry.class);
public MethodAuditEntry()
{
super();
// TODO Auto-generated constructor stub
}
public AuditMode beforeExecution(AuditMode auditMode, MethodInvocation mi)
{
if(s_logger.isDebugEnabled())
{
s_logger.debug("Evaluating if method is audited ..."+((ServiceAuditEntry)getParent()).getName()+"."+getName());
}
return getEffectiveAuditMode();
}
public AuditMode afterExecution(AuditMode auditMode, MethodInvocation mi)
{
throw new UnsupportedOperationException();
}
public AuditMode onError(AuditMode auditMode, MethodInvocation mi)
{
throw new UnsupportedOperationException();
}
public RecordOptions getAuditRecordOptions(MethodInvocation mi)
{
return getEffectiveRecordOptions();
}
public TrueFalseUnset getAuditInternalServiceMethods(MethodInvocation mi)
{
if(s_logger.isDebugEnabled())
{
s_logger.debug("Evaluating if method is internally audited ..."+((ServiceAuditEntry)getParent()).getName()+"."+getName());
}
return getEffectiveAuditInternal();
}
}

View File

@@ -1,64 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
import org.alfresco.repo.audit.AuditModel;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Element;
public class ParameterFilter extends KeyFilter implements XMLModelElement
{
private static Log s_logger = LogFactory.getLog(ParameterFilter.class);
private QName parameterName;
public ParameterFilter()
{
super();
}
@Override
public void configure(Element element, NamespacePrefixResolver namespacePrefixResolver)
{
super.configure(element, namespacePrefixResolver);
Element parameterNameElement = element.element(AuditModel.EL_PARAMETER_NAME);
if(parameterNameElement == null)
{
throw new AuditModelException("A parameter is mandatory for a parameter filter");
}
else
{
String stringQName = parameterNameElement.getStringValue();
if (stringQName.charAt(1) == '{')
{
parameterName = QName.createQName(stringQName);
}
else
{
parameterName = QName.createQName(stringQName);
}
}
}
}

View File

@@ -1,191 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
import org.alfresco.repo.audit.AuditModel;
import org.alfresco.repo.audit.RecordOptions;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Element;
public class RecordOptionsImpl implements XMLModelElement, RecordOptions
{
private static Log s_logger = LogFactory.getLog(RecordOptionsImpl.class);
private TrueFalseUnset recordPath = TrueFalseUnset.UNSET;
private TrueFalseUnset recordFilters = TrueFalseUnset.UNSET;
private TrueFalseUnset recordSerializedReturnValue = TrueFalseUnset.UNSET;
private TrueFalseUnset recordSerializedExceptions = TrueFalseUnset.UNSET;
private TrueFalseUnset recordSerializedMethodArguments = TrueFalseUnset.UNSET;
private TrueFalseUnset recordSerializedKeyPropertiesBeforeEvaluation = TrueFalseUnset.UNSET;
private TrueFalseUnset recordSerializedKeyPropertiesAfterEvaluation = TrueFalseUnset.UNSET;
public RecordOptionsImpl()
{
super();
}
public static RecordOptionsImpl mergeRecordOptions(RecordOptions primary, RecordOptions secondary)
{
RecordOptionsImpl answer = new RecordOptionsImpl();
setOptions(answer, primary, true);
setOptions(answer, secondary, false);
return answer;
}
private static void setOptions(RecordOptionsImpl on, RecordOptions from, boolean force)
{
if(force || on.recordFilters.equals( TrueFalseUnset.UNSET))
{
on.recordFilters = from.getRecordFilters();
}
if(force || on.recordPath.equals( TrueFalseUnset.UNSET))
{
on.recordPath = from.getRecordPath();
}
if(force || on.recordSerializedExceptions.equals( TrueFalseUnset.UNSET))
{
on.recordSerializedExceptions = from.getRecordSerializedExceptions();
}
if(force || on.recordSerializedKeyPropertiesAfterEvaluation.equals( TrueFalseUnset.UNSET))
{
on.recordSerializedKeyPropertiesAfterEvaluation = from.getRecordSerializedKeyPropertiesAfterEvaluation();
}
if(force || on.recordSerializedKeyPropertiesBeforeEvaluation.equals( TrueFalseUnset.UNSET))
{
on.recordSerializedKeyPropertiesBeforeEvaluation = from.getRecordSerializedKeyPropertiesBeforeEvaluation();
}
if(force || on.recordSerializedMethodArguments.equals( TrueFalseUnset.UNSET))
{
on.recordSerializedMethodArguments = from.getRecordSerializedMethodArguments();
}
if(force || on.recordSerializedReturnValue.equals( TrueFalseUnset.UNSET))
{
on.recordSerializedReturnValue = from.getRecordSerializedReturnValue();
}
}
public TrueFalseUnset getRecordFilters()
{
return recordFilters;
}
public TrueFalseUnset getRecordPath()
{
return recordPath;
}
public TrueFalseUnset getRecordSerializedExceptions()
{
return recordSerializedExceptions;
}
public TrueFalseUnset getRecordSerializedKeyPropertiesAfterEvaluation()
{
return recordSerializedKeyPropertiesAfterEvaluation;
}
public TrueFalseUnset getRecordSerializedKeyPropertiesBeforeEvaluation()
{
return recordSerializedKeyPropertiesBeforeEvaluation;
}
public TrueFalseUnset getRecordSerializedMethodArguments()
{
return recordSerializedMethodArguments;
}
public TrueFalseUnset getRecordSerializedReturnValue()
{
return recordSerializedReturnValue;
}
public void configure(Element recordOptionElement, NamespacePrefixResolver namespacePrefixResolver)
{
Element recordFiltersElement = recordOptionElement.element(AuditModel.EL_RECORD_FILTERS);
if (recordFiltersElement != null)
{
recordFilters = TrueFalseUnset.getTrueFalseUnset(recordFiltersElement.getStringValue());
}
Element recordPathElement = recordOptionElement.element(AuditModel.EL_RECORD_PATH);
if (recordPathElement != null)
{
recordPath = TrueFalseUnset.getTrueFalseUnset(recordPathElement.getStringValue());
}
Element recordSerAgrsElement = recordOptionElement.element(AuditModel.EL_RECORD_SER_ARGS);
if (recordSerAgrsElement != null)
{
recordSerializedMethodArguments = TrueFalseUnset.getTrueFalseUnset(recordSerAgrsElement.getStringValue());
}
Element recordSerExElement = recordOptionElement.element(AuditModel.EL_RECORD_SER_EX);
if (recordSerExElement != null)
{
recordSerializedExceptions = TrueFalseUnset.getTrueFalseUnset(recordSerExElement.getStringValue());
}
Element recordSerPropAfterElement = recordOptionElement.element(AuditModel.EL_RECORD_SER_PROP_AFTER);
if (recordSerPropAfterElement != null)
{
recordSerializedKeyPropertiesAfterEvaluation = TrueFalseUnset.getTrueFalseUnset(recordSerPropAfterElement
.getStringValue());
}
Element recordSerPropBeforeElement = recordOptionElement.element(AuditModel.EL_RECORD_SER_PROP_BEFORE);
if (recordSerPropBeforeElement != null)
{
recordSerializedKeyPropertiesBeforeEvaluation = TrueFalseUnset.getTrueFalseUnset(recordSerPropBeforeElement
.getStringValue());
}
Element recordSerRetElement = recordOptionElement.element(AuditModel.EL_RECORD_SER_RETURN_VAL);
if (recordSerRetElement != null)
{
recordSerializedReturnValue = TrueFalseUnset.getTrueFalseUnset(recordSerRetElement.getStringValue());
}
}
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
builder.append("Record Options(");
builder.append("Filters=").append(getRecordFilters());
builder.append(",Path=").append(getRecordPath());
builder.append(",Exception=").append(getRecordSerializedExceptions());
builder.append(",PropertiesBefore=").append(getRecordSerializedKeyPropertiesAfterEvaluation());
builder.append(",PropertiesAfter=").append(getRecordSerializedKeyPropertiesBeforeEvaluation());
builder.append(",Args=").append(getRecordSerializedMethodArguments());
builder.append(",Return=").append(getRecordSerializedReturnValue());
builder.append(")");
return builder.toString();
}
}

View File

@@ -1,126 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.alfresco.repo.audit.AuditMode;
import org.alfresco.repo.audit.AuditModel;
import org.alfresco.repo.audit.MethodAuditModel;
import org.alfresco.repo.audit.RecordOptions;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Element;
public class ServiceAuditEntry extends AbstractNamedAuditEntry implements MethodAuditModel
{
private static Log s_logger = LogFactory.getLog(ServiceAuditEntry.class);
private Map<String, MethodAuditEntry> methods = new HashMap<String, MethodAuditEntry>();
public ServiceAuditEntry()
{
super();
}
@Override
void configure(AbstractAuditEntry parent, Element element, NamespacePrefixResolver namespacePrefixResolver)
{
super.configure(parent, element, namespacePrefixResolver);
// Add Methods
if (s_logger.isDebugEnabled())
{
s_logger.debug("Adding methods to service " + getName());
}
for (Iterator nsit = element.elementIterator(AuditModel.EL_METHOD); nsit.hasNext(); /**/)
{
Element methodElement = (Element) nsit.next();
MethodAuditEntry method = new MethodAuditEntry();
method.configure(this, methodElement, namespacePrefixResolver);
methods.put(method.getName(), method);
}
if (s_logger.isDebugEnabled())
{
s_logger.debug("...added methods for service " + getName());
}
}
public AuditMode beforeExecution(AuditMode auditMode, MethodInvocation mi)
{
String methodName = mi.getMethod().getName();
MethodAuditEntry method = methods.get(methodName);
if (method != null)
{
return method.beforeExecution(auditMode, mi);
}
else
{
if (s_logger.isDebugEnabled())
{
s_logger.debug("Evaluating if service is audited (no specific setting) for " + getName() + "." + methodName);
}
return getEffectiveAuditMode();
}
}
public AuditMode afterExecution(AuditMode auditMode, MethodInvocation mi)
{
throw new UnsupportedOperationException();
}
public AuditMode onError(AuditMode auditMode, MethodInvocation mi)
{
throw new UnsupportedOperationException();
}
public RecordOptions getAuditRecordOptions(MethodInvocation mi)
{
return getEffectiveRecordOptions();
}
public TrueFalseUnset getAuditInternalServiceMethods(MethodInvocation mi)
{
String methodName = mi.getMethod().getName();
MethodAuditEntry method = methods.get(methodName);
if (method != null)
{
return method.getAuditInternalServiceMethods(mi);
}
else
{
if (s_logger.isDebugEnabled())
{
s_logger.debug("Evaluating if service is internally audited (no specific setting) for " + getName() + "." + methodName);
}
return getEffectiveAuditInternal();
}
}
public MethodAuditEntry getMethodAuditEntry(String name)
{
return methods.get(name);
}
}

View File

@@ -1,54 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
/**
* An enum for the values
* <ol>
* <li> TRUE
* <li> FALSE
* <li> UNSET
* </ol>
*
* @author Andy Hind
*/
public enum TrueFalseUnset
{
TRUE, FALSE, UNSET;
public static TrueFalseUnset getTrueFalseUnset(String value)
{
if(value.equalsIgnoreCase("true"))
{
return TrueFalseUnset.TRUE;
}
else if(value.equalsIgnoreCase("false"))
{
return TrueFalseUnset.FALSE;
}
else if(value.equalsIgnoreCase("unset"))
{
return TrueFalseUnset.UNSET;
}
else
{
throw new AuditModelException("Invalid value for TrueFalseUnset: "+value);
}
}
}

View File

@@ -1,27 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.audit.model;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.dom4j.Element;
public interface XMLModelElement
{
void configure(Element element, NamespacePrefixResolver namespacePrefixResolver );
}