mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Audit - working without filters
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3646 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc. Licensed under the Mozilla Public License version 1.1 with a permitted attribution clause. You may obtain a copy of the License at
|
||||
* http://www.alfresco.org/legal/license.txt Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
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.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;
|
||||
}
|
||||
|
||||
/* package */TrueFalseUnset getEnabled()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/* package */AbstractFilter getFilter()
|
||||
{
|
||||
return filter;
|
||||
}
|
||||
|
||||
/* package */AbstractAuditEntry getParent()
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
/* package */RecordOptionsImpl getRecordOptions()
|
||||
{
|
||||
return recordOptions;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
}
|
220
source/java/org/alfresco/repo/audit/model/AuditEntry.java
Normal file
220
source/java/org/alfresco/repo/audit/model/AuditEntry.java
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public AuditMode onError(AuditMode auditMode, MethodInvocation mi)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private Document createDocument()
|
||||
{
|
||||
InputStream 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);
|
||||
is.close();
|
||||
return document;
|
||||
}
|
||||
catch (DocumentException e)
|
||||
{
|
||||
throw new AuditModelException("Failed to create audit model document ", e);
|
||||
}
|
||||
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)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.audit.model;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
|
||||
/**
|
||||
* Exceptions from the audit model package.
|
||||
*
|
||||
* @author Andy Hind
|
||||
*/
|
||||
public class AuditModelException extends AlfrescoRuntimeException
|
||||
{
|
||||
|
||||
/**
|
||||
* Comment for <code>serialVersionUID</code>
|
||||
*/
|
||||
private static final long serialVersionUID = -2527034441058184109L;
|
||||
|
||||
public AuditModelException(String msgId)
|
||||
{
|
||||
super(msgId);
|
||||
}
|
||||
|
||||
public AuditModelException(String msgId, Object[] msgParams)
|
||||
{
|
||||
super(msgId, msgParams);
|
||||
}
|
||||
|
||||
public AuditModelException(String msgId, Throwable cause)
|
||||
{
|
||||
super(msgId, cause);
|
||||
}
|
||||
|
||||
public AuditModelException(String msgId, Object[] msgParams, Throwable cause)
|
||||
{
|
||||
super(msgId, msgParams, cause);
|
||||
}
|
||||
|
||||
}
|
72
source/java/org/alfresco/repo/audit/model/FilterSet.java
Normal file
72
source/java/org/alfresco/repo/audit/model/FilterSet.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
43
source/java/org/alfresco/repo/audit/model/FilterSetMode.java
Normal file
43
source/java/org/alfresco/repo/audit/model/FilterSetMode.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
70
source/java/org/alfresco/repo/audit/model/KeyFilter.java
Normal file
70
source/java/org/alfresco/repo/audit/model/KeyFilter.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
86
source/java/org/alfresco/repo/audit/model/KeyFilterMode.java
Normal file
86
source/java/org/alfresco/repo/audit/model/KeyFilterMode.java
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.audit.model;
|
||||
|
||||
import org.alfresco.repo.audit.AuditMode;
|
||||
import org.alfresco.repo.audit.MethodAuditModel;
|
||||
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 RecordOptionsImpl getAuditRecordOptions(MethodInvocation mi)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
189
source/java/org/alfresco/repo/audit/model/RecordOptionsImpl.java
Normal file
189
source/java/org/alfresco/repo/audit/model/RecordOptionsImpl.java
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
100
source/java/org/alfresco/repo/audit/model/ServiceAuditEntry.java
Normal file
100
source/java/org/alfresco/repo/audit/model/ServiceAuditEntry.java
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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.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 RecordOptionsImpl getAuditRecordOptions(MethodInvocation mi)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
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 );
|
||||
}
|
Reference in New Issue
Block a user