Skip to content

Commit ae9ae49

Browse files
committed
[#1803,TCK] Call org.osgi.service.servlet.context.ServletContextHelper#finishSecurity() only when needed
1 parent bdca4ad commit ae9ae49

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pax-web-spi/src/main/java/org/ops4j/pax/web/service/spi/servlet/OsgiFilterChain.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ public void doFilter(ServletRequest request, ServletResponse response) throws IO
9797

9898
// nothing left - time to call security and if it passes - call the rest of the chain (normal filters
9999
// and target servlet)
100+
boolean finishRequired = false;
100101
try {
101-
if (webContext == null || webContext.handleSecurity(req, res)) {
102+
if (webContext == null || (finishRequired = webContext.handleSecurity(req, res))) {
102103
if (authListener != null && webContext != null) {
103104
// it means we've passed the OSGi security handler
104105
// here, the listener may translate (if available):
@@ -123,7 +124,7 @@ public void doFilter(ServletRequest request, ServletResponse response) throws IO
123124
}
124125
}
125126
} finally {
126-
if (webContext != null) {
127+
if (webContext != null && finishRequired) {
127128
webContext.finishSecurity(req, res);
128129
}
129130
}

pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebSecurityHandler.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
5959
webContext = defaultWebContainerContext;
6060
}
6161

62+
boolean finishRequired = false;
6263
try {
63-
if (webContext == null || webContext.handleSecurity(req, res)) {
64+
if (webContext == null || (finishRequired = webContext.handleSecurity(req, res))) {
6465
if (webContext != null) {
6566
final Object user = req.getAttribute(ServletContextHelper.REMOTE_USER);
6667
final Object authType = req.getAttribute(ServletContextHelper.AUTHENTICATION_TYPE);
@@ -98,7 +99,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
9899
}
99100
}
100101
} finally {
101-
if (webContext != null) {
102+
if (webContext != null && finishRequired) {
102103
webContext.finishSecurity(req, res);
103104
}
104105
}

0 commit comments

Comments
 (0)