mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Added APi to get the audit trail.
Fixes for persistence and simple test. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3668 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -181,7 +181,7 @@ public class AuditComponentImpl implements AuditComponent
|
||||
*/
|
||||
public Object auditImpl(MethodInvocation mi) throws Throwable
|
||||
{
|
||||
AuditInfo auditInfo = new AuditInfo(auditConfiguration);
|
||||
AuditState auditInfo = new AuditState(auditConfiguration);
|
||||
// RecordOptions recordOptions = auditModel.getAuditRecordOptions(mi);
|
||||
AuditMode auditMode = AuditMode.UNSET;
|
||||
try
|
||||
@@ -221,7 +221,7 @@ public class AuditComponentImpl implements AuditComponent
|
||||
* @param t
|
||||
* @return
|
||||
*/
|
||||
private AuditMode onError(AuditMode auditMode, AuditInfo auditInfo, MethodInvocation mi, Throwable t)
|
||||
private AuditMode onError(AuditMode auditMode, AuditState auditInfo, MethodInvocation mi, Throwable t)
|
||||
{
|
||||
if ((auditMode == AuditMode.ALL) || (auditMode == AuditMode.FAIL))
|
||||
{
|
||||
@@ -241,7 +241,8 @@ public class AuditComponentImpl implements AuditComponent
|
||||
* @param returnObject
|
||||
* @return
|
||||
*/
|
||||
private AuditMode postInvocation(AuditMode auditMode, AuditInfo auditInfo, MethodInvocation mi, Object returnObject)
|
||||
private AuditMode postInvocation(AuditMode auditMode, AuditState auditInfo, MethodInvocation mi,
|
||||
Object returnObject)
|
||||
{
|
||||
if (returnObject == null)
|
||||
{
|
||||
@@ -255,6 +256,18 @@ public class AuditComponentImpl implements AuditComponent
|
||||
{
|
||||
auditInfo.setReturnObject(returnObject.toString());
|
||||
}
|
||||
|
||||
Auditable auditable = mi.getMethod().getAnnotation(Auditable.class);
|
||||
if (auditable.key() == Auditable.Key.RETURN)
|
||||
{
|
||||
if ((returnObject != null) && (returnObject instanceof NodeRef))
|
||||
{
|
||||
NodeRef key = (NodeRef) returnObject;
|
||||
auditInfo.setKeyStore(key.getStoreRef());
|
||||
auditInfo.setKeyGUID(key.getId());
|
||||
}
|
||||
}
|
||||
|
||||
return auditMode;
|
||||
}
|
||||
|
||||
@@ -266,7 +279,7 @@ public class AuditComponentImpl implements AuditComponent
|
||||
* @param mi
|
||||
* @return
|
||||
*/
|
||||
private AuditMode beforeInvocation(AuditMode auditMode, AuditInfo auditInfo, MethodInvocation mi)
|
||||
private AuditMode beforeInvocation(AuditMode auditMode, AuditState auditInfo, MethodInvocation mi)
|
||||
{
|
||||
AuditMode effectiveAuditMode = auditModel.beforeExecution(auditMode, mi);
|
||||
|
||||
@@ -283,10 +296,51 @@ public class AuditComponentImpl implements AuditComponent
|
||||
auditInfo.setFail(false);
|
||||
auditInfo.setFiltered(false);
|
||||
auditInfo.setHostAddress(auditHost);
|
||||
auditInfo.setKeyGUID(null);
|
||||
Auditable auditable = mi.getMethod().getAnnotation(Auditable.class);
|
||||
Object key = null;
|
||||
switch (auditable.key())
|
||||
{
|
||||
case ARG_0:
|
||||
key = mi.getArguments()[0];
|
||||
break;
|
||||
case ARG_1:
|
||||
key = mi.getArguments()[1];
|
||||
break;
|
||||
case ARG_2:
|
||||
key = mi.getArguments()[2];
|
||||
break;
|
||||
case ARG_3:
|
||||
key = mi.getArguments()[3];
|
||||
break;
|
||||
case ARG_4:
|
||||
key = mi.getArguments()[4];
|
||||
break;
|
||||
case ARG_5:
|
||||
key = mi.getArguments()[5];
|
||||
break;
|
||||
case ARG_6:
|
||||
key = mi.getArguments()[6];
|
||||
break;
|
||||
case ARG_7:
|
||||
key = mi.getArguments()[7];
|
||||
break;
|
||||
case ARG_8:
|
||||
key = mi.getArguments()[8];
|
||||
break;
|
||||
case ARG_9:
|
||||
key = mi.getArguments()[9];
|
||||
break;
|
||||
case NO_KEY:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if ((key != null) && (key instanceof NodeRef))
|
||||
{
|
||||
auditInfo.setKeyStore(((NodeRef) key).getStoreRef());
|
||||
auditInfo.setKeyGUID(((NodeRef) key).getId());
|
||||
}
|
||||
auditInfo.setKeyPropertiesAfter(null);
|
||||
auditInfo.setKeyPropertiesBefore(null);
|
||||
auditInfo.setKeyStore(null);
|
||||
auditInfo.setMessage(null);
|
||||
if (mi.getArguments() != null)
|
||||
{
|
||||
@@ -322,9 +376,9 @@ public class AuditComponentImpl implements AuditComponent
|
||||
/**
|
||||
* A simple audit entry Currently we ignore filtering here.
|
||||
*/
|
||||
public void audit(String source, String description, NodeRef key, Object... args)
|
||||
public void audit(String source, String description, NodeRef key, Object... args)
|
||||
{
|
||||
AuditInfo auditInfo = new AuditInfo(auditConfiguration);
|
||||
AuditState auditInfo = new AuditState(auditConfiguration);
|
||||
// RecordOptions recordOptions = auditModel.getAuditRecordOptions(mi);
|
||||
AuditMode auditMode = AuditMode.UNSET;
|
||||
try
|
||||
@@ -353,18 +407,18 @@ public class AuditComponentImpl implements AuditComponent
|
||||
}
|
||||
}
|
||||
|
||||
private AuditMode onApplicationAudit(AuditMode auditMode, AuditInfo auditInfo, String source, String description,
|
||||
NodeRef key, Object... args)
|
||||
private AuditMode onApplicationAudit(AuditMode auditMode, AuditState auditInfo, String source,
|
||||
String description, NodeRef key, Object... args)
|
||||
{
|
||||
AuditMode effectiveAuditMode = auditModel.beforeExecution(auditMode, source, description, key, args);
|
||||
|
||||
if (auditMode != AuditMode.NONE)
|
||||
{
|
||||
if(source.equals(SYSTEM_APPLICATION))
|
||||
if (source.equals(SYSTEM_APPLICATION))
|
||||
{
|
||||
throw new AuditException("Application audit can not use the reserved identifier "+SYSTEM_APPLICATION);
|
||||
throw new AuditException("Application audit can not use the reserved identifier " + SYSTEM_APPLICATION);
|
||||
}
|
||||
|
||||
|
||||
auditInfo.setAuditApplication(source);
|
||||
auditInfo.setAuditConfiguration(auditConfiguration);
|
||||
auditInfo.setAuditMethod(null);
|
||||
@@ -374,10 +428,13 @@ public class AuditComponentImpl implements AuditComponent
|
||||
auditInfo.setFail(false);
|
||||
auditInfo.setFiltered(false);
|
||||
auditInfo.setHostAddress(auditHost);
|
||||
auditInfo.setKeyGUID(null);
|
||||
if (key != null)
|
||||
{
|
||||
auditInfo.setKeyStore(key.getStoreRef());
|
||||
auditInfo.setKeyGUID(key.getId());
|
||||
}
|
||||
auditInfo.setKeyPropertiesAfter(null);
|
||||
auditInfo.setKeyPropertiesBefore(null);
|
||||
auditInfo.setKeyStore(null);
|
||||
auditInfo.setMessage(description);
|
||||
if (args != null)
|
||||
{
|
||||
@@ -409,9 +466,9 @@ public class AuditComponentImpl implements AuditComponent
|
||||
|
||||
return effectiveAuditMode;
|
||||
}
|
||||
|
||||
private AuditMode onError(AuditMode auditMode, AuditInfo auditInfo, Throwable t, String source, String description,
|
||||
NodeRef key, Object... args)
|
||||
|
||||
private AuditMode onError(AuditMode auditMode, AuditState auditInfo, Throwable t, String source,
|
||||
String description, NodeRef key, Object... args)
|
||||
{
|
||||
if ((auditMode == AuditMode.ALL) || (auditMode == AuditMode.FAIL))
|
||||
{
|
||||
|
@@ -28,5 +28,5 @@ public interface AuditDAO
|
||||
*
|
||||
* @param auditInfo
|
||||
*/
|
||||
public void audit(AuditInfo auditInfo);
|
||||
public void audit(AuditState auditInfo);
|
||||
}
|
||||
|
@@ -16,8 +16,12 @@
|
||||
*/
|
||||
package org.alfresco.repo.audit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.audit.AuditInfo;
|
||||
import org.alfresco.service.cmr.audit.AuditService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
@@ -66,23 +70,41 @@ public class AuditServiceImpl implements AuditService
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
|
||||
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
||||
AuditService as = (AuditService) ctx.getBean("AuditService");
|
||||
|
||||
TransactionService txs = (TransactionService) ctx.getBean("transactionComponent");
|
||||
UserTransaction tx = txs.getUserTransaction();
|
||||
tx.begin();
|
||||
as.audit("AuditedApp", "First");
|
||||
as.audit("AuditedApp", "Second", new NodeRef(new StoreRef("test", "audit"), "id"));
|
||||
as.audit("AuditedApp", "Third", new Object[]{"one", "two", "three"});
|
||||
as.audit("AuditedApp", "Fourth", new NodeRef(new StoreRef("test", "audit"), "id"), new Object[]{"one", "two", "three"});
|
||||
|
||||
as.audit("UnAuditedApp", "First");
|
||||
as.audit("UnAuditedApp", "Second", new NodeRef(new StoreRef("test", "audit"), "id"));
|
||||
as.audit("UnAuditedApp", "Third", new Object[]{"one", "two", "three"});
|
||||
as.audit("UnAuditedApp", "Fourth", new NodeRef(new StoreRef("test", "audit"), "id"), new Object[]{"one", "two", "three"});
|
||||
|
||||
AuthenticationUtil.setSystemUserAsCurrentUser();
|
||||
try
|
||||
{
|
||||
|
||||
as.audit("AuditedApp", "First");
|
||||
as.audit("AuditedApp", "Second", new NodeRef(new StoreRef("test", "audit"), "id"));
|
||||
as.audit("AuditedApp", "Third", new Object[] { "one", "two", "three" });
|
||||
as.audit("AuditedApp", "Fourth", new NodeRef(new StoreRef("test", "audit"), "id"), new Object[] { "one",
|
||||
"two", "three" });
|
||||
|
||||
as.audit("UnAuditedApp", "First");
|
||||
as.audit("UnAuditedApp", "Second", new NodeRef(new StoreRef("test", "audit"), "id"));
|
||||
as.audit("UnAuditedApp", "Third", new Object[] { "one", "two", "three" });
|
||||
as.audit("UnAuditedApp", "Fourth", new NodeRef(new StoreRef("test", "audit"), "id"), new Object[] { "one",
|
||||
"two", "three" });
|
||||
}
|
||||
finally
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
tx.commit();
|
||||
|
||||
}
|
||||
|
||||
public List<AuditInfo> getAuditTrail(NodeRef nodeRef)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -35,9 +35,9 @@ import org.apache.log4j.Logger;
|
||||
*
|
||||
* @author Andy Hind
|
||||
*/
|
||||
public class AuditInfo
|
||||
public class AuditState
|
||||
{
|
||||
private static Logger s_logger = Logger.getLogger(AuditInfo.class);
|
||||
private static Logger s_logger = Logger.getLogger(AuditState.class);
|
||||
|
||||
/**
|
||||
* The user identifier for the person who caused this audit entry
|
||||
@@ -161,7 +161,7 @@ public class AuditInfo
|
||||
}
|
||||
}
|
||||
|
||||
public AuditInfo(AuditConfiguration auditConfiguration)
|
||||
public AuditState(AuditConfiguration auditConfiguration)
|
||||
{
|
||||
super();
|
||||
// Add default information
|
@@ -109,9 +109,9 @@
|
||||
<!-- The app_source_idx index is used to find the app source -->
|
||||
<!-- The look up is always the tripple, the service and method or just the method may be null -->
|
||||
|
||||
<property name="application" column="application" type="string" length="255" not-null="true" index="app_source_idx"/>
|
||||
<property name="service" column="service" type="string" length="255" not-null="false" index="app_source_idx"/>
|
||||
<property name="method" column="method" type="string" length="255" not-null="false" index="app_source_idx"/>
|
||||
<property name="application" column="application" type="string" length="255" not-null="true" index="app_source_app_idx"/>
|
||||
<property name="service" column="service" type="string" length="255" not-null="false" index="app_source_ser_idx"/>
|
||||
<property name="method" column="method" type="string" length="255" not-null="false" index="app_source_met_idx"/>
|
||||
|
||||
</class>
|
||||
|
||||
|
@@ -28,7 +28,7 @@ import java.util.HashMap;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.audit.AuditConfiguration;
|
||||
import org.alfresco.repo.audit.AuditDAO;
|
||||
import org.alfresco.repo.audit.AuditInfo;
|
||||
import org.alfresco.repo.audit.AuditState;
|
||||
import org.alfresco.repo.content.AbstractContentStore;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
@@ -92,7 +92,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
this.contentStore = contentStore;
|
||||
}
|
||||
|
||||
public void audit(AuditInfo auditInfo)
|
||||
public void audit(AuditState auditInfo)
|
||||
{
|
||||
// Find/Build the configuraton entry
|
||||
AuditConfigImpl auditConfig = getAuditConfig(auditInfo);
|
||||
@@ -170,7 +170,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
}
|
||||
}
|
||||
|
||||
private AuditSourceImpl getAuditSource(AuditInfo auditInfo)
|
||||
private AuditSourceImpl getAuditSource(AuditState auditInfo)
|
||||
{
|
||||
AuditSourceImpl auditSourceImpl;
|
||||
|
||||
@@ -218,7 +218,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
return auditSourceImpl;
|
||||
}
|
||||
|
||||
private AuditDateImpl getAuditDate(AuditInfo auditInfo)
|
||||
private AuditDateImpl getAuditDate(AuditState auditInfo)
|
||||
{
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
cal.setTime(auditInfo.getDate());
|
||||
@@ -265,7 +265,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
return auditDate;
|
||||
}
|
||||
|
||||
private AuditConfigImpl getAuditConfig(AuditInfo auditInfo)
|
||||
private AuditConfigImpl getAuditConfig(AuditState auditInfo)
|
||||
{
|
||||
AuditConfigImpl auditConfig;
|
||||
if ((auditConfiguration.get() == null) || (auditConfiguration.get() != auditInfo.getAuditConfiguration()))
|
||||
@@ -323,7 +323,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
return auditConfig;
|
||||
}
|
||||
|
||||
private AuditConfigImpl createNewAuditConfigImpl(AuditInfo auditInfo)
|
||||
private AuditConfigImpl createNewAuditConfigImpl(AuditState auditInfo)
|
||||
{
|
||||
AuditConfigImpl auditConfig = new AuditConfigImpl();
|
||||
InputStream is = new BufferedInputStream(auditInfo.getAuditConfiguration().getInputStream());
|
||||
|
@@ -16,6 +16,9 @@
|
||||
*/
|
||||
package org.alfresco.service.cmr.audit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.audit.AuditState;
|
||||
import org.alfresco.service.NotAuditable;
|
||||
import org.alfresco.service.PublicService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -81,5 +84,14 @@ public interface AuditService
|
||||
*/
|
||||
@NotAuditable
|
||||
public void audit(String source, String description, NodeRef key, Object... args);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the audit trail for a node ref.
|
||||
*
|
||||
* @param nodeRef - the node ref for which to get the audit trail.
|
||||
* @return - tha audit trail
|
||||
*/
|
||||
@NotAuditable
|
||||
public List<AuditInfo> getAuditTrail(NodeRef nodeRef);
|
||||
}
|
||||
|
Reference in New Issue
Block a user