Skip to content

Commit

Permalink
Merge pull request #1384 from obiba/fix/unknown-session-in-async
Browse files Browse the repository at this point in the history
MK-1280
  • Loading branch information
meek0 authored Feb 6, 2017
2 parents 13cf093 + bfc331b commit ccf100d
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.math3.util.Pair;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.UnknownSessionException;
import org.apache.shiro.subject.Subject;
import org.bson.types.ObjectId;
import org.joda.time.DateTime;
Expand Down Expand Up @@ -916,9 +917,16 @@ private static String extractBaseName(String pathWithName) {

private String getCurrentUsername() {
Subject subject = SecurityUtils.getSubject();
return subject == null || subject.getPrincipal() == null
? AbstractGitWriteCommand.DEFAULT_AUTHOR_NAME
: subject.getPrincipal().toString();

try {
if(subject != null && subject.getPrincipal() != null)
return subject.getPrincipal().toString();
} catch (UnknownSessionException ignore) {
log.debug(String.format(
"Impossible to get currentUsername, we are probably in an @Async method. Use DEFAULT_AUTHOR_NAME [%s]", AbstractGitWriteCommand.DEFAULT_AUTHOR_NAME), ignore);
}

return AbstractGitWriteCommand.DEFAULT_AUTHOR_NAME;
}

private void validateFileName(String name) {
Expand Down

0 comments on commit ccf100d

Please sign in to comment.