improve trace logging for authentication

This commit is contained in:
Sebastian Sdorra
2012-06-28 10:55:55 +02:00
parent d9cedfd8b1
commit da7e9c67d8
4 changed files with 75 additions and 0 deletions

View File

@@ -123,15 +123,42 @@ public class BasicAuthenticationFilter extends HttpFilter
if (Util.isNotEmpty(authentication) if (Util.isNotEmpty(authentication)
&& authentication.toUpperCase().startsWith(AUTHORIZATION_BASIC_PREFIX)) && authentication.toUpperCase().startsWith(AUTHORIZATION_BASIC_PREFIX))
{ {
if (logger.isTraceEnabled())
{
logger.trace("found basic authorization header, start authentication");
}
user = authenticate(request, response, securityContext, authentication); user = authenticate(request, response, securityContext, authentication);
if (logger.isTraceEnabled())
{
if (user != null)
{
logger.trace("user {} successfully authenticated", user.getName());
}
else
{
logger.trace("authentcation failed, user object is null");
}
}
} }
else if (securityContext.isAuthenticated()) else if (securityContext.isAuthenticated())
{ {
if (logger.isTraceEnabled())
{
logger.trace("user is allready authenticated");
}
user = securityContext.getUser(); user = securityContext.getUser();
} }
if (user == null) if (user == null)
{ {
if (logger.isTraceEnabled())
{
logger.trace("could not find user send unauthorized");
}
HttpUtil.sendUnauthorized(response); HttpUtil.sendUnauthorized(response);
} }
else else
@@ -192,6 +219,11 @@ public class BasicAuthenticationFilter extends HttpFilter
if (Util.isNotEmpty(username) && Util.isNotEmpty(password)) if (Util.isNotEmpty(username) && Util.isNotEmpty(password))
{ {
if (logger.isTraceEnabled())
{
logger.trace("try to authenticate user {}", username);
}
user = securityContext.authenticate(request, response, username, user = securityContext.authenticate(request, response, username,
password); password);
} }

View File

@@ -150,6 +150,15 @@ public abstract class PermissionFilter extends HttpFilter
if (hasPermission(repository, securityContext, writeRequest)) if (hasPermission(repository, securityContext, writeRequest))
{ {
if (logger.isTraceEnabled())
{
logger.trace("{} access to repository {} for user {} granted",
new Object[] { writeRequest
? "write"
: "read", repository.getName(),
user.getName() });
}
chain.doFilter(request, response); chain.doFilter(request, response);
} }
else else

View File

@@ -124,9 +124,16 @@ public class BasicSecurityContext implements WebSecurityContext
HttpServletResponse response, String username, HttpServletResponse response, String username,
String password) String password)
{ {
if ( logger.isTraceEnabled() ){
logger.trace("start authentication for user {}", username);
}
AuthenticationResult ar = authenticator.authenticate(request, response, AuthenticationResult ar = authenticator.authenticate(request, response,
username, password); username, password);
if ( logger.isTraceEnabled() ){
logger.trace("authentication ends with {}", ar);
}
if ((ar != null) && (ar.getState() == AuthenticationState.SUCCESS)) if ((ar != null) && (ar.getState() == AuthenticationState.SUCCESS))
{ {
authenticate(request, password, ar); authenticate(request, password, ar);

View File

@@ -130,6 +130,12 @@ public class ChainAuthenticatonManager extends AbstractAuthenticationManager
if (ar == null) if (ar == null)
{ {
if (logger.isTraceEnabled())
{
logger.trace("no authentication result for user {} found in cache",
username);
}
ar = doAuthentication(request, response, username, password); ar = doAuthentication(request, response, username, password);
if ((ar != null) && ar.isCacheable()) if ((ar != null) && ar.isCacheable())
@@ -157,6 +163,11 @@ public class ChainAuthenticatonManager extends AbstractAuthenticationManager
{ {
for (AuthenticationHandler authenticator : authenticationHandlerSet) for (AuthenticationHandler authenticator : authenticationHandlerSet)
{ {
if (logger.isTraceEnabled())
{
logger.trace("close authenticator {}", authenticator.getClass());
}
IOUtil.close(authenticator); IOUtil.close(authenticator);
} }
} }
@@ -172,6 +183,11 @@ public class ChainAuthenticatonManager extends AbstractAuthenticationManager
{ {
for (AuthenticationHandler authenticator : authenticationHandlerSet) for (AuthenticationHandler authenticator : authenticationHandlerSet)
{ {
if (logger.isTraceEnabled())
{
logger.trace("initialize authenticator {}", authenticator.getClass());
}
authenticator.init(context); authenticator.init(context);
} }
@@ -200,8 +216,19 @@ public class ChainAuthenticatonManager extends AbstractAuthenticationManager
{ {
AuthenticationResult ar = null; AuthenticationResult ar = null;
if (logger.isTraceEnabled())
{
logger.trace("start authentication chain for user {}", username);
}
for (AuthenticationHandler authenticator : authenticationHandlerSet) for (AuthenticationHandler authenticator : authenticationHandlerSet)
{ {
if (logger.isTraceEnabled())
{
logger.trace("check authenticator {} for user {}",
authenticator.getClass(), username);
}
try try
{ {
AuthenticationResult result = authenticator.authenticate(request, AuthenticationResult result = authenticator.authenticate(request,