Skip to content

Commit 8a4dbf2

Browse files
authored
Merge pull request eugenp#3644 from eugenp/BAEL-1501
Bael 1501
2 parents 7ead9b7 + 5842c87 commit 8a4dbf2

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

‎spring-5-security/src/main/java/com/baeldung/dsl/ClientErrorLoggingFilter.java‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,22 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
3232
Authentication auth = SecurityContextHolder.getContext()
3333
.getAuthentication();
3434

35-
if (auth != null) {
36-
int status = ((HttpServletResponse) response).getStatus();
37-
if (status >= 400 && status < 500) {
38-
if (errorCodes == null) {
39-
logger.debug("User " + auth.getName() + " encountered error " + status);
40-
} else {
41-
if (errorCodes.stream()
42-
.filter(s -> s.value() == status)
43-
.findFirst()
44-
.isPresent()) {
45-
logger.debug("User " + auth.getName() + " encountered error " + status);
46-
}
47-
}
35+
if (auth == null) {
36+
chain.doFilter(request, response);
37+
return;
38+
}
39+
int status = ((HttpServletResponse) response).getStatus();
40+
if (status < 400 || status >= 500) {
41+
chain.doFilter(request, response);
42+
return;
43+
}
44+
45+
if (errorCodes == null) {
46+
logger.debug("User " + auth.getName() + " encountered error " + status);
47+
} else {
48+
if (errorCodes.stream()
49+
.anyMatch(s -> s.value() == status)) {
50+
logger.debug("User " + auth.getName() + " encountered error " + status);
4851
}
4952
}
5053

‎spring-5-security/src/main/resources/application.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ server.port=8081
22

33
logging.level.root=INFO
44

5-
logging.level.com.baeldung.dsl.ClientErrorLoggingFilter=DEBUG
5+
logging.level.com.baeldung.dsl.ClientErrorLoggingFilter=DEBUG

0 commit comments

Comments
 (0)