From e22575b74e2c46e0138e1feb51c0e3c8a111c344 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Fri, 7 Sep 2007 14:27:17 +0000 Subject: [PATCH] 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 --- .../repo/audit/AuditComponentImpl.java | 112 ++++++++++-------- .../authentication/AuthenticationUtil.java | 6 +- .../impl/AbstractPermissionReference.java | 7 +- .../org/alfresco/service/namespace/QName.java | 14 +-- 4 files changed, 76 insertions(+), 63 deletions(-) diff --git a/source/java/org/alfresco/repo/audit/AuditComponentImpl.java b/source/java/org/alfresco/repo/audit/AuditComponentImpl.java index e9539cd81a..4b2b946002 100644 --- a/source/java/org/alfresco/repo/audit/AuditComponentImpl.java +++ b/source/java/org/alfresco/repo/audit/AuditComponentImpl.java @@ -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 diff --git a/source/java/org/alfresco/repo/security/authentication/AuthenticationUtil.java b/source/java/org/alfresco/repo/security/authentication/AuthenticationUtil.java index 280a00f7e5..65869247b1 100644 --- a/source/java/org/alfresco/repo/security/authentication/AuthenticationUtil.java +++ b/source/java/org/alfresco/repo/security/authentication/AuthenticationUtil.java @@ -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; } diff --git a/source/java/org/alfresco/repo/security/permissions/impl/AbstractPermissionReference.java b/source/java/org/alfresco/repo/security/permissions/impl/AbstractPermissionReference.java index 2e1595dc0e..faf6828c81 100644 --- a/source/java/org/alfresco/repo/security/permissions/impl/AbstractPermissionReference.java +++ b/source/java/org/alfresco/repo/security/permissions/impl/AbstractPermissionReference.java @@ -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; } } diff --git a/source/java/org/alfresco/service/namespace/QName.java b/source/java/org/alfresco/service/namespace/QName.java index facd81cd31..8aa37c0b94 100644 --- a/source/java/org/alfresco/service/namespace/QName.java +++ b/source/java/org/alfresco/service/namespace/QName.java @@ -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(); }