mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Audit log clearing and related tests
- RM start(), stop() and clear() implemented git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16276 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
<typeAlias alias="AuditModel" type="org.alfresco.repo.domain.audit.AuditModelEntity"/>
|
||||
<typeAlias alias="AuditApplication" type="org.alfresco.repo.domain.audit.AuditApplicationEntity"/>
|
||||
<typeAlias alias="AuditEntry" type="org.alfresco.repo.domain.audit.AuditEntryEntity"/>
|
||||
<typeAlias alias="AuditDeleteParameters" type="org.alfresco.repo.domain.audit.AuditDeleteParameters"/>
|
||||
<typeAlias alias="AuditQueryParameters" type="org.alfresco.repo.domain.audit.AuditQueryParameters"/>
|
||||
<typeAlias alias="AuditQueryResult" type="org.alfresco.repo.domain.audit.AuditQueryResult"/>
|
||||
|
||||
@@ -135,6 +136,21 @@
|
||||
version = (#version# -1)
|
||||
</update>
|
||||
|
||||
<!-- TODO: This has to be replaced with two deletes; one for the property links and another for the entries -->
|
||||
<delete id="delete_AuditEntries" parameterClass="AuditDeleteParameters">
|
||||
delete
|
||||
from
|
||||
alf_audit_entry
|
||||
where
|
||||
audit_app_id = #auditApplicationId#
|
||||
<isNotNull property="auditFromTime">
|
||||
<![CDATA[and audit_time >= #auditFromTime#]]>
|
||||
</isNotNull>
|
||||
<isNotNull property="auditFromTime">
|
||||
<![CDATA[and audit_time < #auditToTime#]]>
|
||||
</isNotNull>
|
||||
</delete>
|
||||
|
||||
<!-- Get audit entries -->
|
||||
<select id="select_AuditEntriesWithValues" parameterClass="AuditQueryParameters" resultMap="result_AuditQueryAllValues">
|
||||
select
|
||||
|
@@ -84,6 +84,30 @@ public interface AuditComponent
|
||||
* V3.2 from here on. Put all fixes to the older audit code before this point, please.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Delete audit entries for the given application and time range
|
||||
*
|
||||
* @param applicationName the name of the application being logged to
|
||||
* @param fromTime the start time of entries to remove (inclusive and optional)
|
||||
* @param toTime the end time of entries to remove (exclusive and optional)
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
void deleteAuditEntries(String applicationName, Long fromTime, Long toTime);
|
||||
|
||||
/**
|
||||
* Check if an audit path is disabled. The path will be disabled if it or any higher
|
||||
* path has been explicitly disabled. Any disabled path will not be processed when
|
||||
* data is audited.
|
||||
*
|
||||
* @param applicationName the name of the application being logged to
|
||||
* @param path the audit path to check
|
||||
* @return Returns <tt>true</tt> if the audit path has been disabled
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
boolean isAuditPathDisabled(String applicationName, String path);
|
||||
|
||||
/**
|
||||
* Enable auditing (if it is not already enabled) for all paths that contain the given path.
|
||||
* The path is the path as originally logged (see {@link #audit(String, String, Map)}) and
|
||||
|
@@ -782,7 +782,40 @@ public class AuditComponentImpl implements AuditComponent
|
||||
{
|
||||
this.propertyValueDAO = propertyValueDAO;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 3.2
|
||||
*/
|
||||
public void deleteAuditEntries(String applicationName, Long fromTime, Long toTime)
|
||||
{
|
||||
ParameterCheck.mandatory("applicationName", applicationName);
|
||||
|
||||
if (AlfrescoTransactionSupport.getTransactionReadState() == TxnReadState.TXN_NONE)
|
||||
{
|
||||
throw new IllegalStateException("Auditing requires a read transaction.");
|
||||
}
|
||||
|
||||
AuditApplication application = auditModelRegistry.getAuditApplication(applicationName);
|
||||
if (application == null)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("No audit application named '" + applicationName + "' has been registered.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Long applicationId = application.getApplicationId();
|
||||
|
||||
auditDAO.deleteAuditEntries(applicationId, fromTime, toTime);
|
||||
// Done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Delete audit entries for " + applicationName + " (" + fromTime + " to " + toTime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param application the audit application object
|
||||
* @return Returns a copy of the set of disabled paths associated with the application
|
||||
@@ -804,6 +837,56 @@ public class AuditComponentImpl implements AuditComponent
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 3.2
|
||||
*/
|
||||
public boolean isAuditPathDisabled(String applicationName, String path)
|
||||
{
|
||||
ParameterCheck.mandatory("applicationName", applicationName);
|
||||
ParameterCheck.mandatory("path", path);
|
||||
|
||||
if (AlfrescoTransactionSupport.getTransactionReadState() == TxnReadState.TXN_NONE)
|
||||
{
|
||||
throw new IllegalStateException("Auditing requires a read transaction.");
|
||||
}
|
||||
|
||||
AuditApplication application = auditModelRegistry.getAuditApplication(applicationName);
|
||||
if (application == null)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("No audit application named '" + applicationName + "' has been registered.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Check the path against the application
|
||||
application.checkPath(path);
|
||||
|
||||
Set<String> disabledPaths = getDisabledPaths(application);
|
||||
|
||||
// Check if there are any entries that match or superced the given path
|
||||
String disablingPath = null;;
|
||||
for (String disabledPath : disabledPaths)
|
||||
{
|
||||
if (path.startsWith(disabledPath))
|
||||
{
|
||||
disablingPath = disabledPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(
|
||||
"Audit disable check: \n" +
|
||||
" Application: " + applicationName + "\n" +
|
||||
" Path: " + path + "\n" +
|
||||
" Disabling Path: " + disablingPath);
|
||||
}
|
||||
return disablingPath != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 3.2
|
||||
|
@@ -128,6 +128,44 @@ public class AuditServiceImpl implements AuditService
|
||||
* V3.2 from here on. Put all fixes to the older audit code before this point, please.
|
||||
*/
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 3.2
|
||||
*/
|
||||
public boolean isAuditEnabled(String applicationName, String path)
|
||||
{
|
||||
// Get the root path for the application
|
||||
return auditComponent.isAuditPathDisabled(applicationName, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 3.2
|
||||
*/
|
||||
public void enableAudit(String applicationName, String path)
|
||||
{
|
||||
auditComponent.enableAudit(applicationName, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 3.2
|
||||
*/
|
||||
public void disableAudit(String applicationName, String path)
|
||||
{
|
||||
auditComponent.disableAudit(applicationName, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 3.2
|
||||
*/
|
||||
public void clearAudit(String applicationName)
|
||||
{
|
||||
Long now = Long.valueOf(System.currentTimeMillis());
|
||||
auditComponent.deleteAuditEntries(applicationName, null, now);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 3.2
|
||||
|
@@ -710,6 +710,17 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fallout implementation from new audit DAO
|
||||
*
|
||||
* @throws UnsupportedOperationException always
|
||||
* @since 3.2
|
||||
*/
|
||||
public void deleteAuditEntries(Long applicationId, Long from, Long to)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fallout implementation from new audit DAO
|
||||
*
|
||||
|
@@ -133,6 +133,7 @@ public interface AuditDAO
|
||||
* @param the URL of the configuration
|
||||
* @return Returns the ID of the config matching the input stream and the
|
||||
* content storage details
|
||||
* @since 3.2
|
||||
*/
|
||||
Pair<Long, ContentData> getOrCreateAuditModel(URL url);
|
||||
|
||||
@@ -141,6 +142,8 @@ public interface AuditDAO
|
||||
*
|
||||
* @param applicationName the name of the application
|
||||
* @return Returns details of an existing application or <tt>null</tt> if it doesn't exist
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
AuditApplicationInfo getAuditApplication(String applicationName);
|
||||
|
||||
@@ -149,6 +152,8 @@ public interface AuditDAO
|
||||
*
|
||||
* @param application the name of the application
|
||||
* @param modelId the ID of the model configuration
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
AuditApplicationInfo createAuditApplication(String application, Long modelId);
|
||||
|
||||
@@ -158,6 +163,8 @@ public interface AuditDAO
|
||||
*
|
||||
* @param id the ID of the audit application
|
||||
* @param modelId the ID of the new model
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
void updateAuditApplicationModel(Long id, Long modelId);
|
||||
|
||||
@@ -167,24 +174,59 @@ public interface AuditDAO
|
||||
*
|
||||
* @param id the ID of the audit application
|
||||
* @param disabledPaths the new disabled paths
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
void updateAuditApplicationDisabledPaths(Long id, Set<String> disabledPaths);
|
||||
|
||||
/**
|
||||
* Delete audit entries for the application, possibly limiting the time range.
|
||||
*
|
||||
* @param applicationId and existing audit application ID
|
||||
* @param from the minimum entry time (inclusive, optional)
|
||||
* @param to the maximum entry time (exclusive, optional)
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
void deleteAuditEntries(Long applicationId, Long from, Long to);
|
||||
|
||||
/**
|
||||
* Create a new audit entry with the given map of values.
|
||||
*
|
||||
* @param applicationId an existing audit application ID
|
||||
* @param time the time (ms since epoch) to log the entry against
|
||||
* @param username the authenticated user (<tt>null</tt> if not present)
|
||||
* @param values the values to record
|
||||
* @return Returns the unique entry ID
|
||||
* @param applicationId an existing audit application ID
|
||||
* @param time the time (ms since epoch) to log the entry against
|
||||
* @param username the authenticated user (<tt>null</tt> if not present)
|
||||
* @param values the values to record
|
||||
* @return Returns the unique entry ID
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
Long createAuditEntry(Long applicationId, long time, String username, Map<String, Serializable> values);
|
||||
|
||||
/**
|
||||
* Find audit entries using the given parameters, any of which may be null
|
||||
*
|
||||
* @param callback the data callback per entry
|
||||
* @param applicationName the name of the application to search against (optional)
|
||||
* @param user the user to search for (optional)
|
||||
* @param from the minimum entry time (optional)
|
||||
* @param to the maximum entry time (optional)
|
||||
* @param maxResults the maximum number of results to retrieve
|
||||
*/
|
||||
void findAuditEntries(
|
||||
AuditQueryCallback callback,
|
||||
String applicationName, String user, Long from, Long to, int maxResults);
|
||||
|
||||
/**
|
||||
* Find audit entries using the given parameters, any of which may be null.
|
||||
*
|
||||
* @param searchKey the audit path key to search for (optional)
|
||||
* @param searchString the audit string value to search for (optional)
|
||||
*
|
||||
* @see #findAuditEntries(AuditQueryCallback, String, String, Long, Long, int)
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
void findAuditEntries(
|
||||
AuditQueryCallback callback,
|
||||
String applicationName, String user, Long from, Long to,
|
||||
|
@@ -90,7 +90,7 @@ public class AuditDAOTest extends TestCase
|
||||
assertEquals(configPair, configPairCheck);
|
||||
}
|
||||
|
||||
public void testAuditApplicatoin() throws Exception
|
||||
public void testAuditApplication() throws Exception
|
||||
{
|
||||
final File file = AbstractContentTransformerTest.loadQuickTestFile("pdf");
|
||||
assertNotNull(file);
|
||||
@@ -187,7 +187,7 @@ public class AuditDAOTest extends TestCase
|
||||
// Some entries
|
||||
doAuditEntryImpl(1);
|
||||
|
||||
// Find everything, bug look for a specific key
|
||||
// Find everything, but look for a specific key
|
||||
final AuditQueryCallback callback = new AuditQueryCallback()
|
||||
{
|
||||
public boolean handleAuditEntry(
|
||||
@@ -212,4 +212,37 @@ public class AuditDAOTest extends TestCase
|
||||
};
|
||||
txnHelper.doInTransaction(findCallback);
|
||||
}
|
||||
|
||||
public void testAuditDeleteEntries() throws Exception
|
||||
{
|
||||
final AuditQueryCallback noResultsCallback = new AuditQueryCallback()
|
||||
{
|
||||
public boolean handleAuditEntry(
|
||||
Long entryId,
|
||||
String applicationName,
|
||||
String user,
|
||||
long time,
|
||||
Map<String, Serializable> values)
|
||||
{
|
||||
fail("Expected no results. All entries should have been removed.");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Some entries
|
||||
final String appName = doAuditEntryImpl(1);
|
||||
// Delete the entries
|
||||
RetryingTransactionCallback<Void> deletedCallback = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
Long appId = auditDAO.getAuditApplication(appName).getId();
|
||||
auditDAO.deleteAuditEntries(appId, null, null);
|
||||
// There should be no entries
|
||||
auditDAO.findAuditEntries(noResultsCallback, appName, null, null, null, -1);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
txnHelper.doInTransaction(deletedCallback);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program 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 General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.domain.audit;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Deletion parameters for <b>alf_audit_entry</b> table.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
* @since 3.2
|
||||
*/
|
||||
public class AuditDeleteParameters
|
||||
{
|
||||
private Long auditApplicationId;
|
||||
private Long auditFromTime;
|
||||
private Long auditToTime;
|
||||
|
||||
public AuditDeleteParameters()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(512);
|
||||
sb.append("AuditDeleteParameters")
|
||||
.append("[ auditApplicationId=").append(auditApplicationId)
|
||||
.append(", auditFromTime").append(auditFromTime == null ? null : new Date(auditFromTime))
|
||||
.append(", auditToTime").append(auditToTime == null ? null : new Date(auditToTime))
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Long getAuditApplicationId()
|
||||
{
|
||||
return auditApplicationId;
|
||||
}
|
||||
|
||||
public void setAuditApplicationId(Long auditApplicationId)
|
||||
{
|
||||
this.auditApplicationId = auditApplicationId;
|
||||
}
|
||||
|
||||
public Long getAuditFromTime()
|
||||
{
|
||||
return auditFromTime;
|
||||
}
|
||||
|
||||
public void setAuditFromTime(Long auditFromTime)
|
||||
{
|
||||
this.auditFromTime = auditFromTime;
|
||||
}
|
||||
|
||||
public Long getAuditToTime()
|
||||
{
|
||||
return auditToTime;
|
||||
}
|
||||
|
||||
public void setAuditToTime(Long auditToTime)
|
||||
{
|
||||
this.auditToTime = auditToTime;
|
||||
}
|
||||
}
|
@@ -56,8 +56,8 @@ public class AuditQueryParameters
|
||||
.append("[ auditEntryId=").append(auditEntryId)
|
||||
.append(", auditAppNameCrcPair=").append(auditAppNameCrcPair)
|
||||
.append(", auditUserCrcPair=").append(auditUserCrcPair)
|
||||
.append(", auditFromTime").append(new Date(auditFromTime))
|
||||
.append(", auditToTime").append(new Date(auditToTime))
|
||||
.append(", auditFromTime").append(auditFromTime == null ? null : new Date(auditFromTime))
|
||||
.append(", auditToTime").append(auditToTime == null ? null : new Date(auditToTime))
|
||||
.append(", searchKey").append(searchKey)
|
||||
.append(", searchValueString").append(searchValueString)
|
||||
.append("]");
|
||||
|
@@ -32,6 +32,7 @@ import java.util.Map;
|
||||
import org.alfresco.ibatis.RollupRowHandler;
|
||||
import org.alfresco.repo.domain.audit.AbstractAuditDAOImpl;
|
||||
import org.alfresco.repo.domain.audit.AuditApplicationEntity;
|
||||
import org.alfresco.repo.domain.audit.AuditDeleteParameters;
|
||||
import org.alfresco.repo.domain.audit.AuditEntryEntity;
|
||||
import org.alfresco.repo.domain.audit.AuditModelEntity;
|
||||
import org.alfresco.repo.domain.audit.AuditQueryParameters;
|
||||
@@ -57,6 +58,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
|
||||
private static final String INSERT_APPLICATION = "alfresco.audit.insert_AuditApplication";
|
||||
private static final String UPDATE_APPLICATION = "alfresco.audit.update_AuditApplication";
|
||||
|
||||
private static final String DELETE_ENTRIES = "alfresco.audit.delete_AuditEntries";
|
||||
private static final String INSERT_ENTRY = "alfresco.audit.insert_AuditEntry";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -162,6 +164,15 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
|
||||
return updateEntity;
|
||||
}
|
||||
|
||||
public void deleteAuditEntries(Long applicationId, Long from, Long to)
|
||||
{
|
||||
AuditDeleteParameters params = new AuditDeleteParameters();
|
||||
params.setAuditApplicationId(applicationId);
|
||||
params.setAuditFromTime(from);
|
||||
params.setAuditToTime(to);
|
||||
template.delete(DELETE_ENTRIES, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuditEntryEntity createAuditEntry(Long applicationId, long time, Long usernameId, Long valuesId)
|
||||
{
|
||||
|
@@ -107,8 +107,47 @@ public interface AuditService
|
||||
* V3.2 from here on. Put all fixes to the older audit code before this point, please.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param applicationName the name of the application to check
|
||||
* @param path the path to check
|
||||
* @return Returns <tt>true</tt> if auditing is enabled for the given path
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
boolean isAuditEnabled(String applicationName, String path);
|
||||
|
||||
/**
|
||||
* Enable auditing for an application path
|
||||
*
|
||||
* @param applicationName the name of the application to check
|
||||
* @param path the path to enable
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
void enableAudit(String applicationName, String path);
|
||||
|
||||
/**
|
||||
* Disable auditing for an application path
|
||||
*
|
||||
* @param applicationName the name of the application to check
|
||||
* @param path the path to disable
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
void disableAudit(String applicationName, String path);
|
||||
|
||||
/**
|
||||
* Remove all audit entries for the given application
|
||||
*
|
||||
* @param applicationName the name of the application for which to remove entries
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
void clearAudit(String applicationName);
|
||||
|
||||
/**
|
||||
* The interface that will be used to give query results to the calling code.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public static interface AuditQueryCallback
|
||||
@@ -140,6 +179,8 @@ public interface AuditService
|
||||
* @param from the start search time (<tt>null</tt> to start at the beginning)
|
||||
* @param to the end search time (<tt>null</tt> for no limit)
|
||||
* @param maxResults the maximum number of results to retrieve (zero or negative to ignore)
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
void auditQuery(
|
||||
AuditQueryCallback callback,
|
||||
@@ -157,6 +198,8 @@ public interface AuditService
|
||||
* @param searchKey the audit key path that must exist (<tt>null</tt> to ignore)
|
||||
* @param searchString an audit value string that must exist (<tt>null</tt> to ignore)
|
||||
* @param maxResults the maximum number of results to retrieve (zero or negative to ignore)
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
void auditQuery(
|
||||
AuditQueryCallback callback,
|
||||
|
Reference in New Issue
Block a user