Skip to content

Commit

Permalink
fix username in the list of http sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
evernat committed Nov 28, 2015
1 parent 7143d04 commit d111126
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/net/bull/javamelody/NodesController.java
Expand Up @@ -54,6 +54,11 @@
* @author Emeric Vernat
*/
public class NodesController {
/**
* For HudsonMonitoringFilter.
*/
public static final String SESSION_REMOTE_USER = SessionInformations.SESSION_REMOTE_USER;

private final Collector collector;
private final String nodeName;
private final List<JavaInformations> lastJavaInformationsList;
Expand Down
Expand Up @@ -29,6 +29,7 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jenkins.model.Jenkins;
import net.bull.javamelody.NodesCollector;
Expand Down Expand Up @@ -96,7 +97,11 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
return;
}

super.doFilter(request, response, chain);
try {
super.doFilter(request, response, chain);
} finally {
putUserInfoInSession(httpRequest);
}
}

private boolean hasInvalidParameters(ServletRequest request) {
Expand All @@ -113,6 +118,22 @@ private boolean hasInvalidParameters(ServletRequest request) {
return false;
}

private void putUserInfoInSession(HttpServletRequest httpRequest) {
final HttpSession session = httpRequest.getSession(false);
if (session == null) {
// la session n'est pas encore créée (et ne le sera peut-être jamais)
return;
}
if (session.getAttribute(NodesController.SESSION_REMOTE_USER) == null) {
// login utilisateur, peut être null
// dans Jenkins, pas remoteUser = httpRequest.getRemoteUser();
final String remoteUser = Jenkins.getAuthentication().getName();
if (remoteUser != null) {
session.setAttribute(NodesController.SESSION_REMOTE_USER, remoteUser);
}
}
}

/**
* Generate a report
*
Expand Down

0 comments on commit d111126

Please sign in to comment.