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:
@@ -3,7 +3,7 @@
|
|||||||
<!-- Default Audit Configuration -->
|
<!-- Default Audit Configuration -->
|
||||||
|
|
||||||
|
|
||||||
<Audit xmlns="http://www.alfresco.org/model/audit/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" enabled="false" auditInternal="false" mode="all">
|
<Audit xmlns="http://www.alfresco.org/model/audit/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" enabled="true" auditInternal="false" mode="all">
|
||||||
|
|
||||||
<!-- -->
|
<!-- -->
|
||||||
<!-- Global options -->
|
<!-- Global options -->
|
||||||
|
@@ -181,7 +181,7 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
*/
|
*/
|
||||||
public Object auditImpl(MethodInvocation mi) throws Throwable
|
public Object auditImpl(MethodInvocation mi) throws Throwable
|
||||||
{
|
{
|
||||||
AuditInfo auditInfo = new AuditInfo(auditConfiguration);
|
AuditState auditInfo = new AuditState(auditConfiguration);
|
||||||
// RecordOptions recordOptions = auditModel.getAuditRecordOptions(mi);
|
// RecordOptions recordOptions = auditModel.getAuditRecordOptions(mi);
|
||||||
AuditMode auditMode = AuditMode.UNSET;
|
AuditMode auditMode = AuditMode.UNSET;
|
||||||
try
|
try
|
||||||
@@ -221,7 +221,7 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
* @param t
|
* @param t
|
||||||
* @return
|
* @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))
|
if ((auditMode == AuditMode.ALL) || (auditMode == AuditMode.FAIL))
|
||||||
{
|
{
|
||||||
@@ -241,7 +241,8 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
* @param returnObject
|
* @param returnObject
|
||||||
* @return
|
* @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)
|
if (returnObject == null)
|
||||||
{
|
{
|
||||||
@@ -255,6 +256,18 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
{
|
{
|
||||||
auditInfo.setReturnObject(returnObject.toString());
|
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;
|
return auditMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +279,7 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
* @param mi
|
* @param mi
|
||||||
* @return
|
* @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);
|
AuditMode effectiveAuditMode = auditModel.beforeExecution(auditMode, mi);
|
||||||
|
|
||||||
@@ -283,10 +296,51 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
auditInfo.setFail(false);
|
auditInfo.setFail(false);
|
||||||
auditInfo.setFiltered(false);
|
auditInfo.setFiltered(false);
|
||||||
auditInfo.setHostAddress(auditHost);
|
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.setKeyPropertiesAfter(null);
|
||||||
auditInfo.setKeyPropertiesBefore(null);
|
auditInfo.setKeyPropertiesBefore(null);
|
||||||
auditInfo.setKeyStore(null);
|
|
||||||
auditInfo.setMessage(null);
|
auditInfo.setMessage(null);
|
||||||
if (mi.getArguments() != null)
|
if (mi.getArguments() != null)
|
||||||
{
|
{
|
||||||
@@ -324,7 +378,7 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
*/
|
*/
|
||||||
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);
|
// RecordOptions recordOptions = auditModel.getAuditRecordOptions(mi);
|
||||||
AuditMode auditMode = AuditMode.UNSET;
|
AuditMode auditMode = AuditMode.UNSET;
|
||||||
try
|
try
|
||||||
@@ -353,16 +407,16 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuditMode onApplicationAudit(AuditMode auditMode, AuditInfo auditInfo, String source, String description,
|
private AuditMode onApplicationAudit(AuditMode auditMode, AuditState auditInfo, String source,
|
||||||
NodeRef key, Object... args)
|
String description, NodeRef key, Object... args)
|
||||||
{
|
{
|
||||||
AuditMode effectiveAuditMode = auditModel.beforeExecution(auditMode, source, description, key, args);
|
AuditMode effectiveAuditMode = auditModel.beforeExecution(auditMode, source, description, key, args);
|
||||||
|
|
||||||
if (auditMode != AuditMode.NONE)
|
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.setAuditApplication(source);
|
||||||
@@ -374,10 +428,13 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
auditInfo.setFail(false);
|
auditInfo.setFail(false);
|
||||||
auditInfo.setFiltered(false);
|
auditInfo.setFiltered(false);
|
||||||
auditInfo.setHostAddress(auditHost);
|
auditInfo.setHostAddress(auditHost);
|
||||||
auditInfo.setKeyGUID(null);
|
if (key != null)
|
||||||
|
{
|
||||||
|
auditInfo.setKeyStore(key.getStoreRef());
|
||||||
|
auditInfo.setKeyGUID(key.getId());
|
||||||
|
}
|
||||||
auditInfo.setKeyPropertiesAfter(null);
|
auditInfo.setKeyPropertiesAfter(null);
|
||||||
auditInfo.setKeyPropertiesBefore(null);
|
auditInfo.setKeyPropertiesBefore(null);
|
||||||
auditInfo.setKeyStore(null);
|
|
||||||
auditInfo.setMessage(description);
|
auditInfo.setMessage(description);
|
||||||
if (args != null)
|
if (args != null)
|
||||||
{
|
{
|
||||||
@@ -410,8 +467,8 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
return effectiveAuditMode;
|
return effectiveAuditMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuditMode onError(AuditMode auditMode, AuditInfo auditInfo, Throwable t, String source, String description,
|
private AuditMode onError(AuditMode auditMode, AuditState auditInfo, Throwable t, String source,
|
||||||
NodeRef key, Object... args)
|
String description, NodeRef key, Object... args)
|
||||||
{
|
{
|
||||||
if ((auditMode == AuditMode.ALL) || (auditMode == AuditMode.FAIL))
|
if ((auditMode == AuditMode.ALL) || (auditMode == AuditMode.FAIL))
|
||||||
{
|
{
|
||||||
|
@@ -28,5 +28,5 @@ public interface AuditDAO
|
|||||||
*
|
*
|
||||||
* @param auditInfo
|
* @param auditInfo
|
||||||
*/
|
*/
|
||||||
public void audit(AuditInfo auditInfo);
|
public void audit(AuditState auditInfo);
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.audit;
|
package org.alfresco.repo.audit;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.transaction.UserTransaction;
|
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.audit.AuditService;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
@@ -66,23 +70,41 @@ public class AuditServiceImpl implements AuditService
|
|||||||
|
|
||||||
public static void main(String[] args) throws Exception
|
public static void main(String[] args) throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
||||||
AuditService as = (AuditService) ctx.getBean("AuditService");
|
AuditService as = (AuditService) ctx.getBean("AuditService");
|
||||||
|
|
||||||
TransactionService txs = (TransactionService) ctx.getBean("transactionComponent");
|
TransactionService txs = (TransactionService) ctx.getBean("transactionComponent");
|
||||||
UserTransaction tx = txs.getUserTransaction();
|
UserTransaction tx = txs.getUserTransaction();
|
||||||
tx.begin();
|
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");
|
AuthenticationUtil.setSystemUserAsCurrentUser();
|
||||||
as.audit("UnAuditedApp", "Second", new NodeRef(new StoreRef("test", "audit"), "id"));
|
try
|
||||||
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"});
|
|
||||||
|
|
||||||
|
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();
|
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
|
* @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
|
* 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();
|
super();
|
||||||
// Add default information
|
// Add default information
|
@@ -109,9 +109,9 @@
|
|||||||
<!-- The app_source_idx index is used to find the app source -->
|
<!-- 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 -->
|
<!-- 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="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_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_idx"/>
|
<property name="method" column="method" type="string" length="255" not-null="false" index="app_source_met_idx"/>
|
||||||
|
|
||||||
</class>
|
</class>
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@ import java.util.HashMap;
|
|||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.repo.audit.AuditConfiguration;
|
import org.alfresco.repo.audit.AuditConfiguration;
|
||||||
import org.alfresco.repo.audit.AuditDAO;
|
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.AbstractContentStore;
|
||||||
import org.alfresco.repo.content.ContentStore;
|
import org.alfresco.repo.content.ContentStore;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
@@ -92,7 +92,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
|||||||
this.contentStore = contentStore;
|
this.contentStore = contentStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void audit(AuditInfo auditInfo)
|
public void audit(AuditState auditInfo)
|
||||||
{
|
{
|
||||||
// Find/Build the configuraton entry
|
// Find/Build the configuraton entry
|
||||||
AuditConfigImpl auditConfig = getAuditConfig(auditInfo);
|
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;
|
AuditSourceImpl auditSourceImpl;
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
|||||||
return auditSourceImpl;
|
return auditSourceImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuditDateImpl getAuditDate(AuditInfo auditInfo)
|
private AuditDateImpl getAuditDate(AuditState auditInfo)
|
||||||
{
|
{
|
||||||
Calendar cal = GregorianCalendar.getInstance();
|
Calendar cal = GregorianCalendar.getInstance();
|
||||||
cal.setTime(auditInfo.getDate());
|
cal.setTime(auditInfo.getDate());
|
||||||
@@ -265,7 +265,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
|||||||
return auditDate;
|
return auditDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuditConfigImpl getAuditConfig(AuditInfo auditInfo)
|
private AuditConfigImpl getAuditConfig(AuditState auditInfo)
|
||||||
{
|
{
|
||||||
AuditConfigImpl auditConfig;
|
AuditConfigImpl auditConfig;
|
||||||
if ((auditConfiguration.get() == null) || (auditConfiguration.get() != auditInfo.getAuditConfiguration()))
|
if ((auditConfiguration.get() == null) || (auditConfiguration.get() != auditInfo.getAuditConfiguration()))
|
||||||
@@ -323,7 +323,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
|||||||
return auditConfig;
|
return auditConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuditConfigImpl createNewAuditConfigImpl(AuditInfo auditInfo)
|
private AuditConfigImpl createNewAuditConfigImpl(AuditState auditInfo)
|
||||||
{
|
{
|
||||||
AuditConfigImpl auditConfig = new AuditConfigImpl();
|
AuditConfigImpl auditConfig = new AuditConfigImpl();
|
||||||
InputStream is = new BufferedInputStream(auditInfo.getAuditConfiguration().getInputStream());
|
InputStream is = new BufferedInputStream(auditInfo.getAuditConfiguration().getInputStream());
|
||||||
|
@@ -16,6 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.service.cmr.audit;
|
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.NotAuditable;
|
||||||
import org.alfresco.service.PublicService;
|
import org.alfresco.service.PublicService;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
@@ -82,4 +85,13 @@ public interface AuditService
|
|||||||
@NotAuditable
|
@NotAuditable
|
||||||
public void audit(String source, String description, NodeRef key, Object... args);
|
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