[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-94-ge13257d
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Thu Mar 18 19:11:52 CET 2010
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".
The branch, master has been updated
via e13257d75b2b4439c4c98b85e25a76611080a3d4 (commit)
from 499abbba89771332844fa84262e77277f66e8932 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=e13257d75b2b4439c4c98b85e25a76611080a3d4
http://github.com/ceki/logback/commit/e13257d75b2b4439c4c98b85e25a76611080a3d4
commit e13257d75b2b4439c4c98b85e25a76611080a3d4
Author: Ceki Gulcu <ceki at qos.ch>
Date: Thu Mar 18 19:08:24 2010 +0100
Fixed http://jira.qos.ch/browse/LBSITE-36
diff --git a/logback-examples/src/main/java/chapters/mdc/UserServletFilter.java b/logback-examples/src/main/java/chapters/mdc/UserServletFilter.java
index cc9db4c..532517b 100644
--- a/logback-examples/src/main/java/chapters/mdc/UserServletFilter.java
+++ b/logback-examples/src/main/java/chapters/mdc/UserServletFilter.java
@@ -23,38 +23,21 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
import org.slf4j.MDC;
/**
* A simple servlet filter that puts the username
- * found either in the Principle or as a session attribute
- * in the MDC.
+ * found either in the Principal.
*
- * The value is removed from the MDC once the request has been
+ * <p> The value is removed from the MDC once the request has been
* fully processed.
*
- * To be used, add the following lines to a web.xml file
- *
- * <filter>
- * <filter-name>User Servlet Filter</filter-name>
- * <filter-class>
- * chapters.mdc.UserServletFilter
- * </filter-class>
- * </filter>
- * <filter-mapping>
- * <filter-name>User Servlet Filter</filter-name>
- * <url-pattern>/*</url-pattern>
- * </filter-mapping>
- *
* @author Sébastien Pennec
*/
public class UserServletFilter implements Filter {
- boolean userRegistered = false;
-
- private final String userKey = "username";
+ private final String USER_KEY = "username";
public void destroy() {
}
@@ -62,25 +45,22 @@ public class UserServletFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
+ boolean successfulRegistration = false;
HttpServletRequest req = (HttpServletRequest) request;
Principal principal = req.getUserPrincipal();
- // Please note that we could have also used a cookie to
- // retreive the user name
+ // Please note that we also could have used a cookie to
+ // retrieve the user name
if (principal != null) {
String username = principal.getName();
- registerUsername(username);
- } else {
- HttpSession session = req.getSession();
- String username = (String)session.getAttribute(userKey);
- registerUsername(username);
+ successfulRegistration = registerUsername(username);
}
try {
chain.doFilter(request, response);
} finally {
- if (userRegistered) {
- MDC.remove(userKey);
+ if (successfulRegistration) {
+ MDC.remove(USER_KEY);
}
}
}
@@ -88,11 +68,18 @@ public class UserServletFilter implements Filter {
public void init(FilterConfig arg0) throws ServletException {
}
- private void registerUsername(String username) {
+ /**
+ * Register the user in the MDC under USER_KEY.
+ *
+ * @param username
+ * @return true id the user can be successfully registered
+ */
+ private boolean registerUsername(String username) {
if (username != null && username.trim().length() > 0) {
- MDC.put(userKey, username);
- userRegistered = true;
+ MDC.put(USER_KEY, username);
+ return true;
}
+ return false;
}
}
diff --git a/logback-site/src/site/pages/manual/mdc.html b/logback-site/src/site/pages/manual/mdc.html
index 43e0c1a..6cdfc59 100644
--- a/logback-site/src/site/pages/manual/mdc.html
+++ b/logback-site/src/site/pages/manual/mdc.html
@@ -550,9 +550,7 @@ import org.slf4j.MDC;
public class UserServletFilter implements Filter {
- boolean userRegistered = false;
-
- private final String userKey = "username";
+ private final String USER_KEY = "username";
public void destroy() {
}
@@ -560,26 +558,23 @@ public class UserServletFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
- HttpServletRequest req = (HttpServletRequest) request;
-
+ boolean successfulRegistration = false;
+
+ HttpServletRequest req = (HttpServletRequest) request;
Principal principal = req.getUserPrincipal();
// Please note that we could have also used a cookie to
// retrieve the user name
if (principal != null) {
String username = principal.getName();
- registerUsername(username);
- } else {
- HttpSession session = req.getSession();
- String username = (String)session.getAttribute(userKey);
- registerUsername(username);
- }
-
+ successfulRegistration = registerUsername(username);
+ }
+
try {
chain.doFilter(request, response);
} finally {
- if (userRegistered) {
- MDC.remove(userKey);
+ if (successfulRegistration) {
+ MDC.remove(USER_KEY);
}
}
}
@@ -587,21 +582,27 @@ public class UserServletFilter implements Filter {
public void init(FilterConfig arg0) throws ServletException {
}
- private void registerUsername(String username) {
+
+ /**
+ * Register the user in the MDC under USER_KEY.
+ *
+ * @param username
+ * @return true id the user can be successfully registered
+ */
+ private boolean registerUsername(String username) {
if (username != null && username.trim().length() > 0) {
- MDC.put(userKey, username);
- userRegistered = true;
+ MDC.put(USER_KEY, username);
+ return true;
}
+ return false;
}
}</pre>
<p>When the filter's <code>doFilter()</code> method is called, it
first looks for a <code>java.security.Principal</code> object in the
request. This object contains the name of the currently
- authenticated user. In case the user principal is not set, the
- filter looks for a session attribute matching a given key (here
- <em>username</em>). If a user information is found, it is
- registered in the <code>MDC</code>.
+ authenticated user. If a user information is found, it is registered
+ in the <code>MDC</code>.
</p>
<p>Once the filter chain has completed, the filter removes the user
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 8d5fb90..644d52a 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -131,6 +131,10 @@
reported by Tom SH Liu.
</p>
+ <p>Fixed <a
+ href="http://jira.qos.ch/browse/LBSITE-36">LBSITE-36</a> reported
+ by John Jimenez.</p>
+
<hr width="80%" align="center" />
<!-- ======================================================================== -->
-----------------------------------------------------------------------
Summary of changes:
.../main/java/chapters/mdc/UserServletFilter.java | 51 +++++++------------
logback-site/src/site/pages/manual/mdc.html | 43 ++++++++--------
logback-site/src/site/pages/news.html | 4 ++
3 files changed, 45 insertions(+), 53 deletions(-)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list