mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Performance tweaks after profiling HEAD code. Audit interceptor shortcut to avoid calling auditImpl at all when auditing disabled in config.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6700 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -31,6 +31,7 @@ import java.net.UnknownHostException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.audit.model.AuditEntry;
|
||||
import org.alfresco.repo.audit.model.TrueFalseUnset;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
@@ -160,77 +161,84 @@ public class AuditComponentImpl implements AuditComponent
|
||||
{
|
||||
if ((auditFlag.get() == null) || (!auditFlag.get().booleanValue()))
|
||||
{
|
||||
boolean auditInternal = (auditModel.getAuditInternalServiceMethods(mi) == TrueFalseUnset.TRUE);
|
||||
try
|
||||
if (auditModel instanceof AuditEntry && ((AuditEntry)auditModel).getEnabled() == TrueFalseUnset.TRUE)
|
||||
{
|
||||
Method method = mi.getMethod();
|
||||
String methodName = method.getName();
|
||||
String serviceName = publicServiceIdentifier.getPublicServiceName(mi);
|
||||
boolean auditInternal = (auditModel.getAuditInternalServiceMethods(mi) == TrueFalseUnset.TRUE);
|
||||
try
|
||||
{
|
||||
Method method = mi.getMethod();
|
||||
String methodName = method.getName();
|
||||
String serviceName = publicServiceIdentifier.getPublicServiceName(mi);
|
||||
|
||||
if (!auditInternal)
|
||||
{
|
||||
auditFlag.set(Boolean.TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
if (!auditInternal)
|
||||
{
|
||||
s_logger.debug("Auditing internal service use for - " + serviceName + "." + methodName);
|
||||
}
|
||||
}
|
||||
|
||||
if (method.isAnnotationPresent(Auditable.class))
|
||||
{
|
||||
|
||||
if (serviceName != null)
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("Auditing - " + serviceName + "." + methodName);
|
||||
}
|
||||
return auditImpl(mi);
|
||||
auditFlag.set(Boolean.TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("UnknownService." + methodName);
|
||||
s_logger.debug("Auditing internal service use for - " + serviceName + "." + methodName);
|
||||
}
|
||||
return auditImpl(mi);
|
||||
}
|
||||
|
||||
}
|
||||
else if (method.isAnnotationPresent(NotAuditable.class))
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
if (method.isAnnotationPresent(Auditable.class))
|
||||
{
|
||||
s_logger.debug("Not Audited. " + serviceName + "." + methodName);
|
||||
|
||||
if (serviceName != null)
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("Auditing - " + serviceName + "." + methodName);
|
||||
}
|
||||
return auditImpl(mi);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("UnknownService." + methodName);
|
||||
}
|
||||
return auditImpl(mi);
|
||||
}
|
||||
|
||||
}
|
||||
return mi.proceed();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("Unannotated service method " + serviceName + "." + methodName);
|
||||
}
|
||||
if (method.getDeclaringClass().isInterface()
|
||||
&& method.getDeclaringClass().isAnnotationPresent(PublicService.class))
|
||||
{
|
||||
throw new RuntimeException("Unannotated service method " + serviceName + "." + methodName);
|
||||
}
|
||||
else
|
||||
else if (method.isAnnotationPresent(NotAuditable.class))
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("Not Audited. " + serviceName + "." + methodName);
|
||||
}
|
||||
return mi.proceed();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("Unannotated service method " + serviceName + "." + methodName);
|
||||
}
|
||||
if (method.getDeclaringClass().isInterface()
|
||||
&& method.getDeclaringClass().isAnnotationPresent(PublicService.class))
|
||||
{
|
||||
throw new RuntimeException("Unannotated service method " + serviceName + "." + methodName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return mi.proceed();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!auditInternal)
|
||||
{
|
||||
auditFlag.set(Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
else
|
||||
{
|
||||
if (!auditInternal)
|
||||
{
|
||||
auditFlag.set(Boolean.FALSE);
|
||||
}
|
||||
return mi.proceed();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@@ -222,12 +222,16 @@ public abstract class AuthenticationUtil
|
||||
*/
|
||||
private static String getUserName(Authentication authentication)
|
||||
{
|
||||
String username = authentication.getPrincipal().toString();
|
||||
String username;
|
||||
|
||||
if (authentication.getPrincipal() instanceof UserDetails)
|
||||
{
|
||||
username = ((UserDetails) authentication.getPrincipal()).getUsername();
|
||||
}
|
||||
else
|
||||
{
|
||||
username = authentication.getPrincipal().toString();
|
||||
}
|
||||
|
||||
return username;
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ import org.alfresco.repo.security.permissions.PermissionReference;
|
||||
public abstract class AbstractPermissionReference implements PermissionReference
|
||||
{
|
||||
private int hashcode = 0;
|
||||
private String str = null;
|
||||
|
||||
public AbstractPermissionReference()
|
||||
{
|
||||
@@ -69,6 +70,10 @@ public abstract class AbstractPermissionReference implements PermissionReference
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getQName()+ "." + getName();
|
||||
if (str == null)
|
||||
{
|
||||
str = getQName() + "." + getName();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
@@ -296,10 +296,6 @@ public final class QName implements QNamePattern, Serializable, Cloneable
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (object == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (object instanceof QName)
|
||||
{
|
||||
QName other = (QName)object;
|
||||
@@ -307,10 +303,7 @@ public final class QName implements QNamePattern, Serializable, Cloneable
|
||||
return (this.localName.equals(other.localName) &&
|
||||
this.namespaceURI.equals(other.namespaceURI));
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,7 +340,10 @@ public final class QName implements QNamePattern, Serializable, Cloneable
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return NAMESPACE_BEGIN + namespaceURI + NAMESPACE_END + localName;
|
||||
return new StringBuffer(80).append(NAMESPACE_BEGIN)
|
||||
.append(namespaceURI)
|
||||
.append(NAMESPACE_END)
|
||||
.append(localName).toString();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user