Skip to content

Commit

Permalink
Fix user name in log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bernd committed Mar 17, 2016
1 parent 3a3c35d commit c606667
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -18,7 +18,7 @@


import org.apache.shiro.authz.AuthorizationException; import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject; import org.graylog2.rest.RestTools;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;


Expand All @@ -44,13 +44,13 @@ public void filter(ContainerRequestContext requestContext) throws IOException {
final SecurityContext securityContext = requestContext.getSecurityContext(); final SecurityContext securityContext = requestContext.getSecurityContext();
if (securityContext instanceof ShiroSecurityContext) { if (securityContext instanceof ShiroSecurityContext) {
final ShiroSecurityContext context = (ShiroSecurityContext) securityContext; final ShiroSecurityContext context = (ShiroSecurityContext) securityContext;
final Subject subject = context.getSubject(); final String userName = RestTools.getUserNameFromRequest(requestContext);
final ContextAwarePermissionAnnotationHandler annotationHandler = new ContextAwarePermissionAnnotationHandler(context); final ContextAwarePermissionAnnotationHandler annotationHandler = new ContextAwarePermissionAnnotationHandler(context);
try { try {
LOG.debug("Checking authorization for user {}, needs permissions {}", subject, annotation.value()); LOG.debug("Checking authorization for user [{}], needs permissions: {}", userName, annotation.value());
annotationHandler.assertAuthorized(annotation); annotationHandler.assertAuthorized(annotation);
} catch (AuthorizationException e) { } catch (AuthorizationException e) {
LOG.info("User " + subject + "not authorized.", e); LOG.info("User [" + userName + "] not authorized.", e);
throw new NotAuthorizedException(e, "Basic realm=\"Graylog Server\""); throw new NotAuthorizedException(e, "Basic realm=\"Graylog Server\"");
} }
} else { } else {
Expand Down

0 comments on commit c606667

Please sign in to comment.