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:
Kevin Roast
2007-09-07 14:27:17 +00:00
parent a03df08f5e
commit e22575b74e
4 changed files with 76 additions and 63 deletions

View File

@@ -31,6 +31,7 @@ import java.net.UnknownHostException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.alfresco.repo.audit.model.AuditEntry;
import org.alfresco.repo.audit.model.TrueFalseUnset; import org.alfresco.repo.audit.model.TrueFalseUnset;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
@@ -160,77 +161,84 @@ public class AuditComponentImpl implements AuditComponent
{ {
if ((auditFlag.get() == null) || (!auditFlag.get().booleanValue())) if ((auditFlag.get() == null) || (!auditFlag.get().booleanValue()))
{ {
boolean auditInternal = (auditModel.getAuditInternalServiceMethods(mi) == TrueFalseUnset.TRUE); if (auditModel instanceof AuditEntry && ((AuditEntry)auditModel).getEnabled() == TrueFalseUnset.TRUE)
try
{ {
Method method = mi.getMethod(); boolean auditInternal = (auditModel.getAuditInternalServiceMethods(mi) == TrueFalseUnset.TRUE);
String methodName = method.getName(); try
String serviceName = publicServiceIdentifier.getPublicServiceName(mi); {
Method method = mi.getMethod();
String methodName = method.getName();
String serviceName = publicServiceIdentifier.getPublicServiceName(mi);
if (!auditInternal) if (!auditInternal)
{
auditFlag.set(Boolean.TRUE);
}
else
{
if (s_logger.isDebugEnabled())
{ {
s_logger.debug("Auditing internal service use for - " + serviceName + "." + methodName); auditFlag.set(Boolean.TRUE);
}
}
if (method.isAnnotationPresent(Auditable.class))
{
if (serviceName != null)
{
if (s_logger.isDebugEnabled())
{
s_logger.debug("Auditing - " + serviceName + "." + methodName);
}
return auditImpl(mi);
} }
else else
{ {
if (s_logger.isDebugEnabled()) if (s_logger.isDebugEnabled())
{ {
s_logger.debug("UnknownService." + methodName); s_logger.debug("Auditing internal service use for - " + serviceName + "." + methodName);
} }
return auditImpl(mi);
} }
} if (method.isAnnotationPresent(Auditable.class))
else if (method.isAnnotationPresent(NotAuditable.class))
{
if (s_logger.isDebugEnabled())
{ {
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 (method.isAnnotationPresent(NotAuditable.class))
}
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
{ {
if (s_logger.isDebugEnabled())
{
s_logger.debug("Not Audited. " + serviceName + "." + methodName);
}
return mi.proceed(); 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) return mi.proceed();
{
auditFlag.set(Boolean.FALSE);
}
} }
} }
else else

View File

@@ -222,12 +222,16 @@ public abstract class AuthenticationUtil
*/ */
private static String getUserName(Authentication authentication) private static String getUserName(Authentication authentication)
{ {
String username = authentication.getPrincipal().toString(); String username;
if (authentication.getPrincipal() instanceof UserDetails) if (authentication.getPrincipal() instanceof UserDetails)
{ {
username = ((UserDetails) authentication.getPrincipal()).getUsername(); username = ((UserDetails) authentication.getPrincipal()).getUsername();
} }
else
{
username = authentication.getPrincipal().toString();
}
return username; return username;
} }

View File

@@ -35,6 +35,7 @@ import org.alfresco.repo.security.permissions.PermissionReference;
public abstract class AbstractPermissionReference implements PermissionReference public abstract class AbstractPermissionReference implements PermissionReference
{ {
private int hashcode = 0; private int hashcode = 0;
private String str = null;
public AbstractPermissionReference() public AbstractPermissionReference()
{ {
@@ -69,6 +70,10 @@ public abstract class AbstractPermissionReference implements PermissionReference
@Override @Override
public String toString() public String toString()
{ {
return getQName()+ "." + getName(); if (str == null)
{
str = getQName() + "." + getName();
}
return str;
} }
} }

View File

@@ -296,10 +296,6 @@ public final class QName implements QNamePattern, Serializable, Cloneable
{ {
return true; return true;
} }
else if (object == null)
{
return false;
}
if (object instanceof QName) if (object instanceof QName)
{ {
QName other = (QName)object; QName other = (QName)object;
@@ -307,10 +303,7 @@ public final class QName implements QNamePattern, Serializable, Cloneable
return (this.localName.equals(other.localName) && return (this.localName.equals(other.localName) &&
this.namespaceURI.equals(other.namespaceURI)); 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() 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();
} }