mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Yet another merge from head to WCM-DEV2.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3774 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -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="256" not-null="true" index="app_source_idx"/>
|
||||
<property name="service" column="service" type="string" length="256" not-null="false" index="app_source_idx"/>
|
||||
<property name="method" column="method" type="string" length="256" 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>
|
||||
|
||||
@@ -155,4 +155,30 @@
|
||||
audit_store.method = :method
|
||||
</query>
|
||||
|
||||
<query name="audit.GetAuditTrailForNode">
|
||||
select
|
||||
audit_fact
|
||||
from
|
||||
org.alfresco.repo.audit.hibernate.AuditFactImpl as audit_fact
|
||||
where
|
||||
(audit_fact.storeProtocol = :protocol and
|
||||
audit_fact.storeId = :store_id and
|
||||
audit_fact.nodeUUID = :node_id)
|
||||
or
|
||||
arg1 like :nodeRef
|
||||
or
|
||||
arg2 like :nodeRef
|
||||
or
|
||||
arg3 like :nodeRef
|
||||
or
|
||||
arg4 like :nodeRef
|
||||
or
|
||||
arg5 like :nodeRef
|
||||
or
|
||||
returnValue like :nodeRef
|
||||
order by
|
||||
audit_fact.date asc
|
||||
</query>
|
||||
|
||||
|
||||
</hibernate-mapping>
|
@@ -87,10 +87,10 @@ public class AuditConfigImpl implements AuditConfig, InitializingBean
|
||||
/**
|
||||
* Helper method to get the latest audit config
|
||||
*/
|
||||
public static AuditConfigImpl getLatestConfig(Session session)
|
||||
public static AuditConfig getLatestConfig(Session session)
|
||||
{
|
||||
Query query = session.getNamedQuery(HibernateAuditDAO.QUERY_LAST_AUDIT_CONFIG);
|
||||
return (AuditConfigImpl) query.uniqueResult();
|
||||
return (AuditConfig) query.uniqueResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -280,10 +280,10 @@ public class AuditDateImpl implements AuditDate
|
||||
/**
|
||||
* Helper method to get the latest audit date
|
||||
*/
|
||||
public static AuditDateImpl getLatestDate(Session session)
|
||||
public static AuditDate getLatestDate(Session session)
|
||||
{
|
||||
Query query = session.getNamedQuery(HibernateAuditDAO.QUERY_LAST_AUDIT_DATE);
|
||||
return (AuditDateImpl) query.uniqueResult();
|
||||
return (AuditDate) query.uniqueResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,6 +17,11 @@
|
||||
package org.alfresco.repo.audit.hibernate;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
|
||||
/**
|
||||
* An Audit fact Rely on standard equals and hash code as they should all be unique.
|
||||
@@ -575,4 +580,17 @@ public class AuditFactImpl implements AuditFact
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get all the audit entries for a node.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<AuditFact> getAuditTrail(Session session, NodeRef nodeRef)
|
||||
{
|
||||
Query query = session.getNamedQuery(HibernateAuditDAO.QUERY_AUDIT_TRAIL);
|
||||
query.setParameter(HibernateAuditDAO.QUERY_AUDIT_PROTOCOL, nodeRef.getStoreRef().getProtocol());
|
||||
query.setParameter(HibernateAuditDAO.QUERY_AUDIT_STORE_ID, nodeRef.getStoreRef().getIdentifier());
|
||||
query.setParameter(HibernateAuditDAO.QUERY_AUDIT_NODE_ID, nodeRef.getId());
|
||||
query.setParameter(HibernateAuditDAO.QUERY_AUDIT_NODE_REF, "%"+nodeRef.toString()+"%");
|
||||
return (List<AuditFact>) query.list();
|
||||
}
|
||||
}
|
||||
|
231
source/java/org/alfresco/repo/audit/hibernate/AuditInfoImpl.java
Normal file
231
source/java/org/alfresco/repo/audit/hibernate/AuditInfoImpl.java
Normal file
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* 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.hibernate;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.audit.AuditInfo;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
public class AuditInfoImpl implements AuditInfo
|
||||
{
|
||||
private String auditApplication;
|
||||
|
||||
private String auditMethod;
|
||||
|
||||
private String auditService;
|
||||
|
||||
private String clientAddress;
|
||||
|
||||
private Date date;
|
||||
|
||||
private boolean fail;
|
||||
|
||||
private boolean filtered;
|
||||
|
||||
private String hostAddress;
|
||||
|
||||
private String keyGUID;
|
||||
|
||||
private Map<QName, Serializable> keyPropertiesAfter;
|
||||
|
||||
private Map<QName, Serializable> keyPropertiesBefore;
|
||||
|
||||
private StoreRef keyStore;
|
||||
|
||||
private String message;
|
||||
|
||||
private Serializable[] methodArguments;
|
||||
|
||||
private String[] methodArgumentsAsStrings;
|
||||
|
||||
private String path;
|
||||
|
||||
private Serializable returnObject;
|
||||
|
||||
private String returnObjectAsString;
|
||||
|
||||
private String sessionId;
|
||||
|
||||
private Throwable throwable;
|
||||
|
||||
private String throwableAsString;
|
||||
|
||||
private String txId;
|
||||
|
||||
private String userIdentifier;
|
||||
|
||||
public AuditInfoImpl(AuditFact auditFact)
|
||||
{
|
||||
super();
|
||||
this.auditApplication = auditFact.getAuditSource().getApplication();
|
||||
this.auditMethod = auditFact.getAuditSource().getMethod();
|
||||
this.auditService = auditFact.getAuditSource().getService();
|
||||
this.clientAddress = auditFact.getClientInetAddress();
|
||||
this.date = auditFact.getDate();
|
||||
this.fail = auditFact.isFail();
|
||||
this.filtered = auditFact.isFiltered();
|
||||
this.hostAddress= auditFact.getHostInetAddress();
|
||||
this.keyGUID = auditFact.getNodeUUID();
|
||||
this.keyPropertiesAfter = null;
|
||||
this.keyPropertiesBefore = null;
|
||||
if((auditFact.getStoreProtocol() != null) && (auditFact.getStoreId() != null))
|
||||
{
|
||||
this.keyStore = new StoreRef(auditFact.getStoreProtocol(), auditFact.getStoreId());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.keyStore = null;
|
||||
}
|
||||
this.message = auditFact.getMessage();
|
||||
this.methodArguments = null;
|
||||
this.methodArgumentsAsStrings = new String[5];
|
||||
this.methodArgumentsAsStrings[0] = auditFact.getArg1();
|
||||
this.methodArgumentsAsStrings[1] = auditFact.getArg2();
|
||||
this.methodArgumentsAsStrings[2] = auditFact.getArg3();
|
||||
this.methodArgumentsAsStrings[3] = auditFact.getArg4();
|
||||
this.methodArgumentsAsStrings[4] = auditFact.getArg5();
|
||||
this.path = auditFact.getPath();
|
||||
this.returnObject = null;
|
||||
this.returnObjectAsString = auditFact.getReturnValue();
|
||||
this.sessionId = auditFact.getSessionId();
|
||||
this.throwable = null;
|
||||
this.throwableAsString = auditFact.getException();
|
||||
this.txId = auditFact.getTransactionId();
|
||||
this.userIdentifier = auditFact.getUserId();
|
||||
}
|
||||
|
||||
public String getAuditApplication()
|
||||
{
|
||||
return auditApplication;
|
||||
}
|
||||
|
||||
public String getAuditMethod()
|
||||
{
|
||||
return auditMethod;
|
||||
}
|
||||
|
||||
public String getAuditService()
|
||||
{
|
||||
return auditService;
|
||||
}
|
||||
|
||||
public String getClientAddress()
|
||||
{
|
||||
return clientAddress;
|
||||
}
|
||||
|
||||
public Date getDate()
|
||||
{
|
||||
return date;
|
||||
}
|
||||
|
||||
public boolean isFail()
|
||||
{
|
||||
return fail;
|
||||
}
|
||||
|
||||
public boolean isFiltered()
|
||||
{
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public String getHostAddress()
|
||||
{
|
||||
return hostAddress;
|
||||
}
|
||||
|
||||
public String getKeyGUID()
|
||||
{
|
||||
return keyGUID;
|
||||
}
|
||||
|
||||
public Map<QName, Serializable> getKeyPropertiesAfter()
|
||||
{
|
||||
return keyPropertiesAfter;
|
||||
}
|
||||
|
||||
public Map<QName, Serializable> getKeyPropertiesBefore()
|
||||
{
|
||||
return keyPropertiesBefore;
|
||||
}
|
||||
|
||||
public StoreRef getKeyStore()
|
||||
{
|
||||
return keyStore;
|
||||
}
|
||||
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
public Serializable[] getMethodArguments()
|
||||
{
|
||||
return methodArguments;
|
||||
}
|
||||
|
||||
public String[] getMethodArgumentsAsStrings()
|
||||
{
|
||||
return methodArgumentsAsStrings;
|
||||
}
|
||||
|
||||
public String getPath()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
public Serializable getReturnObject()
|
||||
{
|
||||
return returnObject;
|
||||
}
|
||||
|
||||
public String getReturnObjectAsString()
|
||||
{
|
||||
return returnObjectAsString;
|
||||
}
|
||||
|
||||
public String getSessionId()
|
||||
{
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public Throwable getThrowable()
|
||||
{
|
||||
return throwable;
|
||||
}
|
||||
|
||||
public String getThrowableAsString()
|
||||
{
|
||||
return throwableAsString;
|
||||
}
|
||||
|
||||
public String getTxId()
|
||||
{
|
||||
return txId;
|
||||
}
|
||||
|
||||
public String getUserIdentifier()
|
||||
{
|
||||
return userIdentifier;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -26,4 +26,10 @@ public interface AuditSource
|
||||
|
||||
public String getService();
|
||||
|
||||
void setApplication(String auditApplication);
|
||||
|
||||
void setService(String auditService);
|
||||
|
||||
void setMethod(String auditMethod);
|
||||
|
||||
}
|
@@ -87,21 +87,21 @@ public class AuditSourceImpl implements AuditSource
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public static AuditSourceImpl getApplicationSource(Session session, String application)
|
||||
public static AuditSource getApplicationSource(Session session, String application)
|
||||
{
|
||||
Query query = session.getNamedQuery(HibernateAuditDAO.QUERY_AUDIT_APP_SOURCE);
|
||||
query.setParameter(HibernateAuditDAO.QUERY_AUDIT_APP_SOURCE_APP, application);
|
||||
return (AuditSourceImpl) query.uniqueResult();
|
||||
return (AuditSource) query.uniqueResult();
|
||||
}
|
||||
|
||||
public static AuditSourceImpl getApplicationSource(Session session, String application, String service,
|
||||
public static AuditSource getApplicationSource(Session session, String application, String service,
|
||||
String method)
|
||||
{
|
||||
Query query = session.getNamedQuery(HibernateAuditDAO.QUERY_AUDIT_METHOD_SOURCE);
|
||||
query.setParameter(HibernateAuditDAO.QUERY_AUDIT_APP_SOURCE_APP, application);
|
||||
query.setParameter(HibernateAuditDAO.QUERY_AUDIT_APP_SOURCE_SER, service);
|
||||
query.setParameter(HibernateAuditDAO.QUERY_AUDIT_APP_SOURCE_MET, method);
|
||||
return (AuditSourceImpl) query.uniqueResult();
|
||||
return (AuditSource) query.uniqueResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -20,21 +20,28 @@ import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
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.AuditException;
|
||||
import org.alfresco.repo.audit.AuditState;
|
||||
import org.alfresco.repo.content.AbstractContentStore;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.TransactionalDao;
|
||||
import org.alfresco.service.cmr.audit.AuditInfo;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.datatype.Duration;
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.alfresco.util.GUID;
|
||||
@@ -63,6 +70,16 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
|
||||
public static final String QUERY_AUDIT_APP_SOURCE_MET = "method";
|
||||
|
||||
public static final String QUERY_AUDIT_TRAIL = "audit.GetAuditTrailForNode";
|
||||
|
||||
public static final String QUERY_AUDIT_PROTOCOL = "protocol";
|
||||
|
||||
public static final String QUERY_AUDIT_STORE_ID = "store_id";
|
||||
|
||||
public static final String QUERY_AUDIT_NODE_ID = "node_id";
|
||||
|
||||
public static final String QUERY_AUDIT_NODE_REF = "nodeRef";
|
||||
|
||||
/** a uuid identifying this unique instance */
|
||||
private String uuid;
|
||||
|
||||
@@ -92,16 +109,40 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
this.contentStore = contentStore;
|
||||
}
|
||||
|
||||
public void audit(AuditInfo auditInfo)
|
||||
public void audit(AuditState auditInfo)
|
||||
{
|
||||
if(auditInfo.getUserIdentifier() == null)
|
||||
{
|
||||
auditInfo.setUserIdentifier(AuthenticationUtil.getSystemUserName());
|
||||
}
|
||||
if(AuthenticationUtil.getCurrentUserName() == null)
|
||||
{
|
||||
AuthenticationUtil.setSystemUserAsCurrentUser();
|
||||
try
|
||||
{
|
||||
audit0(auditInfo);
|
||||
}
|
||||
finally
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
audit0(auditInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private void audit0(AuditState auditInfo)
|
||||
{
|
||||
// Find/Build the configuraton entry
|
||||
AuditConfigImpl auditConfig = getAuditConfig(auditInfo);
|
||||
AuditConfig auditConfig = getAuditConfig(auditInfo);
|
||||
|
||||
// Find/Build any dates
|
||||
AuditDateImpl auditDate = getAuditDate(auditInfo);
|
||||
AuditDate auditDate = getAuditDate(auditInfo);
|
||||
|
||||
// Find/Build the source
|
||||
AuditSourceImpl auditSource = getAuditSource(auditInfo);
|
||||
AuditSource auditSource = getAuditSource(auditInfo);
|
||||
|
||||
// Build the new audit fact information
|
||||
AuditFactImpl auditFact = new AuditFactImpl();
|
||||
@@ -170,9 +211,9 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
}
|
||||
}
|
||||
|
||||
private AuditSourceImpl getAuditSource(AuditInfo auditInfo)
|
||||
private AuditSource getAuditSource(AuditState auditInfo)
|
||||
{
|
||||
AuditSourceImpl auditSourceImpl;
|
||||
AuditSource auditSourceImpl;
|
||||
|
||||
SourceKey sourceKey = new SourceKey(auditInfo.getAuditApplication(), auditInfo.getAuditService(), auditInfo.getAuditMethod());
|
||||
if(sourceIds.get() == null)
|
||||
@@ -182,7 +223,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
Long id = sourceIds.get().get(sourceKey);
|
||||
if(id != null)
|
||||
{
|
||||
auditSourceImpl = (AuditSourceImpl) getSession().get(AuditSourceImpl.class, id.longValue());
|
||||
auditSourceImpl = (AuditSource) getSession().get(AuditSourceImpl.class, id.longValue());
|
||||
if(auditSourceImpl != null)
|
||||
{
|
||||
return auditSourceImpl;
|
||||
@@ -218,7 +259,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
return auditSourceImpl;
|
||||
}
|
||||
|
||||
private AuditDateImpl getAuditDate(AuditInfo auditInfo)
|
||||
private AuditDate getAuditDate(AuditState auditInfo)
|
||||
{
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
cal.setTime(auditInfo.getDate());
|
||||
@@ -228,7 +269,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
Date required = cal.getTime();
|
||||
|
||||
AuditDateImpl auditDate;
|
||||
AuditDate auditDate;
|
||||
if (auditDateImplId.get() == null)
|
||||
{
|
||||
auditDate = AuditDateImpl.getLatestDate(getSession());
|
||||
@@ -242,7 +283,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
}
|
||||
else
|
||||
{
|
||||
auditDate = (AuditDateImpl) getSession().get(AuditDateImpl.class, auditDateImplId.get().longValue());
|
||||
auditDate = (AuditDate) getSession().get(AuditDateImpl.class, auditDateImplId.get().longValue());
|
||||
if ((auditDate == null) || (!required.equals(auditDate.getDate())))
|
||||
{
|
||||
auditDate = AuditDateImpl.getLatestDate(getSession());
|
||||
@@ -265,9 +306,9 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
return auditDate;
|
||||
}
|
||||
|
||||
private AuditConfigImpl getAuditConfig(AuditInfo auditInfo)
|
||||
private AuditConfig getAuditConfig(AuditState auditInfo)
|
||||
{
|
||||
AuditConfigImpl auditConfig;
|
||||
AuditConfig auditConfig;
|
||||
if ((auditConfiguration.get() == null) || (auditConfiguration.get() != auditInfo.getAuditConfiguration()))
|
||||
{
|
||||
auditConfig = AuditConfigImpl.getLatestConfig(getSession());
|
||||
@@ -313,7 +354,7 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
}
|
||||
else
|
||||
{
|
||||
auditConfig = (AuditConfigImpl) getSession()
|
||||
auditConfig = (AuditConfig) getSession()
|
||||
.get(AuditConfigImpl.class, auditConfigImplId.get().longValue());
|
||||
if (auditConfig == null)
|
||||
{
|
||||
@@ -323,7 +364,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());
|
||||
@@ -436,4 +477,23 @@ public class HibernateAuditDAO extends HibernateDaoSupport implements AuditDAO,
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
public List<AuditInfo> getAuditTrail(NodeRef nodeRef)
|
||||
{
|
||||
if(nodeRef == null)
|
||||
{
|
||||
return Collections.<AuditInfo>emptyList();
|
||||
}
|
||||
List<? extends AuditFact> internalTrail = AuditFactImpl.getAuditTrail(getSession(), nodeRef);
|
||||
|
||||
ArrayList<AuditInfo> answer = new ArrayList<AuditInfo>(internalTrail.size());
|
||||
for(AuditFact auditFact : internalTrail)
|
||||
{
|
||||
AuditInfo info = new AuditInfoImpl(auditFact);
|
||||
answer.add(info);
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user